2 * "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 2007-2008 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 print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_quotas() - Check quotas for a printer and user.
45 * check_rss_recipient() - Check that we do not have a duplicate RSS
47 * copy_attribute() - Copy a single attribute.
48 * copy_attrs() - Copy attributes from one request to another.
49 * copy_banner() - Copy a banner file to the requests directory
50 * for the specified job.
51 * copy_file() - Copy a PPD file or interface script...
52 * copy_model() - Copy a PPD model file, substituting default
54 * copy_job_attrs() - Copy job attributes.
55 * copy_printer_attrs() - Copy printer attributes.
56 * copy_subscription_attrs() - Copy subscription attributes.
57 * create_job() - Print a file to a printer or class.
58 * create_requested_array() - Create an array for the requested-attributes.
59 * create_subscription() - Create a notification subscription.
60 * delete_printer() - Remove a printer or class from the system.
61 * get_default() - Get the default destination.
62 * get_devices() - Get the list of available devices on the
64 * get_document() - Get a copy of a job file.
65 * get_job_attrs() - Get job attributes.
66 * get_jobs() - Get a list of jobs for the specified printer.
67 * get_notifications() - Get events for a subscription.
68 * get_ppd() - Get a named PPD from the local system.
69 * get_ppds() - Get the list of PPD files on the local
71 * get_printer_attrs() - Get printer attributes.
72 * get_printers() - Get a list of printers or classes.
73 * get_subscription_attrs() - Get subscription attributes.
74 * get_subscriptions() - Get subscriptions.
75 * get_username() - Get the username associated with a request.
76 * hold_job() - Hold a print job.
77 * move_job() - Move a job to a new destination.
78 * ppd_parse_line() - Parse a PPD default line.
79 * print_job() - Print a file to a printer or class.
80 * read_job_ticket() - Read a job ticket embedded in a print file.
81 * reject_jobs() - Reject print jobs to a printer.
82 * release_job() - Release a held print job.
83 * renew_subscription() - Renew an existing subscription...
84 * restart_job() - Restart an old print job.
85 * save_auth_info() - Save authentication information for a job.
86 * save_krb5_creds() - Save Kerberos credentials for the job.
87 * send_document() - Send a file to a printer or class.
88 * send_http_error() - Send a HTTP error back to the IPP client.
89 * send_ipp_status() - Send a status back to the IPP client.
90 * set_default() - Set the default destination...
91 * set_job_attrs() - Set job attributes.
92 * set_printer_defaults() - Set printer default options from a request.
93 * start_printer() - Start a printer.
94 * stop_printer() - Stop a printer.
95 * url_encode_attr() - URL-encode a string attribute.
96 * url_encode_string() - URL-encode a string.
97 * user_allowed() - See if a user is allowed to print to a queue.
98 * validate_job() - Validate printer options and destination.
99 * validate_name() - Make sure the printer name only contains
101 * validate_user() - Validate the user for the request.
105 * Include necessary headers...
109 #include <cups/ppd-private.h>
113 #endif /* HAVE_LIBPAPER */
116 # include <ApplicationServices/ApplicationServices.h>
117 # include <CoreFoundation/CoreFoundation.h>
118 # ifdef HAVE_MEMBERSHIP_H
119 # include <membership.h>
120 # endif /* HAVE_MEMBERSHIP_H */
121 # ifdef HAVE_MEMBERSHIPPRIV_H
122 # include <membershipPriv.h>
124 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
125 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
126 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
127 # endif /* HAVE_MEMBERSHIPPRIV_H */
128 #endif /* __APPLE__ */
135 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
136 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
137 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
138 mime_type_t
*filetype
, int compression
);
139 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
140 mime_type_t
*filetype
);
141 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
142 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
143 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
144 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
145 static void add_printer_state_reasons(cupsd_client_t
*con
,
147 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
149 static void apple_init_profile(ppd_file_t
*ppd
, cups_array_t
*languages
,
150 CMDeviceProfileInfo
*profile
, unsigned id
,
151 const char *name
, const char *text
,
152 const char *iccfile
);
153 static void apple_register_profiles(cupsd_printer_t
*p
);
154 static void apple_unregister_profiles(cupsd_printer_t
*p
);
155 #endif /* __APPLE__ */
156 static void apply_printer_defaults(cupsd_printer_t
*printer
,
158 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
159 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
160 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
161 static void cancel_subscription(cupsd_client_t
*con
, int id
);
162 static int check_rss_recipient(const char *recipient
);
163 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
164 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
166 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
167 ipp_tag_t group
, int quickcopy
);
168 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
170 static int copy_file(const char *from
, const char *to
);
171 static int copy_model(cupsd_client_t
*con
, const char *from
,
173 static void copy_job_attrs(cupsd_client_t
*con
,
176 static void copy_printer_attrs(cupsd_client_t
*con
,
177 cupsd_printer_t
*printer
,
179 static void copy_subscription_attrs(cupsd_client_t
*con
,
180 cupsd_subscription_t
*sub
,
182 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
183 static cups_array_t
*create_requested_array(ipp_t
*request
);
184 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
185 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void get_default(cupsd_client_t
*con
);
187 static void get_devices(cupsd_client_t
*con
);
188 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
189 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
191 static void get_notifications(cupsd_client_t
*con
);
192 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void get_ppds(cupsd_client_t
*con
);
194 static void get_printers(cupsd_client_t
*con
, int type
);
195 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
196 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
197 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
198 static const char *get_username(cupsd_client_t
*con
);
199 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
200 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static int ppd_parse_line(const char *line
, char *option
, int olen
,
203 char *choice
, int clen
);
204 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void read_job_ticket(cupsd_client_t
*con
);
206 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void release_held_new_jobs(cupsd_client_t
*con
,
208 ipp_attribute_t
*uri
);
209 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
211 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
212 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
213 ipp_attribute_t
*auth_info
);
214 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
215 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
216 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
217 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
218 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
219 cupsd_printer_t
*printer
);
220 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
221 const char *message
, ...)
223 __attribute__ ((__format__ (__printf__
, 3, 4)))
224 # endif /* __GNUC__ */
226 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
227 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
228 static void set_printer_defaults(cupsd_client_t
*con
,
229 cupsd_printer_t
*printer
);
230 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
231 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
232 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
234 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
235 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
236 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
237 static int validate_name(const char *name
);
238 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
239 const char *owner
, char *username
,
244 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
247 int /* O - 1 on success, 0 on failure */
248 cupsdProcessIPPRequest(
249 cupsd_client_t
*con
) /* I - Client connection */
251 ipp_tag_t group
; /* Current group tag */
252 ipp_attribute_t
*attr
; /* Current attribute */
253 ipp_attribute_t
*charset
; /* Character set attribute */
254 ipp_attribute_t
*language
; /* Language attribute */
255 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
256 ipp_attribute_t
*username
; /* requesting-user-name attr */
257 int sub_id
; /* Subscription ID */
260 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
261 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
262 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
265 * First build an empty response message for this request...
268 con
->response
= ippNew();
270 con
->response
->request
.status
.version
[0] =
271 con
->request
->request
.op
.version
[0];
272 con
->response
->request
.status
.version
[1] =
273 con
->request
->request
.op
.version
[1];
274 con
->response
->request
.status
.request_id
=
275 con
->request
->request
.op
.request_id
;
278 * Then validate the request header and required attributes...
281 if (con
->request
->request
.any
.version
[0] != 1)
284 * Return an error, since we only support IPP 1.x.
287 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
288 "%04X %s Bad request version number %d.%d",
289 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
290 con
->request
->request
.any
.version
[0],
291 con
->request
->request
.any
.version
[1]);
293 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
294 _("Bad request version number %d.%d!"),
295 con
->request
->request
.any
.version
[0],
296 con
->request
->request
.any
.version
[1]);
298 else if (!con
->request
->attrs
)
300 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
301 "%04X %s No attributes in request",
302 IPP_BAD_REQUEST
, con
->http
.hostname
);
304 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
309 * Make sure that the attributes are provided in the correct order and
310 * don't repeat groups...
313 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
316 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
319 * Out of order; return an error...
322 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
323 "%04X %s Attribute groups are out of order",
324 IPP_BAD_REQUEST
, con
->http
.hostname
);
326 send_ipp_status(con
, IPP_BAD_REQUEST
,
327 _("Attribute groups are out of order (%x < %x)!"),
328 attr
->group_tag
, group
);
332 group
= attr
->group_tag
;
337 * Then make sure that the first three attributes are:
340 * attributes-natural-language
341 * printer-uri/job-uri
344 attr
= con
->request
->attrs
;
345 if (attr
&& !strcmp(attr
->name
, "attributes-charset") &&
346 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
354 if (attr
&& !strcmp(attr
->name
, "attributes-natural-language") &&
355 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
360 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
361 IPP_TAG_URI
)) != NULL
)
363 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
364 IPP_TAG_URI
)) != NULL
)
366 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
367 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
372 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
373 "attributes-charset", NULL
,
374 charset
->values
[0].string
.text
);
376 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
377 "attributes-charset", NULL
, DefaultCharset
);
380 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
381 "attributes-natural-language", NULL
,
382 language
->values
[0].string
.text
);
384 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
385 "attributes-natural-language", NULL
, DefaultLanguage
);
388 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
389 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
392 * Bad character set...
395 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"!",
396 charset
->values
[0].string
.text
);
397 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
398 "%04X %s Unsupported attributes-charset value \"%s\"",
399 IPP_CHARSET
, con
->http
.hostname
,
400 charset
->values
[0].string
.text
);
401 send_ipp_status(con
, IPP_BAD_REQUEST
,
402 _("Unsupported character set \"%s\"!"),
403 charset
->values
[0].string
.text
);
405 else if (!charset
|| !language
||
407 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
408 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
409 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
410 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
411 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
414 * Return an error, since attributes-charset,
415 * attributes-natural-language, and printer-uri/job-uri are required
416 * for all operations.
421 cupsdLogMessage(CUPSD_LOG_ERROR
,
422 "Missing attributes-charset attribute!");
424 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
425 "%04X %s Missing attributes-charset attribute",
426 IPP_BAD_REQUEST
, con
->http
.hostname
);
431 cupsdLogMessage(CUPSD_LOG_ERROR
,
432 "Missing attributes-natural-language attribute!");
434 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
435 "%04X %s Missing attributes-natural-language attribute",
436 IPP_BAD_REQUEST
, con
->http
.hostname
);
441 cupsdLogMessage(CUPSD_LOG_ERROR
,
442 "Missing printer-uri, job-uri, or ppd-name "
445 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
446 "%04X %s Missing printer-uri, job-uri, or ppd-name "
447 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
450 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
452 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
453 cupsdLogMessage(CUPSD_LOG_DEBUG
,
454 "attr \"%s\": group_tag = %x, value_tag = %x",
455 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
458 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
460 send_ipp_status(con
, IPP_BAD_REQUEST
,
461 _("Missing required attributes!"));
466 * OK, all the checks pass so far; make sure requesting-user-name is
467 * not "root" from a remote host...
470 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
471 IPP_TAG_NAME
)) != NULL
)
474 * Check for root user...
477 if (!strcmp(username
->values
[0].string
.text
, "root") &&
478 strcasecmp(con
->http
.hostname
, "localhost") &&
479 strcmp(con
->username
, "root"))
482 * Remote unauthenticated user masquerading as local root...
485 _cupsStrFree(username
->values
[0].string
.text
);
486 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
490 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
491 IPP_TAG_INTEGER
)) != NULL
)
492 sub_id
= attr
->values
[0].integer
;
497 * Then try processing the operation...
501 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
502 ippOpString(con
->request
->request
.op
.operation_id
),
503 uri
->values
[0].string
.text
);
505 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
506 ippOpString(con
->request
->request
.op
.operation_id
));
508 switch (con
->request
->request
.op
.operation_id
)
514 case IPP_VALIDATE_JOB
:
515 validate_job(con
, uri
);
518 case IPP_CREATE_JOB
:
519 create_job(con
, uri
);
522 case IPP_SEND_DOCUMENT
:
523 send_document(con
, uri
);
526 case IPP_CANCEL_JOB
:
527 cancel_job(con
, uri
);
530 case IPP_GET_JOB_ATTRIBUTES
:
531 get_job_attrs(con
, uri
);
538 case IPP_GET_PRINTER_ATTRIBUTES
:
539 get_printer_attrs(con
, uri
);
546 case IPP_RELEASE_JOB
:
547 release_job(con
, uri
);
550 case IPP_RESTART_JOB
:
551 restart_job(con
, uri
);
554 case IPP_PAUSE_PRINTER
:
555 stop_printer(con
, uri
);
558 case IPP_RESUME_PRINTER
:
559 start_printer(con
, uri
);
562 case IPP_PURGE_JOBS
:
563 cancel_all_jobs(con
, uri
);
566 case IPP_SET_JOB_ATTRIBUTES
:
567 set_job_attrs(con
, uri
);
570 case IPP_HOLD_NEW_JOBS
:
571 hold_new_jobs(con
, uri
);
574 case IPP_RELEASE_HELD_NEW_JOBS
:
575 release_held_new_jobs(con
, uri
);
578 case CUPS_GET_DEFAULT
:
582 case CUPS_GET_PRINTERS
:
583 get_printers(con
, 0);
586 case CUPS_GET_CLASSES
:
587 get_printers(con
, CUPS_PRINTER_CLASS
);
590 case CUPS_ADD_PRINTER
:
591 add_printer(con
, uri
);
594 case CUPS_DELETE_PRINTER
:
595 delete_printer(con
, uri
);
598 case CUPS_ADD_CLASS
:
602 case CUPS_DELETE_CLASS
:
603 delete_printer(con
, uri
);
606 case CUPS_ACCEPT_JOBS
:
607 case IPP_ENABLE_PRINTER
:
608 accept_jobs(con
, uri
);
611 case CUPS_REJECT_JOBS
:
612 case IPP_DISABLE_PRINTER
:
613 reject_jobs(con
, uri
);
616 case CUPS_SET_DEFAULT
:
617 set_default(con
, uri
);
620 case CUPS_GET_DEVICES
:
624 case CUPS_GET_DOCUMENT
:
625 get_document(con
, uri
);
640 case CUPS_AUTHENTICATE_JOB
:
641 authenticate_job(con
, uri
);
644 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
645 case IPP_CREATE_JOB_SUBSCRIPTION
:
646 create_subscription(con
, uri
);
649 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
650 get_subscription_attrs(con
, sub_id
);
653 case IPP_GET_SUBSCRIPTIONS
:
654 get_subscriptions(con
, uri
);
657 case IPP_RENEW_SUBSCRIPTION
:
658 renew_subscription(con
, sub_id
);
661 case IPP_CANCEL_SUBSCRIPTION
:
662 cancel_subscription(con
, sub_id
);
665 case IPP_GET_NOTIFICATIONS
:
666 get_notifications(con
);
670 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
671 "%04X %s Operation %04X (%s) not supported",
672 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
673 con
->request
->request
.op
.operation_id
,
674 ippOpString(con
->request
->request
.op
.operation_id
));
676 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
677 _("%s not supported!"),
679 con
->request
->request
.op
.operation_id
));
689 * Sending data from the scheduler...
692 cupsdLogMessage(con
->response
->request
.status
.status_code
693 >= IPP_BAD_REQUEST
&&
694 con
->response
->request
.status
.status_code
695 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
696 "Returning IPP %s for %s (%s) from %s",
697 ippErrorString(con
->response
->request
.status
.status_code
),
698 ippOpString(con
->request
->request
.op
.operation_id
),
699 uri
? uri
->values
[0].string
.text
: "no URI",
702 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
704 #ifdef CUPSD_USE_CHUNKING
706 * Because older versions of CUPS (1.1.17 and older) and some IPP
707 * clients do not implement chunking properly, we cannot use
708 * chunking by default. This may become the default in future
709 * CUPS releases, or we might add a configuration directive for
713 if (con
->http
.version
== HTTP_1_1
)
715 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
718 if (cupsdFlushHeader(con
) < 0)
721 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
724 #endif /* CUPSD_USE_CHUNKING */
726 size_t length
; /* Length of response */
729 length
= ippLength(con
->response
);
731 if (con
->file
>= 0 && !con
->pipe_pid
)
733 struct stat fileinfo
; /* File information */
736 if (!fstat(con
->file
, &fileinfo
))
737 length
+= fileinfo
.st_size
;
740 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
741 CUPS_LLCAST length
) < 0)
744 if (cupsdFlushHeader(con
) < 0)
747 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
748 con
->http
.data_remaining
= length
;
750 if (con
->http
.data_remaining
<= INT_MAX
)
751 con
->http
._data_remaining
= con
->http
.data_remaining
;
753 con
->http
._data_remaining
= INT_MAX
;
756 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
757 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
760 * Tell the caller the response header was sent successfully...
768 * Tell the caller the response header could not be sent...
777 * Sending data from a subprocess like cups-deviced; tell the caller
778 * everything is A-OK so far...
787 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
790 int /* O - 0 on success, -1 on error */
791 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
793 cupsd_printer_t
*printer
; /* Destination printer or class */
794 ipp_attribute_t
*attr
; /* job-sheets attribute */
795 int kbytes
; /* Kilobytes in banner */
798 job
->pending_timeout
= 0;
801 * See if we need to add the ending sheet...
804 printer
= cupsdFindDest(job
->dest
);
805 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
808 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
809 attr
&& attr
->num_values
> 1)
815 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
816 attr
->values
[1].string
.text
);
818 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
821 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
829 * 'accept_jobs()' - Accept print jobs to a printer.
833 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
834 ipp_attribute_t
*uri
) /* I - Printer or class URI */
836 http_status_t status
; /* Policy status */
837 cups_ptype_t dtype
; /* Destination type (printer/class) */
838 cupsd_printer_t
*printer
; /* Printer data */
841 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
842 con
->http
.fd
, uri
->values
[0].string
.text
);
845 * Is the destination valid?
848 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
854 send_ipp_status(con
, IPP_NOT_FOUND
,
855 _("The printer or class was not found."));
863 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
865 send_http_error(con
, status
, printer
);
870 * Accept jobs sent to the printer...
873 printer
->accepting
= 1;
874 printer
->state_message
[0] = '\0';
876 cupsdAddPrinterHistory(printer
);
878 if (dtype
& CUPS_PRINTER_CLASS
)
880 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
882 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
883 printer
->name
, get_username(con
));
887 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
889 cupsdLogMessage(CUPSD_LOG_INFO
,
890 "Printer \"%s\" now accepting jobs (\"%s\").",
891 printer
->name
, get_username(con
));
895 * Everything was ok, so return OK status...
898 con
->response
->request
.status
.status_code
= IPP_OK
;
903 * 'add_class()' - Add a class to the system.
907 add_class(cupsd_client_t
*con
, /* I - Client connection */
908 ipp_attribute_t
*uri
) /* I - URI of class */
910 http_status_t status
; /* Policy status */
911 int i
; /* Looping var */
912 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
913 username
[HTTP_MAX_URI
], /* Username portion of URI */
914 host
[HTTP_MAX_URI
], /* Host portion of URI */
915 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
916 int port
; /* Port portion of URI */
917 cupsd_printer_t
*pclass
, /* Class */
918 *member
; /* Member printer/class */
919 cups_ptype_t dtype
; /* Destination type */
920 ipp_attribute_t
*attr
; /* Printer attribute */
921 int modify
; /* Non-zero if we just modified */
922 char newname
[IPP_MAX_NAME
]; /* New class name */
923 int need_restart_job
; /* Need to restart job? */
926 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
927 con
->http
.fd
, uri
->values
[0].string
.text
);
930 * Do we have a valid URI?
933 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
934 sizeof(scheme
), username
, sizeof(username
), host
,
935 sizeof(host
), &port
, resource
, sizeof(resource
));
938 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
941 * No, return an error...
944 send_ipp_status(con
, IPP_BAD_REQUEST
,
945 _("The printer-uri must be of the form "
946 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
951 * Do we have a valid printer name?
954 if (!validate_name(resource
+ 9))
957 * No, return an error...
960 send_ipp_status(con
, IPP_BAD_REQUEST
,
961 _("The printer-uri \"%s\" contains invalid characters."),
962 uri
->values
[0].string
.text
);
967 * See if the class already exists; if not, create a new class...
970 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
973 * Class doesn't exist; see if we have a printer of the same name...
976 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
977 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
980 * Yes, return an error...
983 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
984 _("A printer named \"%s\" already exists!"),
990 * No, check the default policy and then add the class...
993 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
995 send_http_error(con
, status
, NULL
);
999 pclass
= cupsdAddClass(resource
+ 9);
1002 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
1005 * Check the default policy, then rename the implicit class to "AnyClass"
1009 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1011 send_http_error(con
, status
, NULL
);
1015 if (ImplicitAnyClasses
)
1017 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1018 cupsdRenamePrinter(pclass
, newname
);
1021 cupsdDeletePrinter(pclass
, 1);
1024 * Add the class as a new local class...
1027 pclass
= cupsdAddClass(resource
+ 9);
1030 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1033 * Check the default policy, then rename the remote class to "Class"...
1036 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1038 send_http_error(con
, status
, NULL
);
1042 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1043 cupsdRenamePrinter(pclass
, newname
);
1046 * Add the class as a new local class...
1049 pclass
= cupsdAddClass(resource
+ 9);
1052 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1055 send_http_error(con
, status
, pclass
);
1062 * Look for attributes and copy them over as needed...
1065 need_restart_job
= 0;
1067 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1068 IPP_TAG_TEXT
)) != NULL
)
1069 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1071 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1072 IPP_TAG_TEXT
)) != NULL
)
1073 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1075 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1076 IPP_TAG_BOOLEAN
)) != NULL
)
1078 cupsdLogMessage(CUPSD_LOG_INFO
,
1079 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1080 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1082 pclass
->accepting
= attr
->values
[0].boolean
;
1083 cupsdAddPrinterHistory(pclass
);
1086 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1087 IPP_TAG_BOOLEAN
)) != NULL
)
1089 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1090 cupsdDeregisterPrinter(pclass
, 1);
1092 cupsdLogMessage(CUPSD_LOG_INFO
,
1093 "Setting %s printer-is-shared to %d (was %d.)",
1094 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1096 pclass
->shared
= attr
->values
[0].boolean
;
1099 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1100 IPP_TAG_ENUM
)) != NULL
)
1102 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1103 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1105 send_ipp_status(con
, IPP_BAD_REQUEST
,
1106 _("Attempt to set %s printer-state to bad value %d!"),
1107 pclass
->name
, attr
->values
[0].integer
);
1111 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1112 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1114 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1115 cupsdStopPrinter(pclass
, 0);
1118 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1119 need_restart_job
= 1;
1122 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1123 IPP_TAG_TEXT
)) != NULL
)
1125 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1126 sizeof(pclass
->state_message
));
1127 cupsdAddPrinterHistory(pclass
);
1129 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1130 IPP_TAG_URI
)) != NULL
)
1133 * Clear the printer array as needed...
1136 need_restart_job
= 1;
1138 if (pclass
->num_printers
> 0)
1140 free(pclass
->printers
);
1141 pclass
->num_printers
= 0;
1145 * Add each printer or class that is listed...
1148 for (i
= 0; i
< attr
->num_values
; i
++)
1151 * Search for the printer or class URI...
1154 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1160 send_ipp_status(con
, IPP_NOT_FOUND
,
1161 _("The printer or class was not found."));
1166 * Add it to the class...
1169 cupsdAddPrinterToClass(pclass
, member
);
1173 set_printer_defaults(con
, pclass
);
1175 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1176 IPP_TAG_KEYWORD
)) != NULL
)
1177 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1180 * Update the printer class attributes and return...
1183 cupsdSetPrinterAttrs(pclass
);
1184 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1186 if (need_restart_job
&& pclass
->job
)
1191 * Stop the current job and then restart it below...
1194 job
= (cupsd_job_t
*)pclass
->job
;
1196 cupsdStopJob(job
, 1);
1198 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1199 job
->state_value
= IPP_JOB_PENDING
;
1202 if (need_restart_job
)
1205 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1209 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1210 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1213 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1214 pclass
->name
, get_username(con
));
1218 cupsdAddPrinterHistory(pclass
);
1220 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1221 "New class \"%s\" added by \"%s\".", pclass
->name
,
1224 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1225 pclass
->name
, get_username(con
));
1228 con
->response
->request
.status
.status_code
= IPP_OK
;
1233 * 'add_file()' - Add a file to a job.
1236 static int /* O - 0 on success, -1 on error */
1237 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1238 cupsd_job_t
*job
, /* I - Job to add to */
1239 mime_type_t
*filetype
, /* I - Type of file */
1240 int compression
) /* I - Compression */
1242 mime_type_t
**filetypes
; /* New filetypes array... */
1243 int *compressions
; /* New compressions array... */
1246 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1247 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1248 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1249 filetype
->super
, filetype
->type
, compression
);
1252 * Add the file to the job...
1255 if (job
->num_files
== 0)
1257 compressions
= (int *)malloc(sizeof(int));
1258 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1262 compressions
= (int *)realloc(job
->compressions
,
1263 (job
->num_files
+ 1) * sizeof(int));
1264 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1265 (job
->num_files
+ 1) *
1266 sizeof(mime_type_t
*));
1269 if (!compressions
|| !filetypes
)
1271 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
1274 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1275 _("Unable to allocate memory for file types!"));
1280 job
->compressions
= compressions
;
1281 job
->compressions
[job
->num_files
] = compression
;
1282 job
->filetypes
= filetypes
;
1283 job
->filetypes
[job
->num_files
] = filetype
;
1288 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1295 * 'add_job()' - Add a job to a print queue.
1298 static cupsd_job_t
* /* O - Job object */
1299 add_job(cupsd_client_t
*con
, /* I - Client connection */
1300 cupsd_printer_t
*printer
, /* I - Destination printer */
1301 mime_type_t
*filetype
) /* I - First print file type, if any */
1303 http_status_t status
; /* Policy status */
1304 ipp_attribute_t
*attr
, /* Current attribute */
1305 *auth_info
; /* auth-info attribute */
1306 const char *val
; /* Default option value */
1307 int priority
; /* Job priority */
1308 char *title
; /* Job name/title */
1309 cupsd_job_t
*job
; /* Current job */
1310 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1311 int kbytes
; /* Size of print file */
1312 int i
; /* Looping var */
1313 int lowerpagerange
; /* Page range bound */
1316 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1317 con
, con
->http
.fd
, printer
, printer
->name
,
1318 filetype
, filetype
? filetype
->super
: "none",
1319 filetype
? filetype
->type
: "none");
1322 * Check remote printing to non-shared printer...
1325 if (!printer
->shared
&&
1326 strcasecmp(con
->http
.hostname
, "localhost") &&
1327 strcasecmp(con
->http
.hostname
, ServerName
))
1329 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1330 _("The printer or class is not shared!"));
1338 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1340 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1342 send_http_error(con
, status
, printer
);
1345 else if (printer
->num_auth_info_required
> 0 &&
1346 strcmp(printer
->auth_info_required
[0], "none") &&
1347 !con
->username
[0] && !auth_info
)
1349 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1353 else if (auth_info
&& !con
->http
.tls
&&
1354 !httpAddrLocalhost(con
->http
.hostaddr
))
1357 * Require encryption of auth-info over non-local connections...
1360 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1363 #endif /* HAVE_SSL */
1366 * See if the printer is accepting jobs...
1369 if (!printer
->accepting
)
1371 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1372 _("Destination \"%s\" is not accepting jobs."),
1378 * Validate job template attributes; for now just document-format,
1379 * copies, number-up, and page-ranges...
1382 if (filetype
&& printer
->filetypes
&&
1383 !cupsArrayFind(printer
->filetypes
, filetype
))
1385 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1386 /* MIME media type string */
1389 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1392 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1393 _("Unsupported format \'%s\'!"), mimetype
);
1395 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1396 "document-format", NULL
, mimetype
);
1401 if ((attr
= ippFindAttribute(con
->request
, "copies",
1402 IPP_TAG_INTEGER
)) != NULL
)
1404 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1406 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1407 attr
->values
[0].integer
);
1408 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1409 "copies", attr
->values
[0].integer
);
1414 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1415 IPP_TAG_ZERO
)) != NULL
)
1417 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1418 attr
->value_tag
!= IPP_TAG_NAME
)
1420 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type!"));
1424 if (attr
->num_values
> 2)
1426 send_ipp_status(con
, IPP_BAD_REQUEST
,
1427 _("Too many job-sheets values (%d > 2)!"),
1432 for (i
= 0; i
< attr
->num_values
; i
++)
1433 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1434 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1436 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"!"),
1437 attr
->values
[i
].string
.text
);
1442 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1443 IPP_TAG_INTEGER
)) != NULL
)
1445 if (attr
->values
[0].integer
!= 1 &&
1446 attr
->values
[0].integer
!= 2 &&
1447 attr
->values
[0].integer
!= 4 &&
1448 attr
->values
[0].integer
!= 6 &&
1449 attr
->values
[0].integer
!= 9 &&
1450 attr
->values
[0].integer
!= 16)
1452 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1453 attr
->values
[0].integer
);
1454 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1455 "number-up", attr
->values
[0].integer
);
1460 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1461 IPP_TAG_RANGE
)) != NULL
)
1463 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1465 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1466 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1468 send_ipp_status(con
, IPP_BAD_REQUEST
,
1469 _("Bad page-ranges values %d-%d."),
1470 attr
->values
[i
].range
.lower
,
1471 attr
->values
[i
].range
.upper
);
1475 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1480 * Make sure we aren't over our limit...
1483 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1486 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1488 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1489 _("Too many active jobs."));
1493 if ((i
= check_quotas(con
, printer
)) < 0)
1495 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1500 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1505 * Create the job and set things up...
1508 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1509 IPP_TAG_INTEGER
)) != NULL
)
1510 priority
= attr
->values
[0].integer
;
1513 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1514 printer
->options
)) != NULL
)
1515 priority
= atoi(val
);
1519 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1523 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1524 IPP_TAG_NAME
)) != NULL
)
1525 title
= attr
->values
[0].string
.text
;
1527 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1528 title
= "Untitled");
1530 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1532 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1533 _("Unable to add job for destination \"%s\"!"),
1538 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1539 CUPS_PRINTER_REMOTE
);
1540 job
->attrs
= con
->request
;
1542 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1544 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1546 add_job_uuid(con
, job
);
1547 apply_printer_defaults(printer
, job
);
1549 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1551 if (con
->username
[0])
1553 cupsdSetString(&job
->username
, con
->username
);
1556 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1560 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1561 "add_job: requesting-user-name=\"%s\"",
1562 attr
->values
[0].string
.text
);
1564 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1567 cupsdSetString(&job
->username
, "anonymous");
1570 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1571 "job-originating-user-name", NULL
, job
->username
);
1574 attr
->group_tag
= IPP_TAG_JOB
;
1575 _cupsStrFree(attr
->name
);
1576 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1579 if (con
->username
[0] || auth_info
)
1581 save_auth_info(con
, job
, auth_info
);
1584 * Remove the auth-info attribute from the attribute data...
1588 ippDeleteAttribute(job
->attrs
, auth_info
);
1591 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1592 IPP_TAG_ZERO
)) != NULL
)
1595 * Request contains a job-originating-host-name attribute; validate it...
1598 if (attr
->value_tag
!= IPP_TAG_NAME
||
1599 attr
->num_values
!= 1 ||
1600 strcmp(con
->http
.hostname
, "localhost"))
1603 * Can't override the value if we aren't connected via localhost.
1604 * Also, we can only have 1 value and it must be a name value.
1607 switch (attr
->value_tag
)
1609 case IPP_TAG_STRING
:
1610 case IPP_TAG_TEXTLANG
:
1611 case IPP_TAG_NAMELANG
:
1614 case IPP_TAG_KEYWORD
:
1616 case IPP_TAG_URISCHEME
:
1617 case IPP_TAG_CHARSET
:
1618 case IPP_TAG_LANGUAGE
:
1619 case IPP_TAG_MIMETYPE
:
1621 * Free old strings...
1624 for (i
= 0; i
< attr
->num_values
; i
++)
1626 _cupsStrFree(attr
->values
[i
].string
.text
);
1627 attr
->values
[i
].string
.text
= NULL
;
1628 if (attr
->values
[i
].string
.charset
)
1630 _cupsStrFree(attr
->values
[i
].string
.charset
);
1631 attr
->values
[i
].string
.charset
= NULL
;
1640 * Use the default connection hostname instead...
1643 attr
->value_tag
= IPP_TAG_NAME
;
1644 attr
->num_values
= 1;
1645 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1648 attr
->group_tag
= IPP_TAG_JOB
;
1653 * No job-originating-host-name attribute, so use the hostname from
1657 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1658 "job-originating-host-name", NULL
, con
->http
.hostname
);
1661 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1663 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1664 "time-at-processing", 0);
1665 attr
->value_tag
= IPP_TAG_NOVALUE
;
1666 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1667 "time-at-completed", 0);
1668 attr
->value_tag
= IPP_TAG_NOVALUE
;
1671 * Add remaining job attributes...
1674 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1675 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1676 "job-state", IPP_JOB_STOPPED
);
1677 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1678 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1679 "job-media-sheets-completed", 0);
1680 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1682 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1685 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1686 IPP_TAG_INTEGER
)) != NULL
)
1687 attr
->values
[0].integer
= 0;
1689 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1691 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1692 IPP_TAG_KEYWORD
)) == NULL
)
1693 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1696 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1697 printer
->options
)) == NULL
)
1700 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1701 "job-hold-until", NULL
, val
);
1703 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1704 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1707 * Hold job until specified time...
1710 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1712 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1713 job
->state_value
= IPP_JOB_HELD
;
1715 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1717 job
->hold_until
= time(NULL
) + 60;
1718 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1719 job
->state_value
= IPP_JOB_HELD
;
1723 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1724 job
->state_value
= IPP_JOB_PENDING
;
1727 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1731 * Add job sheets options...
1734 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1735 IPP_TAG_ZERO
)) == NULL
)
1737 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1738 "Adding default job-sheets values \"%s,%s\"...",
1739 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1741 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1743 attr
->values
[0].string
.text
= _cupsStrAlloc(printer
->job_sheets
[0]);
1744 attr
->values
[1].string
.text
= _cupsStrAlloc(printer
->job_sheets
[1]);
1747 job
->job_sheets
= attr
;
1750 * Enforce classification level if set...
1755 cupsdLogMessage(CUPSD_LOG_INFO
,
1756 "Classification=\"%s\", ClassifyOverride=%d",
1757 Classification
? Classification
: "(null)",
1760 if (ClassifyOverride
)
1762 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1763 (attr
->num_values
== 1 ||
1764 !strcmp(attr
->values
[1].string
.text
, "none")))
1767 * Force the leading banner to have the classification on it...
1770 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1772 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1773 "job-sheets=\"%s,none\", "
1774 "job-originating-user-name=\"%s\"",
1775 Classification
, job
->username
);
1777 else if (attr
->num_values
== 2 &&
1778 strcmp(attr
->values
[0].string
.text
,
1779 attr
->values
[1].string
.text
) &&
1780 strcmp(attr
->values
[0].string
.text
, "none") &&
1781 strcmp(attr
->values
[1].string
.text
, "none"))
1784 * Can't put two different security markings on the same document!
1787 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1789 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1790 "job-sheets=\"%s,%s\", "
1791 "job-originating-user-name=\"%s\"",
1792 attr
->values
[0].string
.text
,
1793 attr
->values
[1].string
.text
, job
->username
);
1795 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1796 strcmp(attr
->values
[0].string
.text
, "none") &&
1797 (attr
->num_values
== 1 ||
1798 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1799 strcmp(attr
->values
[1].string
.text
, "none"))))
1801 if (attr
->num_values
== 1)
1802 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1803 "CLASSIFICATION OVERRIDDEN "
1804 "job-sheets=\"%s\", "
1805 "job-originating-user-name=\"%s\"",
1806 attr
->values
[0].string
.text
, job
->username
);
1808 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1809 "CLASSIFICATION OVERRIDDEN "
1810 "job-sheets=\"%s,%s\",fffff "
1811 "job-originating-user-name=\"%s\"",
1812 attr
->values
[0].string
.text
,
1813 attr
->values
[1].string
.text
, job
->username
);
1816 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1817 (attr
->num_values
== 1 ||
1818 strcmp(attr
->values
[1].string
.text
, Classification
)))
1821 * Force the banner to have the classification on it...
1824 if (attr
->num_values
> 1 &&
1825 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1827 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1828 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1832 if (attr
->num_values
== 1 ||
1833 strcmp(attr
->values
[0].string
.text
, "none"))
1834 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1836 if (attr
->num_values
> 1 &&
1837 strcmp(attr
->values
[1].string
.text
, "none"))
1838 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1841 if (attr
->num_values
> 1)
1842 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1843 "CLASSIFICATION FORCED "
1844 "job-sheets=\"%s,%s\", "
1845 "job-originating-user-name=\"%s\"",
1846 attr
->values
[0].string
.text
,
1847 attr
->values
[1].string
.text
, job
->username
);
1849 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1850 "CLASSIFICATION FORCED "
1851 "job-sheets=\"%s\", "
1852 "job-originating-user-name=\"%s\"",
1853 Classification
, job
->username
);
1858 * See if we need to add the starting sheet...
1861 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1863 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1864 attr
->values
[0].string
.text
);
1866 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1868 cupsdDeleteJob(job
);
1872 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1875 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1876 IPP_TAG_ZERO
)) != NULL
)
1880 * Fill in the response info...
1883 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1884 LocalPort
, job
->id
);
1886 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1889 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1891 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1893 add_job_state_reasons(con
, job
);
1895 con
->response
->request
.status
.status_code
= IPP_OK
;
1898 * Add any job subscriptions...
1901 add_job_subscriptions(con
, job
);
1904 * Set all but the first two attributes to the job attributes group...
1907 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1908 attr
->group_tag
= IPP_TAG_JOB
;
1911 * Fire the "job created" event...
1914 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1917 * Return the new job...
1925 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1926 * upon the job and printer state...
1930 add_job_state_reasons(
1931 cupsd_client_t
*con
, /* I - Client connection */
1932 cupsd_job_t
*job
) /* I - Job info */
1934 cupsd_printer_t
*dest
; /* Destination printer */
1937 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1938 con
, con
->http
.fd
, job
? job
->id
: 0);
1940 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1942 case IPP_JOB_PENDING
:
1943 dest
= cupsdFindDest(job
->dest
);
1945 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1946 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1947 "job-state-reasons", NULL
, "printer-stopped");
1949 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1950 "job-state-reasons", NULL
, "none");
1954 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1955 IPP_TAG_KEYWORD
) != NULL
||
1956 ippFindAttribute(job
->attrs
, "job-hold-until",
1957 IPP_TAG_NAME
) != NULL
)
1958 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1959 "job-state-reasons", NULL
, "job-hold-until-specified");
1961 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1962 "job-state-reasons", NULL
, "job-incoming");
1965 case IPP_JOB_PROCESSING
:
1966 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1967 "job-state-reasons", NULL
, "job-printing");
1970 case IPP_JOB_STOPPED
:
1971 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1972 "job-state-reasons", NULL
, "job-stopped");
1975 case IPP_JOB_CANCELED
:
1976 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1977 "job-state-reasons", NULL
, "job-canceled-by-user");
1980 case IPP_JOB_ABORTED
:
1981 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1982 "job-state-reasons", NULL
, "aborted-by-system");
1985 case IPP_JOB_COMPLETED
:
1986 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1987 "job-state-reasons", NULL
, "job-completed-successfully");
1994 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1998 add_job_subscriptions(
1999 cupsd_client_t
*con
, /* I - Client connection */
2000 cupsd_job_t
*job
) /* I - Newly created job */
2002 int i
; /* Looping var */
2003 ipp_attribute_t
*prev
, /* Previous attribute */
2004 *next
, /* Next attribute */
2005 *attr
; /* Current attribute */
2006 cupsd_subscription_t
*sub
; /* Subscription object */
2007 const char *recipient
, /* notify-recipient-uri */
2008 *pullmethod
; /* notify-pull-method */
2009 ipp_attribute_t
*user_data
; /* notify-user-data */
2010 int interval
; /* notify-time-interval */
2011 unsigned mask
; /* notify-events */
2015 * Find the first subscription group attribute; return if we have
2019 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2020 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2027 * Process the subscription attributes in the request...
2036 mask
= CUPSD_EVENT_NONE
;
2038 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2040 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2041 attr
->value_tag
== IPP_TAG_URI
)
2044 * Validate the recipient scheme against the ServerBin/notifier
2048 char notifier
[1024], /* Notifier filename */
2049 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2050 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2051 host
[HTTP_MAX_URI
], /* Host portion of URI */
2052 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2053 int port
; /* Port portion of URI */
2056 recipient
= attr
->values
[0].string
.text
;
2058 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2059 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2060 host
, sizeof(host
), &port
,
2061 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2063 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2064 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
2065 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2066 "notify-status-code", IPP_URI_SCHEME
);
2070 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2072 if (access(notifier
, X_OK
))
2074 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2075 _("notify-recipient-uri URI \"%s\" uses unknown "
2076 "scheme!"), recipient
);
2077 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2078 "notify-status-code", IPP_URI_SCHEME
);
2082 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2084 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2085 _("notify-recipient-uri URI \"%s\" is already used!"),
2087 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2088 "notify-status-code", IPP_ATTRIBUTES
);
2092 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2093 attr
->value_tag
== IPP_TAG_KEYWORD
)
2095 pullmethod
= attr
->values
[0].string
.text
;
2097 if (strcmp(pullmethod
, "ippget"))
2099 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2100 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
2101 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2102 "notify-status-code", IPP_ATTRIBUTES
);
2106 else if (!strcmp(attr
->name
, "notify-charset") &&
2107 attr
->value_tag
== IPP_TAG_CHARSET
&&
2108 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2109 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2111 send_ipp_status(con
, IPP_CHARSET
,
2112 _("Character set \"%s\" not supported!"),
2113 attr
->values
[0].string
.text
);
2116 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2117 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2118 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2120 send_ipp_status(con
, IPP_CHARSET
,
2121 _("Language \"%s\" not supported!"),
2122 attr
->values
[0].string
.text
);
2125 else if (!strcmp(attr
->name
, "notify-user-data") &&
2126 attr
->value_tag
== IPP_TAG_STRING
)
2128 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2130 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2131 _("The notify-user-data value is too large "
2132 "(%d > 63 octets)!"),
2133 attr
->values
[0].unknown
.length
);
2139 else if (!strcmp(attr
->name
, "notify-events") &&
2140 attr
->value_tag
== IPP_TAG_KEYWORD
)
2142 for (i
= 0; i
< attr
->num_values
; i
++)
2143 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2145 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2147 send_ipp_status(con
, IPP_BAD_REQUEST
,
2148 _("The notify-lease-duration attribute cannot be "
2149 "used with job subscriptions."));
2152 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2153 attr
->value_tag
== IPP_TAG_INTEGER
)
2154 interval
= attr
->values
[0].integer
;
2159 if (!recipient
&& !pullmethod
)
2162 if (mask
== CUPSD_EVENT_NONE
)
2163 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2165 sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
, recipient
,
2168 sub
->interval
= interval
;
2170 cupsdSetString(&sub
->owner
, job
->username
);
2174 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2175 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2176 sub
->user_data_len
);
2179 ippAddSeparator(con
->response
);
2180 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2181 "notify-subscription-id", sub
->id
);
2187 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2190 * Remove all of the subscription attributes from the job request...
2192 * TODO: Optimize this since subscription groups have to come at the
2193 * end of the request...
2196 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2200 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2201 attr
->group_tag
== IPP_TAG_ZERO
)
2204 * Free and remove this attribute...
2212 job
->attrs
->attrs
= next
;
2218 job
->attrs
->last
= prev
;
2219 job
->attrs
->current
= prev
;
2224 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2226 * See RFC 4122 for the definition of UUIDs and the format.
2230 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2231 cupsd_job_t
*job
) /* I - Job */
2233 char uuid
[1024]; /* job-uuid string */
2234 _cups_md5_state_t md5state
; /* MD5 state */
2235 unsigned char md5sum
[16]; /* MD5 digest/sum */
2239 * First see if the job already has a job-uuid attribute; if so, return...
2242 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2246 * No job-uuid attribute, so build a version 3 UUID with the local job
2247 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2248 * the ServerName, server name and port that the client connected to,
2249 * and local job ID...
2252 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2253 con
->serverport
, job
->id
);
2255 _cupsMD5Init(&md5state
);
2256 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2257 _cupsMD5Finish(&md5state
, md5sum
);
2260 * Format the UUID URI using the MD5 sum and job ID.
2263 snprintf(uuid
, sizeof(uuid
),
2264 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2265 "%02x%02x%02x%02x%02x%02x",
2266 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2267 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2268 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2269 md5sum
[14], md5sum
[15]);
2271 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2276 * 'add_printer()' - Add a printer to the system.
2280 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2281 ipp_attribute_t
*uri
) /* I - URI of printer */
2283 http_status_t status
; /* Policy status */
2284 int i
; /* Looping var */
2285 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2286 username
[HTTP_MAX_URI
], /* Username portion of URI */
2287 host
[HTTP_MAX_URI
], /* Host portion of URI */
2288 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2289 int port
; /* Port portion of URI */
2290 cupsd_printer_t
*printer
; /* Printer/class */
2291 ipp_attribute_t
*attr
; /* Printer attribute */
2292 cups_file_t
*fp
; /* Script/PPD file */
2293 char line
[1024]; /* Line from file... */
2294 char srcfile
[1024], /* Source Script/PPD file */
2295 dstfile
[1024]; /* Destination Script/PPD file */
2296 int modify
; /* Non-zero if we are modifying */
2297 char newname
[IPP_MAX_NAME
]; /* New printer name */
2298 int need_restart_job
; /* Need to restart job? */
2299 int set_device_uri
, /* Did we set the device URI? */
2300 set_port_monitor
; /* Did we set the port monitor? */
2303 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2304 con
->http
.fd
, uri
->values
[0].string
.text
);
2307 * Do we have a valid URI?
2310 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2311 sizeof(scheme
), username
, sizeof(username
), host
,
2312 sizeof(host
), &port
, resource
, sizeof(resource
));
2314 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2317 * No, return an error...
2320 send_ipp_status(con
, IPP_BAD_REQUEST
,
2321 _("The printer-uri must be of the form "
2322 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2327 * Do we have a valid printer name?
2330 if (!validate_name(resource
+ 10))
2333 * No, return an error...
2336 send_ipp_status(con
, IPP_BAD_REQUEST
,
2337 _("The printer-uri \"%s\" contains invalid characters."),
2338 uri
->values
[0].string
.text
);
2343 * See if the printer already exists; if not, create a new printer...
2346 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2349 * Printer doesn't exist; see if we have a class of the same name...
2352 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2353 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2356 * Yes, return an error...
2359 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2360 _("A class named \"%s\" already exists!"),
2366 * No, check the default policy then add the printer...
2369 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2371 send_http_error(con
, status
, NULL
);
2375 printer
= cupsdAddPrinter(resource
+ 10);
2378 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2381 * Check the default policy, then rename the implicit printer to
2382 * "AnyPrinter" or delete it...
2385 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2387 send_http_error(con
, status
, NULL
);
2391 if (ImplicitAnyClasses
)
2393 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2394 cupsdRenamePrinter(printer
, newname
);
2397 cupsdDeletePrinter(printer
, 1);
2400 * Add the printer as a new local printer...
2403 printer
= cupsdAddPrinter(resource
+ 10);
2406 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2409 * Check the default policy, then rename the remote printer to
2410 * "Printer@server"...
2413 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2415 send_http_error(con
, status
, NULL
);
2419 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2421 cupsdRenamePrinter(printer
, newname
);
2424 * Add the printer as a new local printer...
2427 printer
= cupsdAddPrinter(resource
+ 10);
2430 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2433 send_http_error(con
, status
, printer
);
2440 * Look for attributes and copy them over as needed...
2443 need_restart_job
= 0;
2445 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2446 IPP_TAG_TEXT
)) != NULL
)
2447 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2449 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2450 IPP_TAG_TEXT
)) != NULL
)
2451 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2455 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2456 IPP_TAG_URI
)) != NULL
)
2459 * Do we have a valid device URI?
2462 http_uri_status_t uri_status
; /* URI separation status */
2463 char old_device_uri
[1024];
2464 /* Old device URI */
2467 need_restart_job
= 1;
2469 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2470 attr
->values
[0].string
.text
,
2471 scheme
, sizeof(scheme
),
2472 username
, sizeof(username
),
2473 host
, sizeof(host
), &port
,
2474 resource
, sizeof(resource
));
2476 if (uri_status
< HTTP_URI_OK
)
2478 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2479 attr
->values
[0].string
.text
);
2480 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2481 "add_printer: httpSeparateURI returned %d", uri_status
);
2485 if (!strcmp(scheme
, "file"))
2488 * See if the administrator has enabled file devices...
2491 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2494 * File devices are disabled and the URL is not file:/dev/null...
2497 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2498 _("File device URIs have been disabled! "
2499 "To enable, see the FileDevice directive in "
2500 "\"%s/cupsd.conf\"."),
2508 * See if the backend exists and is executable...
2511 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2512 if (access(srcfile
, X_OK
))
2515 * Could not find device in list!
2518 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri scheme \"%s\"!"),
2524 if (printer
->sanitized_device_uri
)
2525 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2526 sizeof(old_device_uri
));
2528 old_device_uri
[0] = '\0';
2530 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2532 cupsdLogMessage(CUPSD_LOG_INFO
,
2533 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2534 printer
->name
, printer
->sanitized_device_uri
,
2540 set_port_monitor
= 0;
2542 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2543 IPP_TAG_NAME
)) != NULL
)
2545 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2548 need_restart_job
= 1;
2550 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2554 for (i
= 0; i
< supported
->num_values
; i
++)
2555 if (!strcmp(supported
->values
[i
].string
.text
,
2556 attr
->values
[0].string
.text
))
2560 if (!supported
|| i
>= supported
->num_values
)
2562 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2563 attr
->values
[0].string
.text
);
2567 cupsdLogMessage(CUPSD_LOG_INFO
,
2568 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2569 printer
->name
, attr
->values
[0].string
.text
,
2570 printer
->port_monitor
? printer
->port_monitor
: "none");
2572 if (strcmp(attr
->values
[0].string
.text
, "none"))
2573 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2575 cupsdClearString(&printer
->port_monitor
);
2577 set_port_monitor
= 1;
2580 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2581 IPP_TAG_BOOLEAN
)) != NULL
)
2583 cupsdLogMessage(CUPSD_LOG_INFO
,
2584 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2585 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2587 printer
->accepting
= attr
->values
[0].boolean
;
2588 cupsdAddPrinterHistory(printer
);
2591 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2592 IPP_TAG_BOOLEAN
)) != NULL
)
2594 if (printer
->shared
&& !attr
->values
[0].boolean
)
2595 cupsdDeregisterPrinter(printer
, 1);
2597 cupsdLogMessage(CUPSD_LOG_INFO
,
2598 "Setting %s printer-is-shared to %d (was %d.)",
2599 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2601 printer
->shared
= attr
->values
[0].boolean
;
2604 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2605 IPP_TAG_ENUM
)) != NULL
)
2607 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2608 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2610 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2611 attr
->values
[0].integer
);
2615 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2616 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2618 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2619 cupsdStopPrinter(printer
, 0);
2622 need_restart_job
= 1;
2623 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2626 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2627 IPP_TAG_TEXT
)) != NULL
)
2629 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2630 sizeof(printer
->state_message
));
2631 cupsdAddPrinterHistory(printer
);
2634 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2635 IPP_TAG_KEYWORD
)) != NULL
)
2637 if (attr
->num_values
>
2638 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2640 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2641 _("Too many printer-state-reasons values (%d > %d)!"),
2643 (int)(sizeof(printer
->reasons
) /
2644 sizeof(printer
->reasons
[0])));
2648 for (i
= 0; i
< printer
->num_reasons
; i
++)
2649 _cupsStrFree(printer
->reasons
[i
]);
2651 printer
->num_reasons
= 0;
2652 for (i
= 0; i
< attr
->num_values
; i
++)
2654 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2657 printer
->reasons
[printer
->num_reasons
] =
2658 _cupsStrAlloc(attr
->values
[i
].string
.text
);
2660 if (!strcmp(printer
->reasons
[printer
->num_reasons
], "paused") &&
2661 printer
->state
!= IPP_PRINTER_STOPPED
)
2663 cupsdLogMessage(CUPSD_LOG_INFO
,
2664 "Setting %s printer-state to %d (was %d.)",
2665 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2666 cupsdStopPrinter(printer
, 0);
2669 printer
->num_reasons
++;
2672 if (PrintcapFormat
== PRINTCAP_PLIST
)
2673 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2676 set_printer_defaults(con
, printer
);
2678 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2679 IPP_TAG_KEYWORD
)) != NULL
)
2680 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2683 * See if we have all required attributes...
2686 if (!printer
->device_uri
)
2687 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2690 * See if we have an interface script or PPD file attached to the request...
2695 need_restart_job
= 1;
2697 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2699 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2702 * Yes; get the first line from it...
2706 cupsFileGets(fp
, line
, sizeof(line
));
2710 * Then see what kind of file it is...
2713 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2716 if (!strncmp(line
, "*PPD-Adobe", 10))
2719 * The new file is a PPD file, so remove any old interface script
2720 * that might be lying around...
2728 * This must be an interface script, so move the file over to the
2729 * interfaces directory and make it executable...
2732 if (copy_file(srcfile
, dstfile
))
2734 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2735 _("Unable to copy interface script - %s!"),
2740 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2741 "Copied interface script successfully!");
2742 chmod(dstfile
, 0755);
2745 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2748 if (!strncmp(line
, "*PPD-Adobe", 10))
2751 * The new file is a PPD file, so move the file over to the
2752 * ppd directory and make it readable by all...
2755 if (copy_file(srcfile
, dstfile
))
2757 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2758 _("Unable to copy PPD file - %s!"),
2763 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2764 "Copied PPD file successfully!");
2765 chmod(dstfile
, 0644);
2769 * (Re)register color profiles...
2774 apple_unregister_profiles(printer
);
2775 apple_register_profiles(printer
);
2777 #endif /* __APPLE__ */
2782 * This must be an interface script, so remove any old PPD file that
2783 * may be lying around...
2790 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2791 IPP_TAG_NAME
)) != NULL
)
2793 need_restart_job
= 1;
2795 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2798 * Raw driver, remove any existing PPD or interface script files.
2801 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2805 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2815 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2819 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2822 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2824 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2828 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2829 "Copied PPD file successfully!");
2830 chmod(dstfile
, 0644);
2834 * (Re)register color profiles...
2839 apple_unregister_profiles(printer
);
2840 apple_register_profiles(printer
);
2842 #endif /* __APPLE__ */
2847 * If we set the device URI but not the port monitor, check which port
2848 * monitor to use by default...
2851 if (set_device_uri
&& !set_port_monitor
)
2853 ppd_file_t
*ppd
; /* PPD file */
2854 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2857 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2858 sizeof(scheme
), username
, sizeof(username
), host
,
2859 sizeof(host
), &port
, resource
, sizeof(resource
));
2861 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2863 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2865 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2867 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2868 if (!strcmp(scheme
, ppdattr
->spec
))
2870 cupsdLogMessage(CUPSD_LOG_INFO
,
2871 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2872 printer
->name
, ppdattr
->value
,
2873 printer
->port_monitor
? printer
->port_monitor
2876 if (strcmp(ppdattr
->value
, "none"))
2877 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2879 cupsdClearString(&printer
->port_monitor
);
2889 * Update the printer attributes and return...
2892 cupsdSetPrinterAttrs(printer
);
2893 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2895 if (need_restart_job
&& printer
->job
)
2900 * Stop the current job and then restart it below...
2903 job
= (cupsd_job_t
*)printer
->job
;
2905 cupsdStopJob(job
, 1);
2907 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2908 job
->state_value
= IPP_JOB_PENDING
;
2911 if (need_restart_job
)
2914 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2918 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2919 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2922 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2923 printer
->name
, get_username(con
));
2927 cupsdAddPrinterHistory(printer
);
2929 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2930 "New printer \"%s\" added by \"%s\".", printer
->name
,
2933 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2934 printer
->name
, get_username(con
));
2937 con
->response
->request
.status
.status_code
= IPP_OK
;
2942 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2943 * based upon the printer state...
2947 add_printer_state_reasons(
2948 cupsd_client_t
*con
, /* I - Client connection */
2949 cupsd_printer_t
*p
) /* I - Printer info */
2951 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2952 "add_printer_state_reasons(%p[%d], %p[%s])",
2953 con
, con
->http
.fd
, p
, p
->name
);
2955 if (p
->num_reasons
== 0)
2956 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2957 "printer-state-reasons", NULL
,
2958 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2960 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2961 "printer-state-reasons", p
->num_reasons
, NULL
,
2962 (const char * const *)p
->reasons
);
2967 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2968 * the specified printer or class.
2972 add_queued_job_count(
2973 cupsd_client_t
*con
, /* I - Client connection */
2974 cupsd_printer_t
*p
) /* I - Printer or class */
2976 int count
; /* Number of jobs on destination */
2979 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2980 con
, con
->http
.fd
, p
, p
->name
);
2982 count
= cupsdGetPrinterJobCount(p
->name
);
2984 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2985 "queued-job-count", count
);
2991 * 'apple_init_profile()' - Initialize a color profile.
2996 ppd_file_t
*ppd
, /* I - PPD file */
2997 cups_array_t
*languages
, /* I - Languages in the PPD file */
2998 CMDeviceProfileInfo
*profile
, /* I - Profile record */
2999 unsigned id
, /* I - Profile ID */
3000 const char *name
, /* I - Profile name */
3001 const char *text
, /* I - Profile UI text */
3002 const char *iccfile
) /* I - ICC filename */
3004 char url
[1024]; /* URL for profile filename */
3005 CFMutableDictionaryRef dict
; /* Dictionary for name */
3006 char *language
; /* Current language */
3007 ppd_attr_t
*attr
; /* Profile attribute */
3008 CFStringRef cflang
, /* Language string */
3009 cftext
; /* Localized text */
3013 * Build the profile name dictionary...
3016 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3017 &kCFTypeDictionaryKeyCallBacks
,
3018 &kCFTypeDictionaryValueCallBacks
);
3020 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
3021 kCFStringEncodingUTF8
);
3025 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
3032 * Find localized names for the color profiles...
3035 cupsArraySave(ppd
->sorted_attrs
);
3037 for (language
= (char *)cupsArrayFirst(languages
);
3039 language
= (char *)cupsArrayNext(languages
))
3043 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
3045 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
3048 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
3050 if (attr
&& attr
->text
[0])
3052 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
3053 kCFStringEncodingUTF8
);
3054 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
3055 kCFStringEncodingUTF8
);
3057 if (cflang
&& cftext
)
3058 CFDictionarySetValue(dict
, cflang
, cftext
);
3068 cupsArrayRestore(ppd
->sorted_attrs
);
3072 * Fill in the profile data...
3076 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3079 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3080 profile
->profileID
= id
;
3081 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3082 profile
->profileName
= dict
;
3085 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3086 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3091 * 'apple_register_profiles()' - Register color profiles for a printer.
3095 apple_register_profiles(
3096 cupsd_printer_t
*p
) /* I - Printer */
3098 int i
; /* Looping var */
3099 char ppdfile
[1024], /* PPD filename */
3100 iccfile
[1024], /* ICC filename */
3101 selector
[PPD_MAX_NAME
];
3102 /* Profile selection string */
3103 ppd_file_t
*ppd
; /* PPD file */
3104 ppd_attr_t
*attr
, /* Profile attributes */
3105 *profileid_attr
,/* cupsProfileID attribute */
3106 *q1_attr
, /* ColorModel (or other) qualifier */
3107 *q2_attr
, /* MediaType (or other) qualifier */
3108 *q3_attr
; /* Resolution (or other) qualifier */
3109 char q_keyword
[PPD_MAX_NAME
];
3110 /* Qualifier keyword */
3111 const char *q1_choice
, /* ColorModel (or other) choice */
3112 *q2_choice
, /* MediaType (or other) choice */
3113 *q3_choice
; /* Resolution (or other) choice */
3114 const char *profile_key
; /* Profile keyword */
3115 ppd_option_t
*cm_option
; /* Color model option */
3116 ppd_choice_t
*cm_choice
; /* Color model choice */
3117 int num_profiles
; /* Number of profiles */
3118 CMError error
; /* Last error */
3119 unsigned device_id
, /* Printer device ID */
3120 profile_id
, /* Profile ID */
3121 default_profile_id
= 0;
3122 /* Default profile ID */
3123 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3124 CFStringRef printer_name
; /* Printer name string */
3125 CMDeviceScope scope
= /* Scope of the registration */
3127 kCFPreferencesAnyUser
,
3128 kCFPreferencesCurrentHost
3130 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3131 CMDeviceProfileInfo
*profile
; /* Current profile */
3132 cups_array_t
*languages
; /* Languages array */
3136 * Make sure ColorSync is available...
3139 if (CMRegisterColorDevice
== NULL
)
3143 * Try opening the PPD file for this printer...
3146 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3147 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3151 * See if we have any profiles...
3154 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3155 profile_key
= "APTiogaProfile";
3158 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3159 profile_key
= "cupsICCProfile";
3162 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3163 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3165 if (attr
->value
[0] != '/')
3166 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3169 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3171 if (access(iccfile
, 0))
3179 * If we have profiles, add them...
3182 if (num_profiles
> 0)
3184 if (profile_key
[0] == 'A')
3187 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3191 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3193 default_profile_id
= atoi(attr
->value
);
3195 q1_choice
= q2_choice
= q3_choice
= NULL
;
3200 * For CUPS PPDs, figure out the default profile selector values...
3203 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3204 attr
->value
&& attr
->value
[0])
3206 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3207 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3209 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3210 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3212 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3213 q1_choice
= q1_attr
->value
;
3217 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3218 attr
->value
&& attr
->value
[0])
3220 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3221 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3224 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3226 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3227 q2_choice
= q2_attr
->value
;
3231 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3232 attr
->value
&& attr
->value
[0])
3234 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3235 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3238 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3240 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3241 q3_choice
= q3_attr
->value
;
3247 * Build the array of profiles...
3249 * Note: This calloc actually requests slightly more memory than needed.
3252 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3254 cupsdLogMessage(CUPSD_LOG_ERROR
,
3255 "Unable to allocate memory for %d profiles!",
3261 profiles
->profileCount
= num_profiles
;
3262 languages
= _ppdGetLanguages(ppd
);
3264 for (profile
= profiles
->profiles
,
3265 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3267 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3268 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3271 * Add this profile...
3274 if (attr
->value
[0] != '/')
3275 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3278 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3280 if (access(iccfile
, 0))
3283 if (profile_key
[0] == 'c')
3285 cupsArraySave(ppd
->sorted_attrs
);
3287 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3288 attr
->spec
)) != NULL
&&
3289 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3290 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3292 profile_id
= _ppdHashName(attr
->spec
);
3294 cupsArrayRestore(ppd
->sorted_attrs
);
3297 profile_id
= atoi(attr
->spec
);
3299 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3300 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3305 * See if this is the default profile...
3308 if (!default_profile_id
)
3314 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3315 q1_choice
, q2_choice
, q3_choice
);
3316 if (!strcmp(selector
, attr
->spec
))
3317 default_profile_id
= profile_id
;
3320 if (!default_profile_id
)
3322 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3324 if (!strcmp(selector
, attr
->spec
))
3325 default_profile_id
= profile_id
;
3329 if (!default_profile_id
&& q3_choice
)
3331 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3333 if (!strcmp(selector
, attr
->spec
))
3334 default_profile_id
= profile_id
;
3337 if (!default_profile_id
)
3339 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3340 if (!strcmp(selector
, attr
->spec
))
3341 default_profile_id
= profile_id
;
3346 _ppdFreeLanguages(languages
);
3348 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3351 * Extract profiles from ColorModel option...
3354 const char *profile_name
; /* Name of generic profile */
3357 num_profiles
= cm_option
->num_choices
;
3359 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3361 cupsdLogMessage(CUPSD_LOG_ERROR
,
3362 "Unable to allocate memory for %d profiles!",
3368 profiles
->profileCount
= num_profiles
;
3370 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3371 cm_choice
= cm_option
->choices
;
3373 i
--, cm_choice
++, profile
++)
3375 if (!strcmp(cm_choice
->choice
, "Gray") ||
3376 !strcmp(cm_choice
->choice
, "Black"))
3377 profile_name
= "Gray";
3378 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3379 !strcmp(cm_choice
->choice
, "CMY"))
3380 profile_name
= "RGB";
3381 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3382 !strcmp(cm_choice
->choice
, "KCMY"))
3383 profile_name
= "CMYK";
3385 profile_name
= "DeviceN";
3387 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3388 profile_id
= _ppdHashName(selector
);
3390 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3391 cm_choice
->text
, NULL
);
3393 if (cm_choice
->marked
)
3394 default_profile_id
= profile_id
;
3400 * Use the default colorspace...
3403 num_profiles
= 1 + ppd
->colorspace
!= PPD_CS_GRAY
;
3405 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3407 cupsdLogMessage(CUPSD_LOG_ERROR
,
3408 "Unable to allocate memory for %d profiles!",
3414 profiles
->profileCount
= num_profiles
;
3416 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3417 "Gray", "Gray", NULL
);
3419 switch (ppd
->colorspace
)
3423 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3424 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3428 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3429 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3433 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3434 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3443 if (num_profiles
> 0)
3446 * Make sure we have a default profile ID...
3449 if (!default_profile_id
)
3450 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3453 * Get the device ID hash and pathelogical name dictionary.
3456 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3459 device_id
= _ppdHashName(p
->name
);
3460 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3461 &kCFTypeDictionaryKeyCallBacks
,
3462 &kCFTypeDictionaryValueCallBacks
);
3463 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
,
3464 p
->name
, kCFStringEncodingUTF8
);
3466 if (device_name
&& printer_name
)
3468 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3471 * Register the device with ColorSync...
3474 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3475 device_name
, &scope
);
3478 * Register the profiles...
3482 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3483 default_profile_id
, profiles
);
3493 cupsdLogMessage(CUPSD_LOG_ERROR
,
3494 "Unable to register ICC color profiles for \"%s\" - %d",
3495 p
->name
, (int)error
);
3497 for (profile
= profiles
->profiles
;
3499 profile
++, num_profiles
--)
3500 CFRelease(profile
->profileName
);
3505 CFRelease(printer_name
);
3508 CFRelease(device_name
);
3516 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3521 apple_unregister_profiles(
3522 cupsd_printer_t
*p
) /* I - Printer */
3525 * Make sure ColorSync is available...
3528 if (CMUnregisterColorDevice
!= NULL
)
3529 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3531 #endif /* __APPLE__ */
3534 * 'apply_printer_defaults()' - Apply printer default options to a job.
3538 apply_printer_defaults(
3539 cupsd_printer_t
*printer
, /* I - Printer */
3540 cupsd_job_t
*job
) /* I - Job */
3542 int i
, /* Looping var */
3543 num_options
; /* Number of default options */
3544 cups_option_t
*options
, /* Default options */
3545 *option
; /* Current option */
3549 * Collect all of the default options and add the missing ones to the
3553 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3554 option
= printer
->options
;
3557 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3559 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3564 * Encode these options as attributes in the job object...
3567 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3568 cupsFreeOptions(num_options
, options
);
3573 * 'authenticate_job()' - Set job authentication info.
3577 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3578 ipp_attribute_t
*uri
) /* I - Job URI */
3580 ipp_attribute_t
*attr
, /* job-id attribute */
3581 *auth_info
; /* auth-info attribute */
3582 int jobid
; /* Job ID */
3583 cupsd_job_t
*job
; /* Current job */
3584 char scheme
[HTTP_MAX_URI
],
3585 /* Method portion of URI */
3586 username
[HTTP_MAX_URI
],
3587 /* Username portion of URI */
3589 /* Host portion of URI */
3590 resource
[HTTP_MAX_URI
];
3591 /* Resource portion of URI */
3592 int port
; /* Port portion of URI */
3595 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3596 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3599 * Start with "everything is OK" status...
3602 con
->response
->request
.status
.status_code
= IPP_OK
;
3605 * See if we have a job URI or a printer URI...
3608 if (!strcmp(uri
->name
, "printer-uri"))
3611 * Got a printer URI; see if we also have a job-id attribute...
3614 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3615 IPP_TAG_INTEGER
)) == NULL
)
3617 send_ipp_status(con
, IPP_BAD_REQUEST
,
3618 _("Got a printer-uri attribute but no job-id!"));
3622 jobid
= attr
->values
[0].integer
;
3627 * Got a job URI; parse it to get the job ID...
3630 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3631 sizeof(scheme
), username
, sizeof(username
), host
,
3632 sizeof(host
), &port
, resource
, sizeof(resource
));
3634 if (strncmp(resource
, "/jobs/", 6))
3640 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3641 uri
->values
[0].string
.text
);
3645 jobid
= atoi(resource
+ 6);
3649 * See if the job exists...
3652 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3655 * Nope - return a "not found" error...
3658 send_ipp_status(con
, IPP_NOT_FOUND
,
3659 _("Job #%d does not exist!"), jobid
);
3664 * See if the job has been completed...
3667 if (job
->state_value
!= IPP_JOB_HELD
)
3670 * Return a "not-possible" error...
3673 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3674 _("Job #%d is not held for authentication!"),
3680 * See if we have already authenticated...
3683 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3685 if (!con
->username
[0] && !auth_info
)
3687 cupsd_printer_t
*printer
; /* Job destination */
3691 * No auth data. If we need to authenticate via Kerberos, send a
3692 * HTTP auth challenge, otherwise just return an IPP error...
3695 printer
= cupsdFindDest(job
->dest
);
3697 if (printer
&& printer
->num_auth_info_required
> 0 &&
3698 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3699 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3701 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3702 _("No authentication information provided!"));
3707 * See if the job is owned by the requesting user...
3710 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3712 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3717 * Save the authentication information for this job...
3720 save_auth_info(con
, job
, auth_info
);
3723 * Reset the job-hold-until value to "no-hold"...
3726 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3727 IPP_TAG_KEYWORD
)) == NULL
)
3728 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3732 attr
->value_tag
= IPP_TAG_KEYWORD
;
3733 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3737 * Release the job and return...
3740 cupsdReleaseJob(job
);
3742 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3747 * 'cancel_all_jobs()' - Cancel all print jobs.
3751 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3752 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3754 http_status_t status
; /* Policy status */
3755 cups_ptype_t dtype
; /* Destination type */
3756 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3757 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3758 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3759 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3760 int port
; /* Port portion of URI */
3761 ipp_attribute_t
*attr
; /* Attribute in request */
3762 const char *username
; /* Username */
3763 int purge
; /* Purge? */
3764 cupsd_printer_t
*printer
; /* Printer */
3767 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3768 con
->http
.fd
, uri
->values
[0].string
.text
);
3771 * See if we have a printer URI...
3774 if (strcmp(uri
->name
, "printer-uri"))
3776 send_ipp_status(con
, IPP_BAD_REQUEST
,
3777 _("The printer-uri attribute is required!"));
3782 * Get the username (if any) for the jobs we want to cancel (only if
3783 * "my-jobs" is specified...
3786 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3787 IPP_TAG_BOOLEAN
)) != NULL
&&
3788 attr
->values
[0].boolean
)
3790 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3791 IPP_TAG_NAME
)) != NULL
)
3792 username
= attr
->values
[0].string
.text
;
3795 send_ipp_status(con
, IPP_BAD_REQUEST
,
3796 _("Missing requesting-user-name attribute!"));
3804 * Look for the "purge-jobs" attribute...
3807 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3808 IPP_TAG_BOOLEAN
)) != NULL
)
3809 purge
= attr
->values
[0].boolean
;
3814 * And if the destination is valid...
3817 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3823 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3824 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3825 hostname
, sizeof(hostname
), &port
,
3826 resource
, sizeof(resource
));
3828 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3829 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3831 send_ipp_status(con
, IPP_NOT_FOUND
,
3832 _("The printer or class was not found."));
3840 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3842 send_http_error(con
, status
, NULL
);
3847 * Cancel all jobs on all printers...
3850 cupsdCancelJobs(NULL
, username
, purge
);
3852 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3853 purge
? "purged" : "canceled", get_username(con
));
3861 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3864 send_http_error(con
, status
, printer
);
3869 * Cancel all of the jobs on the named printer...
3872 cupsdCancelJobs(printer
->name
, username
, purge
);
3874 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3875 printer
->name
, purge
? "purged" : "canceled",
3879 con
->response
->request
.status
.status_code
= IPP_OK
;
3884 * 'cancel_job()' - Cancel a print job.
3888 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3889 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3891 ipp_attribute_t
*attr
; /* Current attribute */
3892 int jobid
; /* Job ID */
3893 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3894 username
[HTTP_MAX_URI
], /* Username portion of URI */
3895 host
[HTTP_MAX_URI
], /* Host portion of URI */
3896 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3897 int port
; /* Port portion of URI */
3898 cupsd_job_t
*job
; /* Job information */
3899 cups_ptype_t dtype
; /* Destination type (printer/class) */
3900 cupsd_printer_t
*printer
; /* Printer data */
3901 int purge
; /* Purge the job? */
3904 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3905 con
->http
.fd
, uri
->values
[0].string
.text
);
3908 * See if we have a job URI or a printer URI...
3911 if (!strcmp(uri
->name
, "printer-uri"))
3914 * Got a printer URI; see if we also have a job-id attribute...
3917 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3918 IPP_TAG_INTEGER
)) == NULL
)
3920 send_ipp_status(con
, IPP_BAD_REQUEST
,
3921 _("Got a printer-uri attribute but no job-id!"));
3925 if ((jobid
= attr
->values
[0].integer
) == 0)
3928 * Find the current job on the specified printer...
3931 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3937 send_ipp_status(con
, IPP_NOT_FOUND
,
3938 _("The printer or class was not found."));
3943 * See if the printer is currently printing a job...
3947 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
3951 * No, see if there are any pending jobs...
3954 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3956 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3957 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3958 !strcasecmp(job
->dest
, printer
->name
))
3965 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3967 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3968 if (job
->state_value
== IPP_JOB_STOPPED
&&
3969 !strcasecmp(job
->dest
, printer
->name
))
3976 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
3987 * Got a job URI; parse it to get the job ID...
3990 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3991 sizeof(scheme
), username
, sizeof(username
), host
,
3992 sizeof(host
), &port
, resource
, sizeof(resource
));
3994 if (strncmp(resource
, "/jobs/", 6))
4000 send_ipp_status(con
, IPP_BAD_REQUEST
,
4001 _("Bad job-uri attribute \"%s\"!"),
4002 uri
->values
[0].string
.text
);
4006 jobid
= atoi(resource
+ 6);
4010 * Look for the "purge-job" attribute...
4013 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
4014 IPP_TAG_BOOLEAN
)) != NULL
)
4015 purge
= attr
->values
[0].boolean
;
4020 * See if the job exists...
4023 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4026 * Nope - return a "not found" error...
4029 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
4034 * See if the job is owned by the requesting user...
4037 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
4039 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
4044 * See if the job is already completed, canceled, or aborted; if so,
4045 * we can't cancel...
4048 if (job
->state_value
>= IPP_JOB_CANCELED
&& !purge
)
4050 switch (job
->state_value
)
4052 case IPP_JOB_CANCELED
:
4053 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4054 _("Job #%d is already canceled - can\'t cancel."),
4058 case IPP_JOB_ABORTED
:
4059 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4060 _("Job #%d is already aborted - can\'t cancel."),
4065 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4066 _("Job #%d is already completed - can\'t cancel."),
4075 * Cancel the job and return...
4078 cupsdCancelJob(job
, purge
, IPP_JOB_CANCELED
);
4082 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4085 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4088 con
->response
->request
.status
.status_code
= IPP_OK
;
4093 * 'cancel_subscription()' - Cancel a subscription.
4097 cancel_subscription(
4098 cupsd_client_t
*con
, /* I - Client connection */
4099 int sub_id
) /* I - Subscription ID */
4101 http_status_t status
; /* Policy status */
4102 cupsd_subscription_t
*sub
; /* Subscription */
4105 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4106 "cancel_subscription(con=%p[%d], sub_id=%d)",
4107 con
, con
->http
.fd
, sub_id
);
4110 * Is the subscription ID valid?
4113 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4116 * Bad subscription ID...
4119 send_ipp_status(con
, IPP_NOT_FOUND
,
4120 _("notify-subscription-id %d no good!"), sub_id
);
4128 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4130 con
, sub
->owner
)) != HTTP_OK
)
4132 send_http_error(con
, status
, sub
->dest
);
4137 * Cancel the subscription...
4140 cupsdDeleteSubscription(sub
, 1);
4142 con
->response
->request
.status
.status_code
= IPP_OK
;
4147 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4150 static int /* O - 1 if OK, 0 if not */
4151 check_rss_recipient(
4152 const char *recipient
) /* I - Recipient URI */
4154 cupsd_subscription_t
*sub
; /* Current subscription */
4157 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4159 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4163 * Compare the URIs up to the first ?...
4166 const char *r1
, *r2
;
4168 for (r1
= recipient
, r2
= sub
->recipient
;
4169 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4181 * 'check_quotas()' - Check quotas for a printer and user.
4184 static int /* O - 1 if OK, 0 if not */
4185 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4186 cupsd_printer_t
*p
) /* I - Printer or class */
4188 int i
; /* Looping var */
4189 char username
[33]; /* Username */
4190 cupsd_quota_t
*q
; /* Quota data */
4191 #ifdef HAVE_MBR_UID_TO_UUID
4193 * Use Apple membership APIs which require that all names represent
4194 * valid user account or group records accessible by the server.
4197 uuid_t usr_uuid
; /* UUID for job requesting user */
4198 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4199 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4200 int mbr_err
; /* Error from membership function */
4201 int is_member
; /* Is this user a member? */
4204 * Use standard POSIX APIs for checking users and groups...
4207 struct passwd
*pw
; /* User password data */
4208 #endif /* HAVE_MBR_UID_TO_UUID */
4211 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4212 con
, con
->http
.fd
, p
, p
->name
);
4215 * Figure out who is printing...
4218 strlcpy(username
, get_username(con
), sizeof(username
));
4221 * Check global active job limits for printers and users...
4224 if (MaxJobsPerPrinter
)
4227 * Check if there are too many pending jobs on this printer...
4230 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4232 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4241 * Check if there are too many pending jobs for this user...
4244 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4246 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4253 * Check against users...
4256 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4261 #ifdef HAVE_MBR_UID_TO_UUID
4263 * Get UUID for job requesting user...
4266 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4272 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4273 "check_quotas: UUID lookup failed for user \"%s\"",
4275 cupsdLogMessage(CUPSD_LOG_INFO
,
4276 "Denying user \"%s\" access to printer \"%s\" "
4277 "(unknown user)...",
4283 * Get UID and GID of requesting user...
4286 pw
= getpwnam(username
);
4288 #endif /* HAVE_MBR_UID_TO_UUID */
4290 for (i
= 0; i
< p
->num_users
; i
++)
4291 if (p
->users
[i
][0] == '@')
4294 * Check group membership...
4297 #ifdef HAVE_MBR_UID_TO_UUID
4298 if (p
->users
[i
][1] == '#')
4300 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4301 uuid_clear(grp_uuid
);
4303 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4307 * Invalid ACL entries are ignored for matching; just record a
4308 * warning in the log...
4311 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4312 "check_quotas: UUID lookup failed for ACL entry "
4313 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4314 cupsdLogMessage(CUPSD_LOG_WARN
,
4315 "Access control entry \"%s\" not a valid group name; "
4316 "entry ignored", p
->users
[i
]);
4319 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4323 * At this point, there should be no errors, but check anyways...
4326 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4327 "check_quotas: group \"%s\" membership check "
4328 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4333 * Stop if we found a match...
4340 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4342 #endif /* HAVE_MBR_UID_TO_UUID */
4344 #ifdef HAVE_MBR_UID_TO_UUID
4347 if (p
->users
[i
][0] == '#')
4349 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4350 uuid_clear(usr2_uuid
);
4352 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4356 * Invalid ACL entries are ignored for matching; just record a
4357 * warning in the log...
4360 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4361 "check_quotas: UUID lookup failed for ACL entry "
4362 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4363 cupsdLogMessage(CUPSD_LOG_WARN
,
4364 "Access control entry \"%s\" not a valid user name; "
4365 "entry ignored", p
->users
[i
]);
4368 if ((mbr_err
= mbr_check_membership(usr_uuid
, usr2_uuid
,
4371 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4372 "check_quotas: User \"%s\" identity check failed "
4373 "(err=%d)", p
->users
[i
], mbr_err
);
4381 else if (!strcasecmp(username
, p
->users
[i
]))
4383 #endif /* HAVE_MBR_UID_TO_UUID */
4385 if ((i
< p
->num_users
) == p
->deny_users
)
4387 cupsdLogMessage(CUPSD_LOG_INFO
,
4388 "Denying user \"%s\" access to printer \"%s\"...",
4399 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4402 * TODO: Define these special page count values as constants!
4405 if (q
->page_count
== -4) /* special case: unlimited user */
4407 cupsdLogMessage(CUPSD_LOG_INFO
,
4408 "User \"%s\" request approved for printer %s (%s): "
4410 username
, p
->name
, p
->info
);
4411 q
->page_count
= 0; /* allow user to print */
4414 else if (q
->page_count
== -3) /* quota exceeded */
4416 cupsdLogMessage(CUPSD_LOG_INFO
,
4417 "User \"%s\" request denied for printer %s (%s): "
4418 "quota limit exceeded.",
4419 username
, p
->name
, p
->info
);
4420 q
->page_count
= 2; /* force quota exceeded failure */
4423 else if (q
->page_count
== -2) /* quota disabled for user */
4425 cupsdLogMessage(CUPSD_LOG_INFO
,
4426 "User \"%s\" request denied for printer %s (%s): "
4427 "printing disabled for user.",
4428 username
, p
->name
, p
->info
);
4429 q
->page_count
= 2; /* force quota exceeded failure */
4432 else if (q
->page_count
== -1) /* quota access error */
4434 cupsdLogMessage(CUPSD_LOG_INFO
,
4435 "User \"%s\" request denied for printer %s (%s): "
4436 "unable to determine quota limit.",
4437 username
, p
->name
, p
->info
);
4438 q
->page_count
= 2; /* force quota exceeded failure */
4441 else if (q
->page_count
< 0) /* user not found or other error */
4443 cupsdLogMessage(CUPSD_LOG_INFO
,
4444 "User \"%s\" request denied for printer %s (%s): "
4445 "user disabled / missing quota.",
4446 username
, p
->name
, p
->info
);
4447 q
->page_count
= 2; /* force quota exceeded failure */
4450 else /* page within user limits */
4452 q
->page_count
= 0; /* allow user to print */
4457 #endif /* __APPLE__ */
4458 if (p
->k_limit
|| p
->page_limit
)
4460 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4462 cupsdLogMessage(CUPSD_LOG_ERROR
,
4463 "Unable to allocate quota data for user \"%s\"!",
4468 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4469 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4471 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4478 * If we have gotten this far, we're done!
4486 * 'copy_attribute()' - Copy a single attribute.
4489 static ipp_attribute_t
* /* O - New attribute */
4491 ipp_t
*to
, /* O - Destination request/response */
4492 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4493 int quickcopy
) /* I - Do a quick copy? */
4495 int i
; /* Looping var */
4496 ipp_attribute_t
*toattr
; /* Destination attribute */
4499 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4500 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4501 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4504 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4507 toattr
= ippAddSeparator(to
);
4510 case IPP_TAG_INTEGER
:
4512 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4513 attr
->name
, attr
->num_values
, NULL
);
4515 for (i
= 0; i
< attr
->num_values
; i
++)
4516 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4519 case IPP_TAG_BOOLEAN
:
4520 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4521 attr
->num_values
, NULL
);
4523 for (i
= 0; i
< attr
->num_values
; i
++)
4524 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4527 case IPP_TAG_STRING
:
4530 case IPP_TAG_KEYWORD
:
4532 case IPP_TAG_URISCHEME
:
4533 case IPP_TAG_CHARSET
:
4534 case IPP_TAG_LANGUAGE
:
4535 case IPP_TAG_MIMETYPE
:
4536 toattr
= ippAddStrings(to
, attr
->group_tag
,
4537 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4538 attr
->name
, attr
->num_values
, NULL
, NULL
);
4542 for (i
= 0; i
< attr
->num_values
; i
++)
4543 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4547 for (i
= 0; i
< attr
->num_values
; i
++)
4548 toattr
->values
[i
].string
.text
=
4549 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4554 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4555 attr
->values
[0].date
);
4558 case IPP_TAG_RESOLUTION
:
4559 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4560 attr
->num_values
, IPP_RES_PER_INCH
,
4563 for (i
= 0; i
< attr
->num_values
; i
++)
4565 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4566 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4567 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4571 case IPP_TAG_RANGE
:
4572 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4573 attr
->num_values
, NULL
, NULL
);
4575 for (i
= 0; i
< attr
->num_values
; i
++)
4577 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4578 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4582 case IPP_TAG_TEXTLANG
:
4583 case IPP_TAG_NAMELANG
:
4584 toattr
= ippAddStrings(to
, attr
->group_tag
,
4585 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4586 attr
->name
, attr
->num_values
, NULL
, NULL
);
4590 for (i
= 0; i
< attr
->num_values
; i
++)
4592 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4593 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4598 for (i
= 0; i
< attr
->num_values
; i
++)
4601 toattr
->values
[i
].string
.charset
=
4602 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4604 toattr
->values
[i
].string
.charset
=
4605 toattr
->values
[0].string
.charset
;
4607 toattr
->values
[i
].string
.text
=
4608 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4613 case IPP_TAG_BEGIN_COLLECTION
:
4614 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4615 attr
->num_values
, NULL
);
4617 for (i
= 0; i
< attr
->num_values
; i
++)
4619 toattr
->values
[i
].collection
= ippNew();
4620 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4621 NULL
, IPP_TAG_ZERO
, 0);
4626 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4627 attr
->name
, attr
->num_values
, NULL
);
4629 for (i
= 0; i
< attr
->num_values
; i
++)
4631 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4633 if (toattr
->values
[i
].unknown
.length
> 0)
4635 if ((toattr
->values
[i
].unknown
.data
=
4636 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4637 toattr
->values
[i
].unknown
.length
= 0;
4639 memcpy(toattr
->values
[i
].unknown
.data
,
4640 attr
->values
[i
].unknown
.data
,
4641 toattr
->values
[i
].unknown
.length
);
4644 break; /* anti-compiler-warning-code */
4652 * 'copy_attrs()' - Copy attributes from one request to another.
4656 copy_attrs(ipp_t
*to
, /* I - Destination request */
4657 ipp_t
*from
, /* I - Source request */
4658 cups_array_t
*ra
, /* I - Requested attributes */
4659 ipp_tag_t group
, /* I - Group to copy */
4660 int quickcopy
) /* I - Do a quick copy? */
4662 ipp_attribute_t
*fromattr
; /* Source attribute */
4665 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4666 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4667 to
, from
, ra
, group
, quickcopy
);
4672 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4675 * Filter attributes as needed...
4678 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4679 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4682 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4683 copy_attribute(to
, fromattr
, quickcopy
);
4689 * 'copy_banner()' - Copy a banner file to the requests directory for the
4693 static int /* O - Size of banner file in kbytes */
4694 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4695 cupsd_job_t
*job
, /* I - Job information */
4696 const char *name
) /* I - Name of banner */
4698 int i
; /* Looping var */
4699 int kbytes
; /* Size of banner file in kbytes */
4700 char filename
[1024]; /* Job filename */
4701 cupsd_banner_t
*banner
; /* Pointer to banner */
4702 cups_file_t
*in
; /* Input file */
4703 cups_file_t
*out
; /* Output file */
4704 int ch
; /* Character from file */
4705 char attrname
[255], /* Name of attribute */
4706 *s
; /* Pointer into name */
4707 ipp_attribute_t
*attr
; /* Attribute */
4710 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4711 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4712 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4713 name
? name
: "(null)");
4716 * Find the banner; return if not found or "none"...
4719 if (!name
|| !strcmp(name
, "none") ||
4720 (banner
= cupsdFindBanner(name
)) == NULL
)
4724 * Open the banner and job files...
4727 if (add_file(con
, job
, banner
->filetype
, 0))
4730 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4732 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4734 cupsdLogMessage(CUPSD_LOG_ERROR
,
4735 "Unable to create banner job file %s - %s",
4736 filename
, strerror(errno
));
4741 fchmod(cupsFileNumber(out
), 0640);
4742 fchown(cupsFileNumber(out
), RunUser
, Group
);
4745 * Try the localized banner file under the subdirectory...
4748 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4750 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4753 * Convert ll-cc to ll_CC...
4757 attrname
[3] = toupper(attrname
[3] & 255);
4758 attrname
[4] = toupper(attrname
[4] & 255);
4761 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4764 if (access(filename
, 0) && strlen(attrname
) > 2)
4767 * Wasn't able to find "ll_CC" locale file; try the non-national
4768 * localization banner directory.
4773 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4777 if (access(filename
, 0))
4780 * Use the non-localized banner file.
4783 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4786 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4790 cupsdLogMessage(CUPSD_LOG_ERROR
,
4791 "Unable to open banner template file %s - %s",
4792 filename
, strerror(errno
));
4798 * Parse the file to the end...
4801 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4805 * Get an attribute name...
4808 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4809 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4811 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4821 * Ignore { followed by stuff that is not an attribute name...
4824 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4829 * See if it is defined...
4832 if (attrname
[0] == '?')
4837 if (!strcmp(s
, "printer-name"))
4839 cupsFilePuts(out
, job
->dest
);
4842 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4845 * See if we have a leading question mark...
4848 if (attrname
[0] != '?')
4851 * Nope, write to file as-is; probably a PostScript procedure...
4854 cupsFilePrintf(out
, "{%s}", attrname
);
4861 * Output value(s)...
4864 for (i
= 0; i
< attr
->num_values
; i
++)
4867 cupsFilePutChar(out
, ',');
4869 switch (attr
->value_tag
)
4871 case IPP_TAG_INTEGER
:
4873 if (!strncmp(s
, "time-at-", 8))
4874 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
4876 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4879 case IPP_TAG_BOOLEAN
:
4880 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4883 case IPP_TAG_NOVALUE
:
4884 cupsFilePuts(out
, "novalue");
4887 case IPP_TAG_RANGE
:
4888 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4889 attr
->values
[i
].range
.upper
);
4892 case IPP_TAG_RESOLUTION
:
4893 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4894 attr
->values
[i
].resolution
.yres
,
4895 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4900 case IPP_TAG_STRING
:
4903 case IPP_TAG_KEYWORD
:
4904 case IPP_TAG_CHARSET
:
4905 case IPP_TAG_LANGUAGE
:
4906 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4909 * Need to quote strings for PS banners...
4914 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4916 if (*p
== '(' || *p
== ')' || *p
== '\\')
4918 cupsFilePutChar(out
, '\\');
4919 cupsFilePutChar(out
, *p
);
4921 else if (*p
< 32 || *p
> 126)
4922 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4924 cupsFilePutChar(out
, *p
);
4928 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4932 break; /* anti-compiler-warning-code */
4936 else if (ch
== '\\') /* Quoted char */
4938 ch
= cupsFileGetChar(in
);
4940 if (ch
!= '{') /* Only do special handling for \{ */
4941 cupsFilePutChar(out
, '\\');
4943 cupsFilePutChar(out
, ch
);
4946 cupsFilePutChar(out
, ch
);
4950 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4952 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4953 IPP_TAG_INTEGER
)) != NULL
)
4954 attr
->values
[0].integer
+= kbytes
;
4963 * 'copy_file()' - Copy a PPD file or interface script...
4966 static int /* O - 0 = success, -1 = error */
4967 copy_file(const char *from
, /* I - Source file */
4968 const char *to
) /* I - Destination file */
4970 cups_file_t
*src
, /* Source file */
4971 *dst
; /* Destination file */
4972 int bytes
; /* Bytes to read/write */
4973 char buffer
[2048]; /* Copy buffer */
4976 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4979 * Open the source and destination file for a copy...
4982 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4985 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4992 * Copy the source file to the destination...
4995 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4996 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
5004 * Close both files and return...
5009 return (cupsFileClose(dst
));
5014 * 'copy_model()' - Copy a PPD model file, substituting default values
5018 static int /* O - 0 = success, -1 = error */
5019 copy_model(cupsd_client_t
*con
, /* I - Client connection */
5020 const char *from
, /* I - Source file */
5021 const char *to
) /* I - Destination file */
5023 fd_set input
; /* select() input set */
5024 struct timeval timeout
; /* select() timeout */
5025 int maxfd
; /* Max file descriptor for select() */
5026 char tempfile
[1024]; /* Temporary PPD file */
5027 int tempfd
; /* Temporary PPD file descriptor */
5028 int temppid
; /* Process ID of cups-driverd */
5029 int temppipe
[2]; /* Temporary pipes */
5030 char *argv
[4], /* Command-line arguments */
5031 *envp
[MAX_ENV
]; /* Environment */
5032 cups_file_t
*src
, /* Source file */
5033 *dst
; /* Destination file */
5034 ppd_file_t
*ppd
; /* PPD file */
5035 int bytes
, /* Bytes from pipe */
5036 total
; /* Total bytes from pipe */
5037 char buffer
[2048]; /* Copy buffer */
5038 int i
; /* Looping var */
5039 char option
[PPD_MAX_NAME
], /* Option name */
5040 choice
[PPD_MAX_NAME
]; /* Choice name */
5041 int num_defaults
; /* Number of default options */
5042 cups_option_t
*defaults
; /* Default options */
5043 char cups_protocol
[PPD_MAX_LINE
];
5044 /* cupsProtocol attribute */
5047 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5048 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
5052 * Run cups-driverd to get the PPD file...
5055 argv
[0] = "cups-driverd";
5057 argv
[2] = (char *)from
;
5060 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
5062 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
5063 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5064 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5068 cupsdOpenPipe(temppipe
);
5070 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5071 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5073 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5074 -1, -1, 0, DefaultProfile
, &temppid
))
5085 * Wait up to 30 seconds for the PPD file to be copied...
5090 if (temppipe
[0] > CGIPipes
[0])
5091 maxfd
= temppipe
[0] + 1;
5093 maxfd
= CGIPipes
[0] + 1;
5098 * See if we have data ready...
5102 FD_SET(temppipe
[0], &input
);
5103 FD_SET(CGIPipes
[0], &input
);
5105 timeout
.tv_sec
= 30;
5106 timeout
.tv_usec
= 0;
5108 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5118 * We have timed out...
5124 if (FD_ISSET(temppipe
[0], &input
))
5127 * Read the PPD file from the pipe, and write it to the PPD file.
5130 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5132 if (write(tempfd
, buffer
, bytes
) < bytes
)
5141 if (FD_ISSET(CGIPipes
[0], &input
))
5151 * No data from cups-deviced...
5154 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5160 * Read the source file and see what page sizes are supported...
5163 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5170 * Open the destination (if possible) and set the default options...
5175 cups_protocol
[0] = '\0';
5177 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5180 * Read all of the default lines from the old PPD...
5183 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5184 if (!strncmp(buffer
, "*Default", 8))
5187 * Add the default option...
5190 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5191 choice
, sizeof(choice
)))
5193 ppd_option_t
*ppdo
; /* PPD option */
5197 * Only add the default if the default hasn't already been
5198 * set and the choice exists in the new PPD...
5201 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5202 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5203 ppdFindChoice(ppdo
, choice
))
5204 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5208 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5209 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5213 else if (ppdPageSize(ppd
, DefaultPaperSize
))
5216 * Add the default media sizes...
5219 num_defaults
= cupsAddOption("PageSize", DefaultPaperSize
,
5220 num_defaults
, &defaults
);
5221 num_defaults
= cupsAddOption("PageRegion", DefaultPaperSize
,
5222 num_defaults
, &defaults
);
5223 num_defaults
= cupsAddOption("PaperDimension", DefaultPaperSize
,
5224 num_defaults
, &defaults
);
5225 num_defaults
= cupsAddOption("ImageableArea", DefaultPaperSize
,
5226 num_defaults
, &defaults
);
5232 * Open the source file for a copy...
5235 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5237 cupsFreeOptions(num_defaults
, defaults
);
5243 * Open the destination file for a copy...
5246 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5248 cupsFreeOptions(num_defaults
, defaults
);
5255 * Copy the source file to the destination...
5258 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5260 if (!strncmp(buffer
, "*Default", 8))
5263 * Check for an previous default option choice...
5266 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5267 choice
, sizeof(choice
)))
5269 const char *val
; /* Default option value */
5272 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5275 * Substitute the previous choice...
5278 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5283 cupsFilePrintf(dst
, "%s\n", buffer
);
5286 if (cups_protocol
[0])
5287 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5289 cupsFreeOptions(num_defaults
, defaults
);
5292 * Close both files and return...
5299 return (cupsFileClose(dst
));
5304 * 'copy_job_attrs()' - Copy job attributes.
5308 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5309 cupsd_job_t
*job
, /* I - Job */
5310 cups_array_t
*ra
) /* I - Requested attributes array */
5312 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5316 * Send the requested attributes for each job...
5319 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5320 con
->servername
, con
->serverport
, "/jobs/%d",
5323 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5324 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5325 "document-count", job
->num_files
);
5327 if (!ra
|| cupsArrayFind(ra
, "job-media-progress"))
5328 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5329 "job-media-progress", job
->progress
);
5331 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5332 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5333 "job-more-info", NULL
, job_uri
);
5335 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5336 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5337 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5338 job
->num_files
> 0);
5340 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5341 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5342 "job-printer-up-time", time(NULL
));
5344 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5345 add_job_state_reasons(con
, job
);
5347 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5348 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5349 "job-uri", NULL
, job_uri
);
5351 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5356 * 'copy_printer_attrs()' - Copy printer attributes.
5361 cupsd_client_t
*con
, /* I - Client connection */
5362 cupsd_printer_t
*printer
, /* I - Printer */
5363 cups_array_t
*ra
) /* I - Requested attributes array */
5365 char printer_uri
[HTTP_MAX_URI
];
5367 time_t curtime
; /* Current time */
5368 int i
; /* Looping var */
5369 ipp_attribute_t
*history
; /* History collection */
5373 * Copy the printer attributes to the response using requested-attributes
5374 * and document-format attributes that may be provided by the client.
5377 curtime
= time(NULL
);
5380 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5381 printer
->recoverable
)
5382 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5383 "com.apple.print.recoverable-message", NULL
,
5384 printer
->recoverable
);
5385 #endif /* __APPLE__ */
5387 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5388 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5389 "marker-change-time", printer
->marker_time
);
5391 if (printer
->num_printers
> 0 &&
5392 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5394 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5395 cupsd_printer_t
*p2
; /* Printer in class */
5396 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5399 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5400 IPP_TAG_URI
, "member-uris",
5401 printer
->num_printers
, NULL
,
5404 for (i
= 0; i
< printer
->num_printers
; i
++)
5406 p2
= printer
->printers
[i
];
5408 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5409 IPP_TAG_URI
)) != NULL
)
5410 member_uris
->values
[i
].string
.text
=
5411 _cupsStrAlloc(p2_uri
->values
[0].string
.text
);
5414 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5415 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5417 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5418 "/classes/%s" : "/printers/%s", p2
->name
);
5419 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5425 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5426 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5427 "printer-alert", NULL
, printer
->alert
);
5429 if (printer
->alert_description
&&
5430 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5431 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5432 "printer-alert-description", NULL
,
5433 printer
->alert_description
);
5435 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5436 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5437 ippTimeToDate(curtime
));
5440 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5442 if (printer
->reg_name
)
5443 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5444 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5446 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5447 "printer-dns-sd-name", 0);
5449 #endif /* HAVE_DNSSD */
5451 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5452 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5453 "printer-error-policy", NULL
, printer
->error_policy
);
5455 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5456 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5457 printer
->accepting
);
5459 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5460 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5463 if ((!ra
|| cupsArrayFind(ra
, "printer-more-info")) &&
5464 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5466 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5467 "http", NULL
, con
->servername
, con
->serverport
,
5468 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5469 "/classes/%s" : "/printers/%s", printer
->name
);
5470 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5471 "printer-more-info", NULL
, printer_uri
);
5474 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5475 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5476 "printer-op-policy", NULL
, printer
->op_policy
);
5478 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5479 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5482 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5483 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5484 "printer-state-change-time", printer
->state_time
);
5486 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5487 cupsArrayFind(ra
, "printer-state-history"))
5490 * Printer history is only sent if specifically requested, so that
5491 * older CUPS/IPP clients won't barf on the collection attributes.
5494 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5495 "printer-state-history",
5496 printer
->num_history
, NULL
);
5498 for (i
= 0; i
< printer
->num_history
; i
++)
5499 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5500 NULL
, IPP_TAG_ZERO
, 0);
5503 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5504 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5505 "printer-state-message", NULL
, printer
->state_message
);
5507 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5508 add_printer_state_reasons(con
, printer
);
5510 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5512 int type
; /* printer-type value */
5516 * Add the CUPS-specific printer-type attribute...
5519 type
= printer
->type
;
5521 if (printer
== DefaultPrinter
)
5522 type
|= CUPS_PRINTER_DEFAULT
;
5524 if (!printer
->accepting
)
5525 type
|= CUPS_PRINTER_REJECTING
;
5527 if (!printer
->shared
)
5528 type
|= CUPS_PRINTER_NOT_SHARED
;
5530 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5534 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5535 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5536 "printer-up-time", curtime
);
5538 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5539 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
5541 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5542 "ipp", NULL
, con
->servername
, con
->serverport
,
5543 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5544 "/classes/%s" : "/printers/%s", printer
->name
);
5545 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5546 "printer-uri-supported", NULL
, printer_uri
);
5547 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5551 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5552 add_queued_job_count(con
, printer
);
5554 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5555 if (printer
->ppd_attrs
)
5556 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0);
5557 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5562 * 'copy_subscription_attrs()' - Copy subscription attributes.
5566 copy_subscription_attrs(
5567 cupsd_client_t
*con
, /* I - Client connection */
5568 cupsd_subscription_t
*sub
, /* I - Subscription */
5569 cups_array_t
*ra
) /* I - Requested attributes array */
5571 ipp_attribute_t
*attr
; /* Current attribute */
5572 char printer_uri
[HTTP_MAX_URI
];
5574 int count
; /* Number of events */
5575 unsigned mask
; /* Current event mask */
5576 const char *name
; /* Current event name */
5580 * Copy the subscription attributes to the response using the
5581 * requested-attributes attribute that may be provided by the client.
5584 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5586 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5589 * Simple event list...
5592 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5593 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5594 "notify-events", NULL
, name
);
5599 * Complex event list...
5602 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5603 if (sub
->mask
& mask
)
5606 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5607 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5608 "notify-events", count
, NULL
, NULL
);
5610 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5611 if (sub
->mask
& mask
)
5613 attr
->values
[count
].string
.text
=
5614 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5621 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5622 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5623 "notify-job-id", sub
->job
->id
);
5625 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5626 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5627 "notify-lease-duration", sub
->lease
);
5629 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5631 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5632 "ipp", NULL
, con
->servername
, con
->serverport
,
5633 "/printers/%s", sub
->dest
->name
);
5634 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5635 "notify-printer-uri", NULL
, printer_uri
);
5638 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5639 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5640 "notify-recipient-uri", NULL
, sub
->recipient
);
5641 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5642 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5643 "notify-pull-method", NULL
, "ippget");
5645 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5646 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5647 "notify-subscriber-user-name", NULL
, sub
->owner
);
5649 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5650 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5651 "notify-subscription-id", sub
->id
);
5653 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5654 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5655 "notify-time-interval", sub
->interval
);
5657 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5658 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5659 sub
->user_data
, sub
->user_data_len
);
5664 * 'create_job()' - Print a file to a printer or class.
5668 create_job(cupsd_client_t
*con
, /* I - Client connection */
5669 ipp_attribute_t
*uri
) /* I - Printer URI */
5671 cupsd_printer_t
*printer
; /* Printer */
5672 cupsd_job_t
*job
; /* New job */
5675 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5676 con
->http
.fd
, uri
->values
[0].string
.text
);
5679 * Is the destination valid?
5682 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5688 send_ipp_status(con
, IPP_NOT_FOUND
,
5689 _("The printer or class was not found."));
5694 * Create the job object...
5697 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5700 job
->pending_timeout
= 1;
5703 * Save and log the job...
5706 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5707 job
->dest
, job
->username
);
5712 * 'create_requested_array()' - Create an array for the requested-attributes.
5715 static cups_array_t
* /* O - Array of attributes or NULL */
5716 create_requested_array(ipp_t
*request
) /* I - IPP request */
5718 int i
; /* Looping var */
5719 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5720 cups_array_t
*ra
; /* Requested attributes array */
5721 char *value
; /* Current value */
5725 * Get the requested-attributes attribute, and return NULL if we don't
5729 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5730 IPP_TAG_KEYWORD
)) == NULL
)
5734 * If the attribute contains a single "all" keyword, return NULL...
5737 if (requested
->num_values
== 1 &&
5738 !strcmp(requested
->values
[0].string
.text
, "all"))
5742 * Create an array using "strcmp" as the comparison function...
5745 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5747 for (i
= 0; i
< requested
->num_values
; i
++)
5749 value
= requested
->values
[i
].string
.text
;
5751 if (!strcmp(value
, "job-template"))
5753 cupsArrayAdd(ra
, "copies");
5754 cupsArrayAdd(ra
, "copies-default");
5755 cupsArrayAdd(ra
, "copies-supported");
5756 cupsArrayAdd(ra
, "finishings");
5757 cupsArrayAdd(ra
, "finishings-default");
5758 cupsArrayAdd(ra
, "finishings-supported");
5759 cupsArrayAdd(ra
, "job-hold-until");
5760 cupsArrayAdd(ra
, "job-hold-until-default");
5761 cupsArrayAdd(ra
, "job-hold-until-supported");
5762 cupsArrayAdd(ra
, "job-priority");
5763 cupsArrayAdd(ra
, "job-priority-default");
5764 cupsArrayAdd(ra
, "job-priority-supported");
5765 cupsArrayAdd(ra
, "job-sheets");
5766 cupsArrayAdd(ra
, "job-sheets-default");
5767 cupsArrayAdd(ra
, "job-sheets-supported");
5768 cupsArrayAdd(ra
, "media");
5769 cupsArrayAdd(ra
, "media-default");
5770 cupsArrayAdd(ra
, "media-supported");
5771 cupsArrayAdd(ra
, "multiple-document-handling");
5772 cupsArrayAdd(ra
, "multiple-document-handling-default");
5773 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5774 cupsArrayAdd(ra
, "number-up");
5775 cupsArrayAdd(ra
, "number-up-default");
5776 cupsArrayAdd(ra
, "number-up-supported");
5777 cupsArrayAdd(ra
, "orientation-requested");
5778 cupsArrayAdd(ra
, "orientation-requested-default");
5779 cupsArrayAdd(ra
, "orientation-requested-supported");
5780 cupsArrayAdd(ra
, "page-ranges");
5781 cupsArrayAdd(ra
, "page-ranges-supported");
5782 cupsArrayAdd(ra
, "printer-resolution");
5783 cupsArrayAdd(ra
, "printer-resolution-default");
5784 cupsArrayAdd(ra
, "printer-resolution-supported");
5785 cupsArrayAdd(ra
, "print-quality");
5786 cupsArrayAdd(ra
, "print-quality-default");
5787 cupsArrayAdd(ra
, "print-quality-supported");
5788 cupsArrayAdd(ra
, "sides");
5789 cupsArrayAdd(ra
, "sides-default");
5790 cupsArrayAdd(ra
, "sides-supported");
5792 else if (!strcmp(value
, "job-description"))
5794 cupsArrayAdd(ra
, "date-time-at-completed");
5795 cupsArrayAdd(ra
, "date-time-at-creation");
5796 cupsArrayAdd(ra
, "date-time-at-processing");
5797 cupsArrayAdd(ra
, "job-detailed-status-message");
5798 cupsArrayAdd(ra
, "job-document-access-errors");
5799 cupsArrayAdd(ra
, "job-id");
5800 cupsArrayAdd(ra
, "job-impressions");
5801 cupsArrayAdd(ra
, "job-impressions-completed");
5802 cupsArrayAdd(ra
, "job-k-octets");
5803 cupsArrayAdd(ra
, "job-k-octets-processed");
5804 cupsArrayAdd(ra
, "job-media-progress");
5805 cupsArrayAdd(ra
, "job-media-sheets");
5806 cupsArrayAdd(ra
, "job-media-sheets-completed");
5807 cupsArrayAdd(ra
, "job-message-from-operator");
5808 cupsArrayAdd(ra
, "job-more-info");
5809 cupsArrayAdd(ra
, "job-name");
5810 cupsArrayAdd(ra
, "job-originating-user-name");
5811 cupsArrayAdd(ra
, "job-printer-up-time");
5812 cupsArrayAdd(ra
, "job-printer-uri");
5813 cupsArrayAdd(ra
, "job-state");
5814 cupsArrayAdd(ra
, "job-state-message");
5815 cupsArrayAdd(ra
, "job-state-reasons");
5816 cupsArrayAdd(ra
, "job-uri");
5817 cupsArrayAdd(ra
, "number-of-documents");
5818 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5819 cupsArrayAdd(ra
, "output-device-assigned");
5820 cupsArrayAdd(ra
, "time-at-completed");
5821 cupsArrayAdd(ra
, "time-at-creation");
5822 cupsArrayAdd(ra
, "time-at-processing");
5824 else if (!strcmp(value
, "printer-description"))
5826 cupsArrayAdd(ra
, "charset-configured");
5827 cupsArrayAdd(ra
, "charset-supported");
5828 cupsArrayAdd(ra
, "color-supported");
5829 cupsArrayAdd(ra
, "compression-supported");
5830 cupsArrayAdd(ra
, "document-format-default");
5831 cupsArrayAdd(ra
, "document-format-supported");
5832 cupsArrayAdd(ra
, "generated-natural-language-supported");
5833 cupsArrayAdd(ra
, "ipp-versions-supported");
5834 cupsArrayAdd(ra
, "job-impressions-supported");
5835 cupsArrayAdd(ra
, "job-k-octets-supported");
5836 cupsArrayAdd(ra
, "job-media-sheets-supported");
5837 cupsArrayAdd(ra
, "job-settable-attributes-supported");
5838 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5839 cupsArrayAdd(ra
, "multiple-operation-time-out");
5840 cupsArrayAdd(ra
, "natural-language-configured");
5841 cupsArrayAdd(ra
, "notify-attributes-supported");
5842 cupsArrayAdd(ra
, "notify-lease-duration-default");
5843 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5844 cupsArrayAdd(ra
, "notify-max-events-supported");
5845 cupsArrayAdd(ra
, "notify-events-default");
5846 cupsArrayAdd(ra
, "notify-events-supported");
5847 cupsArrayAdd(ra
, "notify-pull-method-supported");
5848 cupsArrayAdd(ra
, "notify-schemes-supported");
5849 cupsArrayAdd(ra
, "operations-supported");
5850 cupsArrayAdd(ra
, "pages-per-minute");
5851 cupsArrayAdd(ra
, "pages-per-minute-color");
5852 cupsArrayAdd(ra
, "pdl-override-supported");
5853 cupsArrayAdd(ra
, "printer-alert");
5854 cupsArrayAdd(ra
, "printer-alert-description");
5855 cupsArrayAdd(ra
, "printer-commands");
5856 cupsArrayAdd(ra
, "printer-current-time");
5857 cupsArrayAdd(ra
, "printer-driver-installer");
5858 cupsArrayAdd(ra
, "printer-dns-sd-name");
5859 cupsArrayAdd(ra
, "printer-info");
5860 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5861 cupsArrayAdd(ra
, "printer-location");
5862 cupsArrayAdd(ra
, "printer-make-and-model");
5863 cupsArrayAdd(ra
, "printer-message-from-operator");
5864 cupsArrayAdd(ra
, "printer-more-info");
5865 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5866 cupsArrayAdd(ra
, "printer-name");
5867 cupsArrayAdd(ra
, "printer-state");
5868 cupsArrayAdd(ra
, "printer-state-message");
5869 cupsArrayAdd(ra
, "printer-state-reasons");
5870 cupsArrayAdd(ra
, "printer-settable-attributes-supported");
5871 cupsArrayAdd(ra
, "printer-type");
5872 cupsArrayAdd(ra
, "printer-up-time");
5873 cupsArrayAdd(ra
, "printer-uri-supported");
5874 cupsArrayAdd(ra
, "queued-job-count");
5875 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5876 cupsArrayAdd(ra
, "uri-authentication-supported");
5877 cupsArrayAdd(ra
, "uri-security-supported");
5879 else if (!strcmp(value
, "printer-defaults"))
5881 char *name
; /* Option name */
5884 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5886 name
= (char *)cupsArrayNext(CommonDefaults
))
5887 cupsArrayAdd(ra
, name
);
5889 else if (!strcmp(value
, "subscription-template"))
5891 cupsArrayAdd(ra
, "notify-attributes");
5892 cupsArrayAdd(ra
, "notify-charset");
5893 cupsArrayAdd(ra
, "notify-events");
5894 cupsArrayAdd(ra
, "notify-lease-duration");
5895 cupsArrayAdd(ra
, "notify-natural-language");
5896 cupsArrayAdd(ra
, "notify-pull-method");
5897 cupsArrayAdd(ra
, "notify-recipient-uri");
5898 cupsArrayAdd(ra
, "notify-time-interval");
5899 cupsArrayAdd(ra
, "notify-user-data");
5902 cupsArrayAdd(ra
, value
);
5910 * 'create_subscription()' - Create a notification subscription.
5914 create_subscription(
5915 cupsd_client_t
*con
, /* I - Client connection */
5916 ipp_attribute_t
*uri
) /* I - Printer URI */
5918 http_status_t status
; /* Policy status */
5919 int i
; /* Looping var */
5920 ipp_attribute_t
*attr
; /* Current attribute */
5921 cups_ptype_t dtype
; /* Destination type (printer/class) */
5922 char scheme
[HTTP_MAX_URI
],
5923 /* Scheme portion of URI */
5924 userpass
[HTTP_MAX_URI
],
5925 /* Username portion of URI */
5927 /* Host portion of URI */
5928 resource
[HTTP_MAX_URI
];
5929 /* Resource portion of URI */
5930 int port
; /* Port portion of URI */
5931 cupsd_printer_t
*printer
; /* Printer/class */
5932 cupsd_job_t
*job
; /* Job */
5933 int jobid
; /* Job ID */
5934 cupsd_subscription_t
*sub
; /* Subscription object */
5935 const char *username
, /* requesting-user-name or
5936 authenticated username */
5937 *recipient
, /* notify-recipient-uri */
5938 *pullmethod
; /* notify-pull-method */
5939 ipp_attribute_t
*user_data
; /* notify-user-data */
5940 int interval
, /* notify-time-interval */
5941 lease
; /* notify-lease-duration */
5942 unsigned mask
; /* notify-events */
5943 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5944 *notify_lease
; /* notify-lease-duration(-default) */
5948 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5950 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5951 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5952 attr
->value_tag
, attr
->name
);
5954 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5959 * Is the destination valid?
5962 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5963 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5964 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5966 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5967 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5968 sizeof(host
), &port
, resource
, sizeof(resource
));
5970 if (!strcmp(resource
, "/"))
5972 dtype
= (cups_ptype_t
)0;
5975 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5977 dtype
= (cups_ptype_t
)0;
5980 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5982 dtype
= CUPS_PRINTER_CLASS
;
5985 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5991 send_ipp_status(con
, IPP_NOT_FOUND
,
5992 _("The printer or class was not found."));
6002 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6005 send_http_error(con
, status
, printer
);
6009 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6011 send_http_error(con
, status
, NULL
);
6016 * Get the user that is requesting the subscription...
6019 username
= get_username(con
);
6022 * Find the first subscription group attribute; return if we have
6026 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6027 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6032 send_ipp_status(con
, IPP_BAD_REQUEST
,
6033 _("No subscription attributes in request!"));
6038 * Process the subscription attributes in the request...
6041 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6049 lease
= DefaultLeaseDuration
;
6051 mask
= CUPSD_EVENT_NONE
;
6055 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6057 notify_lease
= ippFindAttribute(printer
->attrs
,
6058 "notify-lease-duration-default",
6062 lease
= notify_lease
->values
[0].integer
;
6066 notify_events
= NULL
;
6067 notify_lease
= NULL
;
6070 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6072 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6073 attr
->value_tag
== IPP_TAG_URI
)
6076 * Validate the recipient scheme against the ServerBin/notifier
6080 char notifier
[1024]; /* Notifier filename */
6083 recipient
= attr
->values
[0].string
.text
;
6085 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6086 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6087 host
, sizeof(host
), &port
,
6088 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6090 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6091 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6092 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6093 "notify-status-code", IPP_URI_SCHEME
);
6097 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6099 if (access(notifier
, X_OK
))
6101 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6102 _("notify-recipient-uri URI \"%s\" uses unknown "
6103 "scheme!"), recipient
);
6104 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6105 "notify-status-code", IPP_URI_SCHEME
);
6109 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6111 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6112 _("notify-recipient-uri URI \"%s\" is already used!"),
6114 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6115 "notify-status-code", IPP_ATTRIBUTES
);
6119 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6120 attr
->value_tag
== IPP_TAG_KEYWORD
)
6122 pullmethod
= attr
->values
[0].string
.text
;
6124 if (strcmp(pullmethod
, "ippget"))
6126 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6127 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6128 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6129 "notify-status-code", IPP_ATTRIBUTES
);
6133 else if (!strcmp(attr
->name
, "notify-charset") &&
6134 attr
->value_tag
== IPP_TAG_CHARSET
&&
6135 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6136 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6138 send_ipp_status(con
, IPP_CHARSET
,
6139 _("Character set \"%s\" not supported!"),
6140 attr
->values
[0].string
.text
);
6143 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6144 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6145 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6147 send_ipp_status(con
, IPP_CHARSET
,
6148 _("Language \"%s\" not supported!"),
6149 attr
->values
[0].string
.text
);
6152 else if (!strcmp(attr
->name
, "notify-user-data") &&
6153 attr
->value_tag
== IPP_TAG_STRING
)
6155 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6157 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6158 _("The notify-user-data value is too large "
6159 "(%d > 63 octets)!"),
6160 attr
->values
[0].unknown
.length
);
6166 else if (!strcmp(attr
->name
, "notify-events") &&
6167 attr
->value_tag
== IPP_TAG_KEYWORD
)
6168 notify_events
= attr
;
6169 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6170 attr
->value_tag
== IPP_TAG_INTEGER
)
6171 lease
= attr
->values
[0].integer
;
6172 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6173 attr
->value_tag
== IPP_TAG_INTEGER
)
6174 interval
= attr
->values
[0].integer
;
6175 else if (!strcmp(attr
->name
, "notify-job-id") &&
6176 attr
->value_tag
== IPP_TAG_INTEGER
)
6177 jobid
= attr
->values
[0].integer
;
6184 for (i
= 0; i
< notify_events
->num_values
; i
++)
6185 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6189 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6191 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6192 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6193 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6195 if (!recipient
&& !pullmethod
)
6198 if (mask
== CUPSD_EVENT_NONE
)
6201 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6203 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6206 send_ipp_status(con
, IPP_BAD_REQUEST
,
6207 _("notify-events not specified!"));
6212 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6214 cupsdLogMessage(CUPSD_LOG_INFO
,
6215 "create_subscription: Limiting notify-lease-duration to "
6218 lease
= MaxLeaseDuration
;
6223 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6225 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6232 sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0);
6235 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6238 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6239 "Added subscription %d for printer \"%s\"",
6240 sub
->id
, printer
->name
);
6242 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6245 sub
->interval
= interval
;
6247 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6249 cupsdSetString(&sub
->owner
, username
);
6253 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6254 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6255 sub
->user_data_len
);
6258 ippAddSeparator(con
->response
);
6259 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6260 "notify-subscription-id", sub
->id
);
6262 con
->response
->request
.status
.status_code
= IPP_OK
;
6268 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6273 * 'delete_printer()' - Remove a printer or class from the system.
6277 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6278 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6280 http_status_t status
; /* Policy status */
6281 cups_ptype_t dtype
; /* Destination type (printer/class) */
6282 cupsd_printer_t
*printer
; /* Printer/class */
6283 char filename
[1024]; /* Script/PPD filename */
6286 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6287 con
->http
.fd
, uri
->values
[0].string
.text
);
6290 * Do we have a valid URI?
6293 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6299 send_ipp_status(con
, IPP_NOT_FOUND
,
6300 _("The printer or class was not found."));
6308 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6310 send_http_error(con
, status
, NULL
);
6315 * Remove old jobs...
6318 cupsdCancelJobs(printer
->name
, NULL
, 1);
6321 * Remove old subscriptions and send a "deleted printer" event...
6324 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6325 "%s \"%s\" deleted by \"%s\".",
6326 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6327 printer
->name
, get_username(con
));
6329 cupsdExpireSubscriptions(printer
, NULL
);
6332 * Remove any old PPD or script files...
6335 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6339 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6343 snprintf(filename
, sizeof(filename
), "%s/%s.ipp", CacheDir
, printer
->name
);
6348 * Unregister color profiles...
6351 apple_unregister_profiles(printer
);
6352 #endif /* __APPLE__ */
6354 if (dtype
& CUPS_PRINTER_CLASS
)
6356 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6357 printer
->name
, get_username(con
));
6359 cupsdDeletePrinter(printer
, 0);
6360 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6364 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6365 printer
->name
, get_username(con
));
6367 cupsdDeletePrinter(printer
, 0);
6368 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6371 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6374 * Return with no errors...
6377 con
->response
->request
.status
.status_code
= IPP_OK
;
6382 * 'get_default()' - Get the default destination.
6386 get_default(cupsd_client_t
*con
) /* I - Client connection */
6388 http_status_t status
; /* Policy status */
6389 cups_array_t
*ra
; /* Requested attributes array */
6392 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6398 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6400 send_http_error(con
, status
, NULL
);
6406 ra
= create_requested_array(con
->request
);
6408 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6410 cupsArrayDelete(ra
);
6412 con
->response
->request
.status
.status_code
= IPP_OK
;
6415 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6420 * 'get_devices()' - Get the list of available devices on the local system.
6424 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6426 http_status_t status
; /* Policy status */
6427 ipp_attribute_t
*limit
, /* limit attribute */
6428 *timeout
, /* timeout attribute */
6429 *requested
, /* requested-attributes attribute */
6430 *exclude
; /* exclude-schemes attribute */
6431 char command
[1024], /* cups-deviced command */
6432 options
[1024], /* Options to pass to command */
6434 /* String for requested attributes */
6436 /* String for excluded attributes */
6439 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6445 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6447 send_http_error(con
, status
, NULL
);
6452 * Run cups-deviced command with the given options...
6455 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6456 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6457 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6459 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6462 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6464 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6467 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6469 exclude_str
[0] = '\0';
6471 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6472 snprintf(options
, sizeof(options
),
6473 "%d+%d+%d+%d+%s%s%s",
6474 con
->request
->request
.op
.request_id
,
6475 limit
? limit
->values
[0].integer
: 0,
6476 timeout
? timeout
->values
[0].integer
: 10,
6479 exclude_str
[0] ? "%20" : "", exclude_str
);
6481 if (cupsdSendCommand(con
, command
, options
, 1))
6484 * Command started successfully, don't send an IPP response here...
6487 ippDelete(con
->response
);
6488 con
->response
= NULL
;
6493 * Command failed, return "internal error" so the user knows something
6497 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6498 _("cups-deviced failed to execute."));
6504 * 'get_document()' - Get a copy of a job file.
6508 get_document(cupsd_client_t
*con
, /* I - Client connection */
6509 ipp_attribute_t
*uri
) /* I - Job URI */
6511 http_status_t status
; /* Policy status */
6512 ipp_attribute_t
*attr
; /* Current attribute */
6513 int jobid
; /* Job ID */
6514 int docnum
; /* Document number */
6515 cupsd_job_t
*job
; /* Current job */
6516 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6517 username
[HTTP_MAX_URI
], /* Username portion of URI */
6518 host
[HTTP_MAX_URI
], /* Host portion of URI */
6519 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6520 int port
; /* Port portion of URI */
6521 char filename
[1024], /* Filename for document */
6522 format
[1024]; /* Format for document */
6525 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6526 con
->http
.fd
, uri
->values
[0].string
.text
);
6529 * See if we have a job URI or a printer URI...
6532 if (!strcmp(uri
->name
, "printer-uri"))
6535 * Got a printer URI; see if we also have a job-id attribute...
6538 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6539 IPP_TAG_INTEGER
)) == NULL
)
6541 send_ipp_status(con
, IPP_BAD_REQUEST
,
6542 _("Got a printer-uri attribute but no job-id!"));
6546 jobid
= attr
->values
[0].integer
;
6551 * Got a job URI; parse it to get the job ID...
6554 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6555 sizeof(scheme
), username
, sizeof(username
), host
,
6556 sizeof(host
), &port
, resource
, sizeof(resource
));
6558 if (strncmp(resource
, "/jobs/", 6))
6564 send_ipp_status(con
, IPP_BAD_REQUEST
,
6565 _("Bad job-uri attribute \"%s\"!"),
6566 uri
->values
[0].string
.text
);
6570 jobid
= atoi(resource
+ 6);
6574 * See if the job exists...
6577 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6580 * Nope - return a "not found" error...
6583 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6591 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6593 send_http_error(con
, status
, NULL
);
6598 * Get the document number...
6601 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6602 IPP_TAG_INTEGER
)) == NULL
)
6604 send_ipp_status(con
, IPP_BAD_REQUEST
,
6605 _("Missing document-number attribute!"));
6609 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6610 attr
->num_values
> 1)
6612 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6617 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6619 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6621 cupsdLogMessage(CUPSD_LOG_ERROR
,
6622 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6624 send_ipp_status(con
, IPP_NOT_FOUND
,
6625 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6629 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6633 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6634 job
->filetypes
[docnum
- 1]->type
);
6636 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6638 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6640 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6641 IPP_TAG_NAME
)) != NULL
)
6642 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6643 NULL
, attr
->values
[0].string
.text
);
6648 * 'get_job_attrs()' - Get job attributes.
6652 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6653 ipp_attribute_t
*uri
) /* I - Job URI */
6655 http_status_t status
; /* Policy status */
6656 ipp_attribute_t
*attr
; /* Current attribute */
6657 int jobid
; /* Job ID */
6658 cupsd_job_t
*job
; /* Current job */
6659 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6660 username
[HTTP_MAX_URI
], /* Username portion of URI */
6661 host
[HTTP_MAX_URI
], /* Host portion of URI */
6662 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6663 int port
; /* Port portion of URI */
6664 cups_array_t
*ra
; /* Requested attributes array */
6667 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6668 con
->http
.fd
, uri
->values
[0].string
.text
);
6671 * See if we have a job URI or a printer URI...
6674 if (!strcmp(uri
->name
, "printer-uri"))
6677 * Got a printer URI; see if we also have a job-id attribute...
6680 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6681 IPP_TAG_INTEGER
)) == NULL
)
6683 send_ipp_status(con
, IPP_BAD_REQUEST
,
6684 _("Got a printer-uri attribute but no job-id!"));
6688 jobid
= attr
->values
[0].integer
;
6693 * Got a job URI; parse it to get the job ID...
6696 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6697 sizeof(scheme
), username
, sizeof(username
), host
,
6698 sizeof(host
), &port
, resource
, sizeof(resource
));
6700 if (strncmp(resource
, "/jobs/", 6))
6706 send_ipp_status(con
, IPP_BAD_REQUEST
,
6707 _("Bad job-uri attribute \"%s\"!"),
6708 uri
->values
[0].string
.text
);
6712 jobid
= atoi(resource
+ 6);
6716 * See if the job exists...
6719 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6722 * Nope - return a "not found" error...
6725 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6733 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6735 send_http_error(con
, status
, NULL
);
6740 * Copy attributes...
6745 ra
= create_requested_array(con
->request
);
6746 copy_job_attrs(con
, job
, ra
);
6747 cupsArrayDelete(ra
);
6749 con
->response
->request
.status
.status_code
= IPP_OK
;
6754 * 'get_jobs()' - Get a list of jobs for the specified printer.
6758 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6759 ipp_attribute_t
*uri
) /* I - Printer URI */
6761 http_status_t status
; /* Policy status */
6762 ipp_attribute_t
*attr
; /* Current attribute */
6763 const char *dest
; /* Destination */
6764 cups_ptype_t dtype
; /* Destination type (printer/class) */
6765 cups_ptype_t dmask
; /* Destination type mask */
6766 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6767 username
[HTTP_MAX_URI
], /* Username portion of URI */
6768 host
[HTTP_MAX_URI
], /* Host portion of URI */
6769 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6770 int port
; /* Port portion of URI */
6771 int completed
; /* Completed jobs? */
6772 int first_job_id
; /* First job ID */
6773 int limit
; /* Maximum number of jobs to return */
6774 int count
; /* Number of jobs that match */
6775 cupsd_job_t
*job
; /* Current job pointer */
6776 cupsd_printer_t
*printer
; /* Printer */
6777 cups_array_t
*list
; /* Which job list... */
6778 cups_array_t
*ra
; /* Requested attributes array */
6781 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6782 uri
->values
[0].string
.text
);
6785 * Is the destination valid?
6788 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6789 sizeof(scheme
), username
, sizeof(username
), host
,
6790 sizeof(host
), &port
, resource
, sizeof(resource
));
6792 if (!strcmp(resource
, "/") ||
6793 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
6796 dtype
= (cups_ptype_t
)0;
6797 dmask
= (cups_ptype_t
)0;
6800 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6803 dtype
= (cups_ptype_t
)0;
6804 dmask
= CUPS_PRINTER_CLASS
;
6807 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6810 dtype
= CUPS_PRINTER_CLASS
;
6811 dmask
= CUPS_PRINTER_CLASS
;
6814 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6821 send_ipp_status(con
, IPP_NOT_FOUND
,
6822 _("The printer or class was not found."));
6827 dtype
&= CUPS_PRINTER_CLASS
;
6828 dmask
= CUPS_PRINTER_CLASS
;
6837 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6840 send_http_error(con
, status
, printer
);
6844 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6846 send_http_error(con
, status
, NULL
);
6851 * See if the "which-jobs" attribute have been specified...
6854 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6855 IPP_TAG_KEYWORD
)) != NULL
&&
6856 !strcmp(attr
->values
[0].string
.text
, "completed"))
6861 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6866 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "printing"))
6869 list
= PrintingJobs
;
6878 * See if they want to limit the number of jobs reported...
6881 if ((attr
= ippFindAttribute(con
->request
, "limit",
6882 IPP_TAG_INTEGER
)) != NULL
)
6883 limit
= attr
->values
[0].integer
;
6887 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6888 IPP_TAG_INTEGER
)) != NULL
)
6889 first_job_id
= attr
->values
[0].integer
;
6894 * See if we only want to see jobs for a specific user...
6897 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6898 IPP_TAG_BOOLEAN
)) != NULL
&&
6899 attr
->values
[0].boolean
)
6900 strlcpy(username
, get_username(con
), sizeof(username
));
6904 ra
= create_requested_array(con
->request
);
6907 * OK, build a list of jobs for this printer...
6910 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6911 (limit
<= 0 || count
< limit
) && job
;
6912 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6915 * Filter out jobs that don't match...
6918 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
6920 if (!job
->dest
|| !job
->username
)
6923 if (!job
->dest
|| !job
->username
)
6926 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6927 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6929 if ((job
->dtype
& dmask
) != dtype
&&
6930 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6932 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
6935 if (job
->id
< first_job_id
)
6943 if (username
[0] && strcasecmp(username
, job
->username
))
6947 ippAddSeparator(con
->response
);
6951 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
6953 copy_job_attrs(con
, job
, ra
);
6956 cupsArrayDelete(ra
);
6958 con
->response
->request
.status
.status_code
= IPP_OK
;
6963 * 'get_notifications()' - Get events for a subscription.
6967 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6969 int i
, j
; /* Looping vars */
6970 http_status_t status
; /* Policy status */
6971 cupsd_subscription_t
*sub
; /* Subscription */
6972 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6973 *sequences
; /* notify-sequence-numbers */
6974 int min_seq
; /* Minimum sequence number */
6975 int interval
; /* Poll interval */
6978 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6982 * Get subscription attributes...
6985 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6987 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6992 send_ipp_status(con
, IPP_BAD_REQUEST
,
6993 _("Missing notify-subscription-ids attribute!"));
6998 * Are the subscription IDs valid?
7001 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
7003 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
7006 * Bad subscription ID...
7009 send_ipp_status(con
, IPP_NOT_FOUND
,
7010 _("notify-subscription-id %d no good!"),
7011 ids
->values
[i
].integer
);
7019 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7021 con
, sub
->owner
)) != HTTP_OK
)
7023 send_http_error(con
, status
, sub
->dest
);
7028 * Check the subscription type and update the interval accordingly.
7031 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7034 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7036 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7042 * Tell the client to poll again in N seconds...
7046 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7047 "notify-get-interval", interval
);
7049 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7050 "printer-up-time", time(NULL
));
7053 * Copy the subscription event attributes to the response.
7056 con
->response
->request
.status
.status_code
=
7057 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7059 for (i
= 0; i
< ids
->num_values
; i
++)
7062 * Get the subscription and sequence number...
7065 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7067 if (sequences
&& i
< sequences
->num_values
)
7068 min_seq
= sequences
->values
[i
].integer
;
7073 * If we don't have any new events, nothing to do here...
7076 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7080 * Otherwise copy all of the new events...
7083 if (sub
->first_event_id
> min_seq
)
7086 j
= min_seq
- sub
->first_event_id
;
7088 for (; j
< sub
->num_events
; j
++)
7090 ippAddSeparator(con
->response
);
7092 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7093 IPP_TAG_EVENT_NOTIFICATION
, 0);
7100 * 'get_ppd()' - Get a named PPD from the local system.
7104 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7105 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7107 http_status_t status
; /* Policy status */
7108 cupsd_printer_t
*dest
; /* Destination */
7109 cups_ptype_t dtype
; /* Destination type */
7112 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7113 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7115 if (!strcmp(uri
->name
, "ppd-name"))
7118 * Return a PPD file from cups-driverd...
7121 char command
[1024], /* cups-driverd command */
7122 options
[1024], /* Options to pass to command */
7123 ppd_name
[1024]; /* ppd-name */
7130 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7132 send_http_error(con
, status
, NULL
);
7137 * Run cups-driverd command with the given options...
7140 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7141 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7142 snprintf(options
, sizeof(options
), "get+%d+%s",
7143 con
->request
->request
.op
.request_id
, ppd_name
);
7145 if (cupsdSendCommand(con
, command
, options
, 0))
7148 * Command started successfully, don't send an IPP response here...
7151 ippDelete(con
->response
);
7152 con
->response
= NULL
;
7157 * Command failed, return "internal error" so the user knows something
7161 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7162 _("cups-driverd failed to execute."));
7165 else if (!strcmp(uri
->name
, "printer-uri") &&
7166 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7168 int i
; /* Looping var */
7169 char filename
[1024]; /* PPD filename */
7176 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7178 send_http_error(con
, status
, dest
);
7183 * See if we need the PPD for a class or remote printer...
7186 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7189 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7191 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7192 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7193 "printer-uri", NULL
, dest
->uri
);
7196 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7198 for (i
= 0; i
< dest
->num_printers
; i
++)
7199 if (!(dest
->printers
[i
]->type
&
7200 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7202 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7203 dest
->printers
[i
]->name
);
7205 if (!access(filename
, 0))
7209 if (i
< dest
->num_printers
)
7210 dest
= dest
->printers
[i
];
7213 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7214 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7215 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7221 * Found the printer with the PPD file, now see if there is one...
7224 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7226 send_ipp_status(con
, IPP_NOT_FOUND
,
7227 _("The PPD file \"%s\" could not be opened: %s"),
7228 uri
->values
[0].string
.text
, strerror(errno
));
7232 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7236 con
->response
->request
.status
.status_code
= IPP_OK
;
7239 send_ipp_status(con
, IPP_NOT_FOUND
,
7240 _("The PPD file \"%s\" could not be found."),
7241 uri
->values
[0].string
.text
);
7246 * 'get_ppds()' - Get the list of PPD files on the local system.
7250 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7252 http_status_t status
; /* Policy status */
7253 ipp_attribute_t
*limit
, /* Limit attribute */
7254 *device
, /* ppd-device-id attribute */
7255 *language
, /* ppd-natural-language attribute */
7256 *make
, /* ppd-make attribute */
7257 *model
, /* ppd-make-and-model attribute */
7258 *model_number
, /* ppd-model-number attribute */
7259 *product
, /* ppd-product attribute */
7260 *psversion
, /* ppd-psverion attribute */
7261 *type
, /* ppd-type attribute */
7262 *requested
; /* requested-attributes attribute */
7263 char command
[1024], /* cups-driverd command */
7264 options
[1024], /* Options to pass to command */
7265 device_str
[256],/* Escaped ppd-device-id string */
7267 /* Escaped ppd-natural-language */
7268 make_str
[256], /* Escaped ppd-make string */
7269 model_str
[256], /* Escaped ppd-make-and-model string */
7270 model_number_str
[256],
7271 /* ppd-model-number string */
7273 /* Escaped ppd-product string */
7275 /* Escaped ppd-psversion string */
7276 type_str
[256], /* Escaped ppd-type string */
7278 /* String for requested attributes */
7281 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7287 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7289 send_http_error(con
, status
, NULL
);
7294 * Run cups-driverd command with the given options...
7297 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7298 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7299 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7301 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7302 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7304 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7306 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7307 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7308 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7309 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7313 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7315 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7318 url_encode_attr(device
, device_str
, sizeof(device_str
));
7320 device_str
[0] = '\0';
7323 url_encode_attr(language
, language_str
, sizeof(language_str
));
7325 language_str
[0] = '\0';
7328 url_encode_attr(make
, make_str
, sizeof(make_str
));
7333 url_encode_attr(model
, model_str
, sizeof(model_str
));
7335 model_str
[0] = '\0';
7338 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7339 model_number
->values
[0].integer
);
7341 model_number_str
[0] = '\0';
7344 url_encode_attr(product
, product_str
, sizeof(product_str
));
7346 product_str
[0] = '\0';
7349 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7351 psversion_str
[0] = '\0';
7354 url_encode_attr(type
, type_str
, sizeof(type_str
));
7358 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7359 snprintf(options
, sizeof(options
),
7360 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7361 con
->request
->request
.op
.request_id
,
7362 limit
? limit
->values
[0].integer
: 0,
7364 device
? "%20" : "", device_str
,
7365 language
? "%20" : "", language_str
,
7366 make
? "%20" : "", make_str
,
7367 model
? "%20" : "", model_str
,
7368 model_number
? "%20" : "", model_number_str
,
7369 product
? "%20" : "", product_str
,
7370 psversion
? "%20" : "", psversion_str
,
7371 type
? "%20" : "", type_str
);
7373 if (cupsdSendCommand(con
, command
, options
, 0))
7376 * Command started successfully, don't send an IPP response here...
7379 ippDelete(con
->response
);
7380 con
->response
= NULL
;
7385 * Command failed, return "internal error" so the user knows something
7389 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7390 _("cups-driverd failed to execute."));
7396 * 'get_printer_attrs()' - Get printer attributes.
7400 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7401 ipp_attribute_t
*uri
) /* I - Printer URI */
7403 http_status_t status
; /* Policy status */
7404 cups_ptype_t dtype
; /* Destination type (printer/class) */
7405 cupsd_printer_t
*printer
; /* Printer/class */
7406 cups_array_t
*ra
; /* Requested attributes array */
7409 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7410 con
->http
.fd
, uri
->values
[0].string
.text
);
7413 * Is the destination valid?
7416 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7422 send_ipp_status(con
, IPP_NOT_FOUND
,
7423 _("The printer or class was not found."));
7431 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7433 send_http_error(con
, status
, printer
);
7438 * Send the attributes...
7441 ra
= create_requested_array(con
->request
);
7443 copy_printer_attrs(con
, printer
, ra
);
7445 cupsArrayDelete(ra
);
7447 con
->response
->request
.status
.status_code
= IPP_OK
;
7452 * 'get_printers()' - Get a list of printers or classes.
7456 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7457 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7459 http_status_t status
; /* Policy status */
7460 ipp_attribute_t
*attr
; /* Current attribute */
7461 int limit
; /* Max number of printers to return */
7462 int count
; /* Number of printers that match */
7463 cupsd_printer_t
*printer
; /* Current printer pointer */
7464 int printer_type
, /* printer-type attribute */
7465 printer_mask
; /* printer-type-mask attribute */
7466 char *location
; /* Location string */
7467 const char *username
; /* Current user */
7468 char *first_printer_name
; /* first-printer-name attribute */
7469 cups_array_t
*ra
; /* Requested attributes array */
7472 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7473 con
->http
.fd
, type
);
7479 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7481 send_http_error(con
, status
, NULL
);
7486 * Check for printers...
7489 if (!Printers
|| !cupsArrayCount(Printers
))
7491 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7496 * See if they want to limit the number of printers reported...
7499 if ((attr
= ippFindAttribute(con
->request
, "limit",
7500 IPP_TAG_INTEGER
)) != NULL
)
7501 limit
= attr
->values
[0].integer
;
7505 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7506 IPP_TAG_NAME
)) != NULL
)
7507 first_printer_name
= attr
->values
[0].string
.text
;
7509 first_printer_name
= NULL
;
7512 * Support filtering...
7515 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7516 IPP_TAG_ENUM
)) != NULL
)
7517 printer_type
= attr
->values
[0].integer
;
7521 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7522 IPP_TAG_ENUM
)) != NULL
)
7523 printer_mask
= attr
->values
[0].integer
;
7527 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7528 IPP_TAG_TEXT
)) != NULL
)
7529 location
= attr
->values
[0].string
.text
;
7533 if (con
->username
[0])
7534 username
= con
->username
;
7535 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7536 IPP_TAG_NAME
)) != NULL
)
7537 username
= attr
->values
[0].string
.text
;
7541 ra
= create_requested_array(con
->request
);
7544 * OK, build a list of printers for this printer...
7547 if (first_printer_name
)
7549 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7550 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7553 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7556 count
< limit
&& printer
;
7557 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7559 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7560 (printer
->type
& printer_mask
) == printer_type
&&
7562 (printer
->location
&& !strcasecmp(printer
->location
, location
))))
7565 * If HideImplicitMembers is enabled, see if this printer or class
7566 * is a member of an implicit class...
7569 if (ImplicitClasses
&& HideImplicitMembers
&&
7570 printer
->in_implicit_class
)
7574 * If a username is specified, see if it is allowed or denied
7578 if (!(printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
7579 printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7583 * Add the group separator as needed...
7587 ippAddSeparator(con
->response
);
7592 * Send the attributes...
7595 copy_printer_attrs(con
, printer
, ra
);
7599 cupsArrayDelete(ra
);
7601 con
->response
->request
.status
.status_code
= IPP_OK
;
7606 * 'get_subscription_attrs()' - Get subscription attributes.
7610 get_subscription_attrs(
7611 cupsd_client_t
*con
, /* I - Client connection */
7612 int sub_id
) /* I - Subscription ID */
7614 http_status_t status
; /* Policy status */
7615 cupsd_subscription_t
*sub
; /* Subscription */
7616 cups_array_t
*ra
; /* Requested attributes array */
7619 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7620 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7621 con
, con
->http
.fd
, sub_id
);
7624 * Is the subscription ID valid?
7627 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7630 * Bad subscription ID...
7633 send_ipp_status(con
, IPP_NOT_FOUND
,
7634 _("notify-subscription-id %d no good!"), sub_id
);
7642 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7644 con
, sub
->owner
)) != HTTP_OK
)
7646 send_http_error(con
, status
, sub
->dest
);
7651 * Copy the subscription attributes to the response using the
7652 * requested-attributes attribute that may be provided by the client.
7655 ra
= create_requested_array(con
->request
);
7657 copy_subscription_attrs(con
, sub
, ra
);
7659 cupsArrayDelete(ra
);
7661 con
->response
->request
.status
.status_code
= IPP_OK
;
7666 * 'get_subscriptions()' - Get subscriptions.
7670 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7671 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7673 http_status_t status
; /* Policy status */
7674 int count
; /* Number of subscriptions */
7675 int limit
; /* Limit */
7676 cupsd_subscription_t
*sub
; /* Subscription */
7677 cups_array_t
*ra
; /* Requested attributes array */
7678 ipp_attribute_t
*attr
; /* Attribute */
7679 cups_ptype_t dtype
; /* Destination type (printer/class) */
7680 char scheme
[HTTP_MAX_URI
],
7681 /* Scheme portion of URI */
7682 username
[HTTP_MAX_URI
],
7683 /* Username portion of URI */
7685 /* Host portion of URI */
7686 resource
[HTTP_MAX_URI
];
7687 /* Resource portion of URI */
7688 int port
; /* Port portion of URI */
7689 cupsd_job_t
*job
; /* Job pointer */
7690 cupsd_printer_t
*printer
; /* Printer */
7693 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7694 "get_subscriptions(con=%p[%d], uri=%s)",
7695 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7698 * Is the destination valid?
7701 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7702 sizeof(scheme
), username
, sizeof(username
), host
,
7703 sizeof(host
), &port
, resource
, sizeof(resource
));
7705 if (!strcmp(resource
, "/") ||
7706 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7707 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7708 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7713 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7716 job
= cupsdFindJob(atoi(resource
+ 6));
7720 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7725 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7731 send_ipp_status(con
, IPP_NOT_FOUND
,
7732 _("The printer or class was not found."));
7735 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7736 IPP_TAG_INTEGER
)) != NULL
)
7738 job
= cupsdFindJob(attr
->values
[0].integer
);
7742 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7743 attr
->values
[0].integer
);
7754 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7756 con
, NULL
)) != HTTP_OK
)
7758 send_http_error(con
, status
, printer
);
7763 * Copy the subscription attributes to the response using the
7764 * requested-attributes attribute that may be provided by the client.
7767 ra
= create_requested_array(con
->request
);
7769 if ((attr
= ippFindAttribute(con
->request
, "limit",
7770 IPP_TAG_INTEGER
)) != NULL
)
7771 limit
= attr
->values
[0].integer
;
7776 * See if we only want to see subscriptions for a specific user...
7779 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7780 IPP_TAG_BOOLEAN
)) != NULL
&&
7781 attr
->values
[0].boolean
)
7782 strlcpy(username
, get_username(con
), sizeof(username
));
7786 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7788 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7789 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7790 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7792 ippAddSeparator(con
->response
);
7793 copy_subscription_attrs(con
, sub
, ra
);
7796 if (limit
&& count
>= limit
)
7800 cupsArrayDelete(ra
);
7803 con
->response
->request
.status
.status_code
= IPP_OK
;
7805 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7810 * 'get_username()' - Get the username associated with a request.
7813 static const char * /* O - Username */
7814 get_username(cupsd_client_t
*con
) /* I - Connection */
7816 ipp_attribute_t
*attr
; /* Attribute */
7819 if (con
->username
[0])
7820 return (con
->username
);
7821 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7822 IPP_TAG_NAME
)) != NULL
)
7823 return (attr
->values
[0].string
.text
);
7825 return ("anonymous");
7830 * 'hold_job()' - Hold a print job.
7834 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7835 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7837 ipp_attribute_t
*attr
, /* Current job-hold-until */
7838 *newattr
; /* New job-hold-until */
7839 int jobid
; /* Job ID */
7840 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7841 username
[HTTP_MAX_URI
], /* Username portion of URI */
7842 host
[HTTP_MAX_URI
], /* Host portion of URI */
7843 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7844 int port
; /* Port portion of URI */
7845 cupsd_job_t
*job
; /* Job information */
7848 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7849 uri
->values
[0].string
.text
);
7852 * See if we have a job URI or a printer URI...
7855 if (!strcmp(uri
->name
, "printer-uri"))
7858 * Got a printer URI; see if we also have a job-id attribute...
7861 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7862 IPP_TAG_INTEGER
)) == NULL
)
7864 send_ipp_status(con
, IPP_BAD_REQUEST
,
7865 _("Got a printer-uri attribute but no job-id!"));
7869 jobid
= attr
->values
[0].integer
;
7874 * Got a job URI; parse it to get the job ID...
7877 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7878 sizeof(scheme
), username
, sizeof(username
), host
,
7879 sizeof(host
), &port
, resource
, sizeof(resource
));
7881 if (strncmp(resource
, "/jobs/", 6))
7887 send_ipp_status(con
, IPP_BAD_REQUEST
,
7888 _("Bad job-uri attribute \"%s\"!"),
7889 uri
->values
[0].string
.text
);
7893 jobid
= atoi(resource
+ 6);
7897 * See if the job exists...
7900 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7903 * Nope - return a "not found" error...
7906 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7911 * See if the job is owned by the requesting user...
7914 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7916 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
7921 * Hold the job and return...
7926 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
7927 "Job held by user.");
7929 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
7930 IPP_TAG_KEYWORD
)) == NULL
)
7931 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7933 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7934 IPP_TAG_KEYWORD
)) == NULL
)
7935 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7940 * Free the old hold value and copy the new one over...
7943 _cupsStrFree(attr
->values
[0].string
.text
);
7947 attr
->value_tag
= newattr
->value_tag
;
7948 attr
->values
[0].string
.text
=
7949 _cupsStrAlloc(newattr
->values
[0].string
.text
);
7953 attr
->value_tag
= IPP_TAG_KEYWORD
;
7954 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
7958 * Hold job until specified time...
7961 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
7963 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7964 "Job job-hold-until value changed by user.");
7967 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Held by \"%s\".", username
);
7969 con
->response
->request
.status
.status_code
= IPP_OK
;
7974 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7978 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7979 ipp_attribute_t
*uri
) /* I - Printer URI */
7981 http_status_t status
; /* Policy status */
7982 cups_ptype_t dtype
; /* Destination type (printer/class) */
7983 cupsd_printer_t
*printer
; /* Printer data */
7986 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7987 con
->http
.fd
, uri
->values
[0].string
.text
);
7990 * Is the destination valid?
7993 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7999 send_ipp_status(con
, IPP_NOT_FOUND
,
8000 _("The printer or class was not found."));
8008 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8010 send_http_error(con
, status
, printer
);
8015 * Hold pending/new jobs sent to the printer...
8018 printer
->holding_new_jobs
= 1;
8020 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8021 cupsdAddPrinterHistory(printer
);
8023 if (dtype
& CUPS_PRINTER_CLASS
)
8024 cupsdLogMessage(CUPSD_LOG_INFO
,
8025 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8026 printer
->name
, get_username(con
));
8028 cupsdLogMessage(CUPSD_LOG_INFO
,
8029 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8030 printer
->name
, get_username(con
));
8033 * Everything was ok, so return OK status...
8036 con
->response
->request
.status
.status_code
= IPP_OK
;
8041 * 'move_job()' - Move a job to a new destination.
8045 move_job(cupsd_client_t
*con
, /* I - Client connection */
8046 ipp_attribute_t
*uri
) /* I - Job URI */
8048 http_status_t status
; /* Policy status */
8049 ipp_attribute_t
*attr
; /* Current attribute */
8050 int jobid
; /* Job ID */
8051 cupsd_job_t
*job
; /* Current job */
8052 const char *src
; /* Source printer/class */
8053 cups_ptype_t stype
, /* Source type (printer or class) */
8054 dtype
; /* Destination type (printer/class) */
8055 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8056 username
[HTTP_MAX_URI
], /* Username portion of URI */
8057 host
[HTTP_MAX_URI
], /* Host portion of URI */
8058 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8059 int port
; /* Port portion of URI */
8060 cupsd_printer_t
*sprinter
, /* Source printer */
8061 *dprinter
; /* Destination printer */
8064 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
8065 uri
->values
[0].string
.text
);
8068 * Get the new printer or class...
8071 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8072 IPP_TAG_URI
)) == NULL
)
8075 * Need job-printer-uri...
8078 send_ipp_status(con
, IPP_BAD_REQUEST
,
8079 _("job-printer-uri attribute missing!"));
8083 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8089 send_ipp_status(con
, IPP_NOT_FOUND
,
8090 _("The printer or class was not found."));
8095 * See if we have a job URI or a printer URI...
8098 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8099 sizeof(scheme
), username
, sizeof(username
), host
,
8100 sizeof(host
), &port
, resource
, sizeof(resource
));
8102 if (!strcmp(uri
->name
, "printer-uri"))
8105 * Got a printer URI; see if we also have a job-id attribute...
8108 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8109 IPP_TAG_INTEGER
)) == NULL
)
8115 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8116 &sprinter
)) == NULL
)
8122 send_ipp_status(con
, IPP_NOT_FOUND
,
8123 _("The printer or class was not found."));
8132 * Otherwise, just move a single job...
8135 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8138 * Nope - return a "not found" error...
8141 send_ipp_status(con
, IPP_NOT_FOUND
,
8142 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8148 * Job found, initialize source pointers...
8159 * Got a job URI; parse it to get the job ID...
8162 if (strncmp(resource
, "/jobs/", 6))
8168 send_ipp_status(con
, IPP_BAD_REQUEST
,
8169 _("Bad job-uri attribute \"%s\"!"),
8170 uri
->values
[0].string
.text
);
8175 * See if the job exists...
8178 jobid
= atoi(resource
+ 6);
8180 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8183 * Nope - return a "not found" error...
8186 send_ipp_status(con
, IPP_NOT_FOUND
,
8187 _("Job #%d does not exist!"), jobid
);
8193 * Job found, initialize source pointers...
8202 * Check the policy of the destination printer...
8205 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8206 job
? job
->username
: NULL
)) != HTTP_OK
)
8208 send_http_error(con
, status
, dprinter
);
8213 * Now move the job or jobs...
8219 * See if the job has been completed...
8222 if (job
->state_value
> IPP_JOB_STOPPED
)
8225 * Return a "not-possible" error...
8228 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8229 _("Job #%d is finished and cannot be altered!"),
8235 * See if the job is owned by the requesting user...
8238 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8240 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8245 * Move the job to a different printer or class...
8248 cupsdMoveJob(job
, dprinter
);
8253 * Got the source printer, now look through the jobs...
8256 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8258 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8261 * See if the job is pointing at the source printer or has not been
8265 if (strcasecmp(job
->dest
, src
) ||
8266 job
->state_value
> IPP_JOB_STOPPED
)
8270 * See if the job can be moved by the requesting user...
8273 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8277 * Move the job to a different printer or class...
8280 cupsdMoveJob(job
, dprinter
);
8285 * Start jobs if possible...
8291 * Return with "everything is OK" status...
8294 con
->response
->request
.status
.status_code
= IPP_OK
;
8299 * 'ppd_parse_line()' - Parse a PPD default line.
8302 static int /* O - 0 on success, -1 on failure */
8303 ppd_parse_line(const char *line
, /* I - Line */
8304 char *option
, /* O - Option name */
8305 int olen
, /* I - Size of option name */
8306 char *choice
, /* O - Choice name */
8307 int clen
) /* I - Size of choice name */
8310 * Verify this is a default option line...
8313 if (strncmp(line
, "*Default", 8))
8317 * Read the option name...
8320 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
8330 * Skip everything else up to the colon (:)...
8333 while (*line
&& *line
!= ':')
8342 * Now grab the option choice, skipping leading whitespace...
8345 while (isspace(*line
& 255))
8348 for (clen
--; isalnum(*line
& 255); line
++)
8358 * Return with no errors...
8366 * 'print_job()' - Print a file to a printer or class.
8370 print_job(cupsd_client_t
*con
, /* I - Client connection */
8371 ipp_attribute_t
*uri
) /* I - Printer URI */
8373 ipp_attribute_t
*attr
; /* Current attribute */
8374 ipp_attribute_t
*format
; /* Document-format attribute */
8375 const char *default_format
; /* document-format-default value */
8376 cupsd_job_t
*job
; /* New job */
8377 char filename
[1024]; /* Job filename */
8378 mime_type_t
*filetype
; /* Type of file */
8379 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8380 type
[MIME_MAX_TYPE
], /* Subtype of file */
8381 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8382 /* Textual name of mime type */
8383 cupsd_printer_t
*printer
; /* Printer data */
8384 struct stat fileinfo
; /* File information */
8385 int kbytes
; /* Size of file */
8386 int compression
; /* Document compression */
8389 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8390 uri
->values
[0].string
.text
);
8393 * Validate print file attributes, for now just document-format and
8394 * compression (CUPS only supports "none" and "gzip")...
8397 compression
= CUPS_FILE_NONE
;
8399 if ((attr
= ippFindAttribute(con
->request
, "compression",
8400 IPP_TAG_KEYWORD
)) != NULL
)
8402 if (strcmp(attr
->values
[0].string
.text
, "none")
8404 && strcmp(attr
->values
[0].string
.text
, "gzip")
8405 #endif /* HAVE_LIBZ */
8408 send_ipp_status(con
, IPP_ATTRIBUTES
,
8409 _("Unsupported compression \"%s\"!"),
8410 attr
->values
[0].string
.text
);
8411 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8412 "compression", NULL
, attr
->values
[0].string
.text
);
8417 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8418 compression
= CUPS_FILE_GZIP
;
8419 #endif /* HAVE_LIBZ */
8423 * Do we have a file to print?
8428 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8433 * Is the destination valid?
8436 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8442 send_ipp_status(con
, IPP_NOT_FOUND
,
8443 _("The printer or class was not found."));
8448 * Is it a format we support?
8451 if ((format
= ippFindAttribute(con
->request
, "document-format",
8452 IPP_TAG_MIMETYPE
)) != NULL
)
8455 * Grab format from client...
8458 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8461 send_ipp_status(con
, IPP_BAD_REQUEST
,
8462 _("Could not scan type \"%s\"!"),
8463 format
->values
[0].string
.text
);
8467 else if ((default_format
= cupsGetOption("document-format",
8468 printer
->num_options
,
8469 printer
->options
)) != NULL
)
8472 * Use default document format...
8475 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8477 send_ipp_status(con
, IPP_BAD_REQUEST
,
8478 _("Could not scan type \"%s\"!"),
8489 strcpy(super
, "application");
8490 strcpy(type
, "octet-stream");
8493 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8496 * Auto-type the file...
8499 ipp_attribute_t
*doc_name
; /* document-name attribute */
8502 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8504 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8505 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8506 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8510 filetype
= mimeType(MimeDatabase
, super
, type
);
8512 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8513 filetype
->super
, filetype
->type
);
8516 filetype
= mimeType(MimeDatabase
, super
, type
);
8520 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8523 * Replace the document-format attribute value with the auto-typed or
8527 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8532 _cupsStrFree(format
->values
[0].string
.text
);
8534 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8537 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8538 "document-format", NULL
, mimetype
);
8542 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8543 _("Unsupported format \'%s/%s\'!"), super
, type
);
8544 cupsdLogMessage(CUPSD_LOG_INFO
,
8545 "Hint: Do you have the raw file printing rules enabled?");
8548 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8549 "document-format", NULL
, format
->values
[0].string
.text
);
8555 * Read any embedded job ticket info from PS files...
8558 if (!strcasecmp(filetype
->super
, "application") &&
8559 (!strcasecmp(filetype
->type
, "postscript") ||
8560 !strcasecmp(filetype
->type
, "pdf")))
8561 read_job_ticket(con
);
8564 * Create the job object...
8567 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8571 * Update quota data...
8574 if (stat(con
->filename
, &fileinfo
))
8577 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8579 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8581 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8582 IPP_TAG_INTEGER
)) != NULL
)
8583 attr
->values
[0].integer
+= kbytes
;
8586 * Add the job file...
8589 if (add_file(con
, job
, filetype
, compression
))
8592 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8594 rename(con
->filename
, filename
);
8595 cupsdClearString(&con
->filename
);
8598 * See if we need to add the ending sheet...
8601 if (cupsdTimeoutJob(job
))
8605 * Log and save the job...
8608 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8609 "File of type %s/%s queued by \"%s\".",
8610 filetype
->super
, filetype
->type
, job
->username
);
8611 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8612 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8613 job
->dest
, job
->username
);
8616 * Start the job if possible...
8624 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8626 * This function only gets called when printing a single PDF or PostScript
8627 * file using the Print-Job operation. It doesn't work for Create-Job +
8628 * Send-File, since the job attributes need to be set at job creation
8629 * time for banners to work. The embedded job ticket stuff is here
8630 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8631 * options and IPP attributes which otherwise would be lost.
8633 * The format of a job ticket is simple:
8635 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8637 * %cupsJobTicket: attr1=value1
8638 * %cupsJobTicket: attr2=value2
8640 * %cupsJobTicket: attrN=valueN
8642 * Job ticket lines must appear immediately after the first line that
8643 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8644 * stops looking for job ticket info when it finds a line that does not begin
8645 * with "%cupsJobTicket:".
8647 * The maximum length of a job ticket line, including the prefix, is
8648 * 255 characters to conform with the Adobe DSC.
8650 * Read-only attributes are rejected with a notice to the error log in
8651 * case a malicious user tries anything. Since the job ticket is read
8652 * prior to attribute validation in print_job(), job ticket attributes
8653 * will go through the same validation as IPP attributes...
8657 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8659 cups_file_t
*fp
; /* File to read from */
8660 char line
[256]; /* Line data */
8661 int num_options
; /* Number of options */
8662 cups_option_t
*options
; /* Options */
8663 ipp_t
*ticket
; /* New attributes */
8664 ipp_attribute_t
*attr
, /* Current attribute */
8665 *attr2
, /* Job attribute */
8666 *prev2
; /* Previous job attribute */
8670 * First open the print file...
8673 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8675 cupsdLogMessage(CUPSD_LOG_ERROR
,
8676 "Unable to open print file for job ticket - %s",
8682 * Skip the first line...
8685 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8687 cupsdLogMessage(CUPSD_LOG_ERROR
,
8688 "Unable to read from print file for job ticket - %s",
8694 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8697 * Not a DSC-compliant file, so no job ticket info will be available...
8705 * Read job ticket info from the file...
8711 while (cupsFileGets(fp
, line
, sizeof(line
)))
8714 * Stop at the first non-ticket line...
8717 if (strncmp(line
, "%cupsJobTicket:", 15))
8721 * Add the options to the option array...
8724 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8728 * Done with the file; see if we have any options...
8733 if (num_options
== 0)
8737 * OK, convert the options to an attribute list, and apply them to
8742 cupsEncodeOptions(ticket
, num_options
, options
);
8745 * See what the user wants to change.
8748 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8750 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8753 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8754 !strcmp(attr
->name
, "job-originating-user-name") ||
8755 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8756 !strcmp(attr
->name
, "job-k-octets") ||
8757 !strcmp(attr
->name
, "job-id") ||
8758 !strncmp(attr
->name
, "job-state", 9) ||
8759 !strncmp(attr
->name
, "time-at-", 8))
8760 continue; /* Read-only attrs */
8762 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8763 IPP_TAG_ZERO
)) != NULL
)
8766 * Some other value; first free the old value...
8769 if (con
->request
->attrs
== attr2
)
8771 con
->request
->attrs
= attr2
->next
;
8776 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8777 if (prev2
->next
== attr2
)
8779 prev2
->next
= attr2
->next
;
8784 if (con
->request
->last
== attr2
)
8785 con
->request
->last
= prev2
;
8787 _ippFreeAttr(attr2
);
8791 * Add new option by copying it...
8794 copy_attribute(con
->request
, attr
, 0);
8798 * Then free the attribute list and option array...
8802 cupsFreeOptions(num_options
, options
);
8807 * 'reject_jobs()' - Reject print jobs to a printer.
8811 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8812 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8814 http_status_t status
; /* Policy status */
8815 cups_ptype_t dtype
; /* Destination type (printer/class) */
8816 cupsd_printer_t
*printer
; /* Printer data */
8817 ipp_attribute_t
*attr
; /* printer-state-message text */
8820 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8821 con
->http
.fd
, uri
->values
[0].string
.text
);
8824 * Is the destination valid?
8827 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8833 send_ipp_status(con
, IPP_NOT_FOUND
,
8834 _("The printer or class was not found."));
8842 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8844 send_http_error(con
, status
, printer
);
8849 * Reject jobs sent to the printer...
8852 printer
->accepting
= 0;
8854 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8855 IPP_TAG_TEXT
)) == NULL
)
8856 strcpy(printer
->state_message
, "Rejecting Jobs");
8858 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8859 sizeof(printer
->state_message
));
8861 cupsdAddPrinterHistory(printer
);
8863 if (dtype
& CUPS_PRINTER_CLASS
)
8865 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8867 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8868 printer
->name
, get_username(con
));
8872 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8874 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8875 printer
->name
, get_username(con
));
8879 * Everything was ok, so return OK status...
8882 con
->response
->request
.status
.status_code
= IPP_OK
;
8887 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8891 release_held_new_jobs(
8892 cupsd_client_t
*con
, /* I - Connection */
8893 ipp_attribute_t
*uri
) /* I - Printer URI */
8895 http_status_t status
; /* Policy status */
8896 cups_ptype_t dtype
; /* Destination type (printer/class) */
8897 cupsd_printer_t
*printer
; /* Printer data */
8900 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8901 con
->http
.fd
, uri
->values
[0].string
.text
);
8904 * Is the destination valid?
8907 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8913 send_ipp_status(con
, IPP_NOT_FOUND
,
8914 _("The printer or class was not found."));
8922 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8924 send_http_error(con
, status
, printer
);
8929 * Hold pending/new jobs sent to the printer...
8932 printer
->holding_new_jobs
= 0;
8934 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8935 cupsdAddPrinterHistory(printer
);
8937 if (dtype
& CUPS_PRINTER_CLASS
)
8938 cupsdLogMessage(CUPSD_LOG_INFO
,
8939 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8940 printer
->name
, get_username(con
));
8942 cupsdLogMessage(CUPSD_LOG_INFO
,
8943 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8944 printer
->name
, get_username(con
));
8947 * Everything was ok, so return OK status...
8950 con
->response
->request
.status
.status_code
= IPP_OK
;
8955 * 'release_job()' - Release a held print job.
8959 release_job(cupsd_client_t
*con
, /* I - Client connection */
8960 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8962 ipp_attribute_t
*attr
; /* Current attribute */
8963 int jobid
; /* Job ID */
8964 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8965 username
[HTTP_MAX_URI
], /* Username portion of URI */
8966 host
[HTTP_MAX_URI
], /* Host portion of URI */
8967 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8968 int port
; /* Port portion of URI */
8969 cupsd_job_t
*job
; /* Job information */
8972 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8973 con
->http
.fd
, uri
->values
[0].string
.text
);
8976 * See if we have a job URI or a printer URI...
8979 if (!strcmp(uri
->name
, "printer-uri"))
8982 * Got a printer URI; see if we also have a job-id attribute...
8985 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8986 IPP_TAG_INTEGER
)) == NULL
)
8988 send_ipp_status(con
, IPP_BAD_REQUEST
,
8989 _("Got a printer-uri attribute but no job-id!"));
8993 jobid
= attr
->values
[0].integer
;
8998 * Got a job URI; parse it to get the job ID...
9001 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9002 sizeof(scheme
), username
, sizeof(username
), host
,
9003 sizeof(host
), &port
, resource
, sizeof(resource
));
9005 if (strncmp(resource
, "/jobs/", 6))
9011 send_ipp_status(con
, IPP_BAD_REQUEST
,
9012 _("Bad job-uri attribute \"%s\"!"),
9013 uri
->values
[0].string
.text
);
9017 jobid
= atoi(resource
+ 6);
9021 * See if the job exists...
9024 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9027 * Nope - return a "not found" error...
9030 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9035 * See if job is "held"...
9038 if (job
->state_value
!= IPP_JOB_HELD
)
9041 * Nope - return a "not possible" error...
9044 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
9049 * See if the job is owned by the requesting user...
9052 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9054 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9059 * Reset the job-hold-until value to "no-hold"...
9062 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9063 IPP_TAG_KEYWORD
)) == NULL
)
9064 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9068 _cupsStrFree(attr
->values
[0].string
.text
);
9070 attr
->value_tag
= IPP_TAG_KEYWORD
;
9071 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
9073 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9074 "Job job-hold-until value changed by user.");
9078 * Release the job and return...
9081 cupsdReleaseJob(job
);
9083 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9084 "Job released by user.");
9086 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9088 con
->response
->request
.status
.status_code
= IPP_OK
;
9095 * 'renew_subscription()' - Renew an existing subscription...
9100 cupsd_client_t
*con
, /* I - Client connection */
9101 int sub_id
) /* I - Subscription ID */
9103 http_status_t status
; /* Policy status */
9104 cupsd_subscription_t
*sub
; /* Subscription */
9105 ipp_attribute_t
*lease
; /* notify-lease-duration */
9108 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9109 "renew_subscription(con=%p[%d], sub_id=%d)",
9110 con
, con
->http
.fd
, sub_id
);
9113 * Is the subscription ID valid?
9116 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9119 * Bad subscription ID...
9122 send_ipp_status(con
, IPP_NOT_FOUND
,
9123 _("notify-subscription-id %d no good!"), sub_id
);
9130 * Job subscriptions cannot be renewed...
9133 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9134 _("Job subscriptions cannot be renewed!"));
9142 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9144 con
, sub
->owner
)) != HTTP_OK
)
9146 send_http_error(con
, status
, sub
->dest
);
9151 * Renew the subscription...
9154 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9157 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9159 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9161 cupsdLogMessage(CUPSD_LOG_INFO
,
9162 "renew_subscription: Limiting notify-lease-duration to "
9165 sub
->lease
= MaxLeaseDuration
;
9168 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9170 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9172 con
->response
->request
.status
.status_code
= IPP_OK
;
9174 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9175 "notify-lease-duration", sub
->lease
);
9180 * 'restart_job()' - Restart an old print job.
9184 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9185 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9187 ipp_attribute_t
*attr
; /* Current attribute */
9188 int jobid
; /* Job ID */
9189 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9190 username
[HTTP_MAX_URI
], /* Username portion of URI */
9191 host
[HTTP_MAX_URI
], /* Host portion of URI */
9192 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9193 int port
; /* Port portion of URI */
9194 cupsd_job_t
*job
; /* Job information */
9197 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9198 con
->http
.fd
, uri
->values
[0].string
.text
);
9201 * See if we have a job URI or a printer URI...
9204 if (!strcmp(uri
->name
, "printer-uri"))
9207 * Got a printer URI; see if we also have a job-id attribute...
9210 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9211 IPP_TAG_INTEGER
)) == NULL
)
9213 send_ipp_status(con
, IPP_BAD_REQUEST
,
9214 _("Got a printer-uri attribute but no job-id!"));
9218 jobid
= attr
->values
[0].integer
;
9223 * Got a job URI; parse it to get the job ID...
9226 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9227 sizeof(scheme
), username
, sizeof(username
), host
,
9228 sizeof(host
), &port
, resource
, sizeof(resource
));
9230 if (strncmp(resource
, "/jobs/", 6))
9236 send_ipp_status(con
, IPP_BAD_REQUEST
,
9237 _("Bad job-uri attribute \"%s\"!"),
9238 uri
->values
[0].string
.text
);
9242 jobid
= atoi(resource
+ 6);
9246 * See if the job exists...
9249 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9252 * Nope - return a "not found" error...
9255 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9260 * See if job is in any of the "completed" states...
9263 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9266 * Nope - return a "not possible" error...
9269 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9275 * See if we have retained the job files...
9280 if (!job
->attrs
|| job
->num_files
== 0)
9283 * Nope - return a "not possible" error...
9286 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9287 _("Job #%d cannot be restarted - no files!"), jobid
);
9292 * See if the job is owned by the requesting user...
9295 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9297 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9302 * Restart the job and return...
9305 cupsdRestartJob(job
);
9307 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9309 con
->response
->request
.status
.status_code
= IPP_OK
;
9314 * 'save_auth_info()' - Save authentication information for a job.
9319 cupsd_client_t
*con
, /* I - Client connection */
9320 cupsd_job_t
*job
, /* I - Job */
9321 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9323 int i
; /* Looping var */
9324 char filename
[1024]; /* Job authentication filename */
9325 cups_file_t
*fp
; /* Job authentication file */
9326 char line
[2048]; /* Line for file */
9327 cupsd_printer_t
*dest
; /* Destination printer/class */
9331 * This function saves the in-memory authentication information for
9332 * a job so that it can be used to authenticate with a remote host.
9333 * The information is stored in a file that is readable only by the
9334 * root user. The fields are Base-64 encoded, each on a separate line,
9335 * followed by random number (up to 1024) of newlines to limit the
9336 * amount of information that is exposed.
9338 * Because of the potential for exposing of authentication information,
9339 * this functionality is only enabled when running cupsd as root.
9341 * This caching only works for the Basic and BasicDigest authentication
9342 * types. Digest authentication cannot be cached this way, and in
9343 * the future Kerberos authentication may make all of this obsolete.
9345 * Authentication information is saved whenever an authenticated
9346 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9349 * This information is deleted after a job is completed or canceled,
9350 * so reprints may require subsequent re-authentication.
9356 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9360 * Create the authentication file and change permissions...
9363 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9364 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9366 cupsdLogMessage(CUPSD_LOG_ERROR
,
9367 "Unable to save authentication info to \"%s\" - %s",
9368 filename
, strerror(errno
));
9372 fchown(cupsFileNumber(fp
), 0, 0);
9373 fchmod(cupsFileNumber(fp
), 0400);
9375 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9378 * Write 1 to 3 auth values...
9381 cupsdClearString(&job
->auth_username
);
9382 cupsdClearString(&job
->auth_domain
);
9383 cupsdClearString(&job
->auth_password
);
9385 for (i
= 0; i
< auth_info
->num_values
; i
++)
9387 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9388 strlen(auth_info
->values
[i
].string
.text
));
9389 cupsFilePrintf(fp
, "%s\n", line
);
9391 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9392 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9393 auth_info
->values
[i
].string
.text
);
9394 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9395 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9396 auth_info
->values
[i
].string
.text
);
9397 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9398 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9399 auth_info
->values
[i
].string
.text
);
9402 else if (con
->username
[0])
9405 * Write the authenticated username...
9408 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9409 cupsFilePrintf(fp
, "%s\n", line
);
9411 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9412 cupsdClearString(&job
->auth_domain
);
9415 * Write the authenticated password...
9418 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9419 cupsFilePrintf(fp
, "%s\n", line
);
9421 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9425 * Write a random number of newlines to the end of the file...
9428 for (i
= (rand() % 1024); i
>= 0; i
--)
9429 cupsFilePutChar(fp
, '\n');
9432 * Close the file and return...
9437 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9438 if (con
->gss_have_creds
)
9439 save_krb5_creds(con
, job
);
9440 else if (job
->ccname
)
9441 cupsdClearString(&(job
->ccname
));
9442 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9446 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9448 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9452 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9453 cupsd_job_t
*job
) /* I - Job */
9455 # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
9456 cupsdLogMessage(CUPSD_LOG_INFO
,
9457 "Sorry, your version of Kerberos does not support delegated "
9462 krb5_error_code error
; /* Kerberos error code */
9463 OM_uint32 major_status
, /* Major status code */
9464 minor_status
; /* Minor status code */
9465 krb5_principal principal
; /* Kerberos principal */
9470 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
9474 if (krb5_init_context
== NULL
)
9476 # endif /* __APPLE__ */
9478 if (!KerberosInitialized
)
9481 * Setup a Kerberos context for the scheduler to use...
9484 KerberosInitialized
= 1;
9486 if (krb5_init_context(&KerberosContext
))
9488 KerberosContext
= NULL
;
9490 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize Kerberos context");
9496 * We MUST create a file-based cache because memory-based caches are
9497 * only valid for the current process/address space.
9499 * Due to various bugs/features in different versions of Kerberos, we
9500 * need either the krb5_cc_new_unique() function or Heimdal's version
9501 * of krb5_cc_gen_new() to create a new FILE: credential cache that
9502 * can be passed to the backend. These functions create a temporary
9503 * file (typically in /tmp) containing the cached credentials, which
9504 * are removed when we have successfully printed a job.
9507 # ifdef HAVE_KRB5_CC_NEW_UNIQUE
9508 if ((error
= krb5_cc_new_unique(KerberosContext
, "FILE", NULL
,
9509 &(job
->ccache
))) != 0)
9510 # else /* HAVE_HEIMDAL */
9511 if ((error
= krb5_cc_gen_new(KerberosContext
, &krb5_fcc_ops
,
9512 &(job
->ccache
))) != 0)
9513 # endif /* HAVE_KRB5_CC_NEW_UNIQUE */
9515 cupsdLogMessage(CUPSD_LOG_ERROR
,
9516 "Unable to create new credentials cache (%d/%s)",
9517 error
, strerror(errno
));
9522 if ((error
= krb5_parse_name(KerberosContext
, con
->username
, &principal
)) != 0)
9524 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to parse kerberos username (%d/%s)",
9525 error
, strerror(errno
));
9526 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9531 if ((error
= krb5_cc_initialize(KerberosContext
, job
->ccache
, principal
)))
9533 cupsdLogMessage(CUPSD_LOG_ERROR
,
9534 "Unable to initialize credentials cache (%d/%s)", error
,
9536 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9537 krb5_free_principal(KerberosContext
, principal
);
9542 krb5_free_principal(KerberosContext
, principal
);
9545 * Copy the user's credentials to the new cache file...
9548 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
9551 if (GSS_ERROR(major_status
))
9553 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
9554 "Unable to import client credentials cache");
9555 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9561 * Add the KRB5CCNAME environment variable to the job so that the
9562 * backend can use the credentials when printing.
9565 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9566 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9568 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9569 # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
9571 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9575 * 'send_document()' - Send a file to a printer or class.
9579 send_document(cupsd_client_t
*con
, /* I - Client connection */
9580 ipp_attribute_t
*uri
) /* I - Printer URI */
9582 ipp_attribute_t
*attr
; /* Current attribute */
9583 ipp_attribute_t
*format
; /* Request's document-format attribute */
9584 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9585 const char *default_format
;/* document-format-default value */
9586 int jobid
; /* Job ID number */
9587 cupsd_job_t
*job
; /* Current job */
9588 char job_uri
[HTTP_MAX_URI
],
9590 scheme
[HTTP_MAX_URI
],
9591 /* Method portion of URI */
9592 username
[HTTP_MAX_URI
],
9593 /* Username portion of URI */
9595 /* Host portion of URI */
9596 resource
[HTTP_MAX_URI
];
9597 /* Resource portion of URI */
9598 int port
; /* Port portion of URI */
9599 mime_type_t
*filetype
; /* Type of file */
9600 char super
[MIME_MAX_SUPER
],
9601 /* Supertype of file */
9602 type
[MIME_MAX_TYPE
],
9603 /* Subtype of file */
9604 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9605 /* Textual name of mime type */
9606 char filename
[1024]; /* Job filename */
9607 cupsd_printer_t
*printer
; /* Current printer */
9608 struct stat fileinfo
; /* File information */
9609 int kbytes
; /* Size of file */
9610 int compression
; /* Type of compression */
9611 int start_job
; /* Start the job? */
9614 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9615 con
->http
.fd
, uri
->values
[0].string
.text
);
9618 * See if we have a job URI or a printer URI...
9621 if (!strcmp(uri
->name
, "printer-uri"))
9624 * Got a printer URI; see if we also have a job-id attribute...
9627 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9628 IPP_TAG_INTEGER
)) == NULL
)
9630 send_ipp_status(con
, IPP_BAD_REQUEST
,
9631 _("Got a printer-uri attribute but no job-id!"));
9635 jobid
= attr
->values
[0].integer
;
9640 * Got a job URI; parse it to get the job ID...
9643 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9644 sizeof(scheme
), username
, sizeof(username
), host
,
9645 sizeof(host
), &port
, resource
, sizeof(resource
));
9647 if (strncmp(resource
, "/jobs/", 6))
9653 send_ipp_status(con
, IPP_BAD_REQUEST
,
9654 _("Bad job-uri attribute \"%s\"!"),
9655 uri
->values
[0].string
.text
);
9659 jobid
= atoi(resource
+ 6);
9663 * See if the job exists...
9666 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9669 * Nope - return a "not found" error...
9672 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9676 printer
= cupsdFindDest(job
->dest
);
9679 * See if the job is owned by the requesting user...
9682 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9684 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9689 * OK, see if the client is sending the document compressed - CUPS
9690 * only supports "none" and "gzip".
9693 compression
= CUPS_FILE_NONE
;
9695 if ((attr
= ippFindAttribute(con
->request
, "compression",
9696 IPP_TAG_KEYWORD
)) != NULL
)
9698 if (strcmp(attr
->values
[0].string
.text
, "none")
9700 && strcmp(attr
->values
[0].string
.text
, "gzip")
9701 #endif /* HAVE_LIBZ */
9704 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9705 attr
->values
[0].string
.text
);
9706 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9707 "compression", NULL
, attr
->values
[0].string
.text
);
9712 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9713 compression
= CUPS_FILE_GZIP
;
9714 #endif /* HAVE_LIBZ */
9718 * Do we have a file to print?
9723 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9728 * Is it a format we support?
9731 if ((format
= ippFindAttribute(con
->request
, "document-format",
9732 IPP_TAG_MIMETYPE
)) != NULL
)
9735 * Grab format from client...
9738 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9741 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9742 format
->values
[0].string
.text
);
9746 else if ((default_format
= cupsGetOption("document-format",
9747 printer
->num_options
,
9748 printer
->options
)) != NULL
)
9751 * Use default document format...
9754 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9756 send_ipp_status(con
, IPP_BAD_REQUEST
,
9757 _("Could not scan type \"%s\"!"),
9765 * No document format attribute? Auto-type it!
9768 strcpy(super
, "application");
9769 strcpy(type
, "octet-stream");
9772 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9775 * Auto-type the file...
9778 ipp_attribute_t
*doc_name
; /* document-name attribute */
9781 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9783 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9784 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9785 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9789 filetype
= mimeType(MimeDatabase
, super
, type
);
9791 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9792 filetype
->super
, filetype
->type
);
9795 filetype
= mimeType(MimeDatabase
, super
, type
);
9800 * Replace the document-format attribute value with the auto-typed or
9804 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9807 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9808 IPP_TAG_MIMETYPE
)) != NULL
)
9810 _cupsStrFree(jformat
->values
[0].string
.text
);
9812 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9815 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9816 "document-format", NULL
, mimetype
);
9820 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9821 _("Unsupported format \'%s/%s\'!"), super
, type
);
9822 cupsdLogMessage(CUPSD_LOG_INFO
,
9823 "Hint: Do you have the raw file printing rules enabled?");
9826 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9827 "document-format", NULL
, format
->values
[0].string
.text
);
9832 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9834 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9837 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9838 _("Unsupported format \'%s\'!"), mimetype
);
9840 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9841 "document-format", NULL
, mimetype
);
9847 * Add the file to the job...
9852 if (add_file(con
, job
, filetype
, compression
))
9855 if (stat(con
->filename
, &fileinfo
))
9858 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9860 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9862 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9863 IPP_TAG_INTEGER
)) != NULL
)
9864 attr
->values
[0].integer
+= kbytes
;
9866 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9868 rename(con
->filename
, filename
);
9870 cupsdClearString(&con
->filename
);
9872 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9873 filetype
->super
, filetype
->type
, job
->username
);
9876 * Start the job if this is the last document...
9879 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9880 IPP_TAG_BOOLEAN
)) != NULL
&&
9881 attr
->values
[0].boolean
)
9884 * See if we need to add the ending sheet...
9887 if (cupsdTimeoutJob(job
))
9890 if (job
->state_value
== IPP_JOB_STOPPED
)
9892 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9893 job
->state_value
= IPP_JOB_PENDING
;
9895 else if (job
->state_value
== IPP_JOB_HELD
)
9897 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9898 IPP_TAG_KEYWORD
)) == NULL
)
9899 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9901 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9903 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9904 job
->state_value
= IPP_JOB_PENDING
;
9909 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9915 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9916 IPP_TAG_KEYWORD
)) == NULL
)
9917 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9919 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9921 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9922 job
->state_value
= IPP_JOB_HELD
;
9923 job
->hold_until
= time(NULL
) + 60;
9926 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9933 * Fill in the response info...
9936 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
9939 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9942 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9944 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9946 add_job_state_reasons(con
, job
);
9948 con
->response
->request
.status
.status_code
= IPP_OK
;
9951 * Start the job if necessary...
9960 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9965 cupsd_client_t
*con
, /* I - Client connection */
9966 http_status_t status
, /* I - HTTP status code */
9967 cupsd_printer_t
*printer
) /* I - Printer, if any */
9969 ipp_attribute_t
*uri
; /* Request URI, if any */
9972 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9973 IPP_TAG_URI
)) == NULL
)
9974 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9976 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9977 "Returning HTTP %s for %s (%s) from %s",
9979 ippOpString(con
->request
->request
.op
.operation_id
),
9980 uri
? uri
->values
[0].string
.text
: "no URI",
9981 con
->http
.hostname
);
9985 int auth_type
; /* Type of authentication required */
9988 auth_type
= CUPSD_AUTH_NONE
;
9990 if (status
== HTTP_UNAUTHORIZED
&&
9991 printer
->num_auth_info_required
> 0 &&
9992 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9994 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9995 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9996 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9999 * Creating and authenticating jobs requires Kerberos...
10002 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10007 * Use policy/location-defined authentication requirements...
10010 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10011 cupsd_location_t
*auth
; /* Pointer to authentication element */
10014 if (printer
->type
& CUPS_PRINTER_CLASS
)
10015 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10017 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10019 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10020 auth
->type
== CUPSD_AUTH_NONE
)
10021 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10023 con
->request
->request
.op
.operation_id
:
10028 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10029 auth_type
= DefaultAuthType
;
10031 auth_type
= auth
->type
;
10035 cupsdSendError(con
, status
, auth_type
);
10038 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10040 ippDelete(con
->response
);
10041 con
->response
= NULL
;
10048 * 'send_ipp_status()' - Send a status back to the IPP client.
10052 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10053 ipp_status_t status
, /* I - IPP status code */
10054 const char *message
,/* I - Status message */
10055 ...) /* I - Additional args as needed */
10057 va_list ap
; /* Pointer to additional args */
10058 char formatted
[1024]; /* Formatted errror message */
10061 va_start(ap
, message
);
10062 vsnprintf(formatted
, sizeof(formatted
),
10063 _cupsLangString(con
->language
, message
), ap
);
10066 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10067 ippOpString(con
->request
->request
.op
.operation_id
),
10068 ippErrorString(status
), formatted
);
10070 con
->response
->request
.status
.status_code
= status
;
10072 if (ippFindAttribute(con
->response
, "attributes-charset",
10073 IPP_TAG_ZERO
) == NULL
)
10074 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10075 "attributes-charset", NULL
, DefaultCharset
);
10077 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10078 IPP_TAG_ZERO
) == NULL
)
10079 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10080 "attributes-natural-language", NULL
, DefaultLanguage
);
10082 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10083 "status-message", NULL
, formatted
);
10088 * 'set_default()' - Set the default destination...
10092 set_default(cupsd_client_t
*con
, /* I - Client connection */
10093 ipp_attribute_t
*uri
) /* I - Printer URI */
10095 http_status_t status
; /* Policy status */
10096 cups_ptype_t dtype
; /* Destination type (printer/class) */
10097 cupsd_printer_t
*printer
, /* Printer */
10098 *oldprinter
; /* Old default printer */
10101 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10102 con
->http
.fd
, uri
->values
[0].string
.text
);
10105 * Is the destination valid?
10108 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10114 send_ipp_status(con
, IPP_NOT_FOUND
,
10115 _("The printer or class was not found."));
10123 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10125 send_http_error(con
, status
, NULL
);
10130 * Set it as the default...
10133 oldprinter
= DefaultPrinter
;
10134 DefaultPrinter
= printer
;
10137 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10138 "%s is no longer the default printer.", oldprinter
->name
);
10140 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10141 "%s is now the default printer.", printer
->name
);
10143 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10144 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
10146 cupsdLogMessage(CUPSD_LOG_INFO
,
10147 "Default destination set to \"%s\" by \"%s\".",
10148 printer
->name
, get_username(con
));
10151 * Everything was ok, so return OK status...
10154 con
->response
->request
.status
.status_code
= IPP_OK
;
10159 * 'set_job_attrs()' - Set job attributes.
10163 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10164 ipp_attribute_t
*uri
) /* I - Job URI */
10166 ipp_attribute_t
*attr
, /* Current attribute */
10167 *attr2
; /* Job attribute */
10168 int jobid
; /* Job ID */
10169 cupsd_job_t
*job
; /* Current job */
10170 char scheme
[HTTP_MAX_URI
],
10171 /* Method portion of URI */
10172 username
[HTTP_MAX_URI
],
10173 /* Username portion of URI */
10174 host
[HTTP_MAX_URI
],
10175 /* Host portion of URI */
10176 resource
[HTTP_MAX_URI
];
10177 /* Resource portion of URI */
10178 int port
; /* Port portion of URI */
10179 int event
; /* Events? */
10180 int check_jobs
; /* Check jobs? */
10183 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10184 con
->http
.fd
, uri
->values
[0].string
.text
);
10187 * Start with "everything is OK" status...
10190 con
->response
->request
.status
.status_code
= IPP_OK
;
10193 * See if we have a job URI or a printer URI...
10196 if (!strcmp(uri
->name
, "printer-uri"))
10199 * Got a printer URI; see if we also have a job-id attribute...
10202 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10203 IPP_TAG_INTEGER
)) == NULL
)
10205 send_ipp_status(con
, IPP_BAD_REQUEST
,
10206 _("Got a printer-uri attribute but no job-id!"));
10210 jobid
= attr
->values
[0].integer
;
10215 * Got a job URI; parse it to get the job ID...
10218 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10219 sizeof(scheme
), username
, sizeof(username
), host
,
10220 sizeof(host
), &port
, resource
, sizeof(resource
));
10222 if (strncmp(resource
, "/jobs/", 6))
10228 send_ipp_status(con
, IPP_BAD_REQUEST
,
10229 _("Bad job-uri attribute \"%s\"!"),
10230 uri
->values
[0].string
.text
);
10234 jobid
= atoi(resource
+ 6);
10238 * See if the job exists...
10241 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10244 * Nope - return a "not found" error...
10247 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10252 * See if the job has been completed...
10255 if (job
->state_value
> IPP_JOB_STOPPED
)
10258 * Return a "not-possible" error...
10261 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10262 _("Job #%d is finished and cannot be altered!"), jobid
);
10267 * See if the job is owned by the requesting user...
10270 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10272 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
10277 * See what the user wants to change.
10285 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10287 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10290 if (!strcmp(attr
->name
, "attributes-charset") ||
10291 !strcmp(attr
->name
, "attributes-natural-language") ||
10292 !strcmp(attr
->name
, "document-compression") ||
10293 !strcmp(attr
->name
, "document-format") ||
10294 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10295 !strcmp(attr
->name
, "job-document-access-errors") ||
10296 !strcmp(attr
->name
, "job-id") ||
10297 !strcmp(attr
->name
, "job-impressions-completed") ||
10298 !strcmp(attr
->name
, "job-k-octets") ||
10299 !strcmp(attr
->name
, "job-originating-host-name") ||
10300 !strcmp(attr
->name
, "job-originating-user-name") ||
10301 !strcmp(attr
->name
, "job-printer-up-time") ||
10302 !strcmp(attr
->name
, "job-printer-uri") ||
10303 !strcmp(attr
->name
, "job-sheets") ||
10304 !strcmp(attr
->name
, "job-state-message") ||
10305 !strcmp(attr
->name
, "job-state-reasons") ||
10306 !strcmp(attr
->name
, "job-uri") ||
10307 !strcmp(attr
->name
, "number-of-documents") ||
10308 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10309 !strcmp(attr
->name
, "output-device-assigned") ||
10310 !strncmp(attr
->name
, "date-time-at-", 13) ||
10311 !strncmp(attr
->name
, "job-k-octets", 12) ||
10312 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10313 !strncmp(attr
->name
, "time-at-", 8))
10319 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10320 _("%s cannot be changed."), attr
->name
);
10322 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10323 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10328 if (!strcmp(attr
->name
, "job-priority"))
10331 * Change the job priority...
10334 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10336 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10338 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10339 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10341 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10343 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10344 _("Job is completed and cannot be changed."));
10347 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10349 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10350 attr
->values
[0].integer
);
10351 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10354 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10355 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10358 else if (!strcmp(attr
->name
, "job-state"))
10361 * Change the job state...
10364 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10366 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10368 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10369 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10373 switch (attr
->values
[0].integer
)
10375 case IPP_JOB_PENDING
:
10376 case IPP_JOB_HELD
:
10377 if (job
->state_value
> IPP_JOB_HELD
)
10379 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10380 _("Job state cannot be changed."));
10383 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10385 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10386 attr
->values
[0].integer
);
10388 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
10389 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
10391 event
|= CUPSD_EVENT_JOB_STATE
;
10396 case IPP_JOB_PROCESSING
:
10397 case IPP_JOB_STOPPED
:
10398 if (job
->state_value
!= attr
->values
[0].integer
)
10400 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10401 _("Job state cannot be changed."));
10406 case IPP_JOB_CANCELED
:
10407 case IPP_JOB_ABORTED
:
10408 case IPP_JOB_COMPLETED
:
10409 if (job
->state_value
> IPP_JOB_PROCESSING
)
10411 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10412 _("Job state cannot be changed."));
10415 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10417 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10418 attr
->values
[0].integer
);
10419 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
10427 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10429 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10430 IPP_TAG_ZERO
)) != NULL
)
10433 * Some other value; first free the old value...
10436 if (job
->attrs
->prev
)
10437 job
->attrs
->prev
->next
= attr2
->next
;
10439 job
->attrs
->attrs
= attr2
->next
;
10441 if (job
->attrs
->last
== attr2
)
10442 job
->attrs
->last
= job
->attrs
->prev
;
10444 _ippFreeAttr(attr2
);
10447 * Then copy the attribute...
10450 copy_attribute(job
->attrs
, attr
, 0);
10453 * See if the job-name or job-hold-until is being changed.
10456 if (!strcmp(attr
->name
, "job-hold-until"))
10458 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10459 attr
->values
[0].string
.text
);
10460 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
10462 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10463 cupsdReleaseJob(job
);
10468 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10471 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10474 * Delete the attribute...
10477 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10478 IPP_TAG_ZERO
)) != NULL
)
10480 if (job
->attrs
->prev
)
10481 job
->attrs
->prev
->next
= attr2
->next
;
10483 job
->attrs
->attrs
= attr2
->next
;
10485 if (attr2
== job
->attrs
->last
)
10486 job
->attrs
->last
= job
->attrs
->prev
;
10488 _ippFreeAttr(attr2
);
10490 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10496 * Add new option by copying it...
10499 copy_attribute(job
->attrs
, attr
, 0);
10501 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10510 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10513 * Send events as needed...
10516 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10517 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10518 cupsdFindDest(job
->dest
), job
,
10519 "Job priority changed by user.");
10521 if (event
& CUPSD_EVENT_JOB_STATE
)
10522 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10523 job
->state_value
== IPP_JOB_HELD
?
10524 "Job held by user." : "Job restarted by user.");
10526 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10527 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10528 "Job options changed by user.");
10531 * Start jobs if possible...
10540 * 'set_printer_defaults()' - Set printer default options from a request.
10544 set_printer_defaults(
10545 cupsd_client_t
*con
, /* I - Client connection */
10546 cupsd_printer_t
*printer
) /* I - Printer */
10548 int i
; /* Looping var */
10549 ipp_attribute_t
*attr
; /* Current attribute */
10550 int namelen
; /* Length of attribute name */
10551 char name
[256], /* New attribute name */
10552 value
[256]; /* String version of integer attrs */
10555 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10558 * Skip non-printer attributes...
10561 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10564 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10566 if (!strcmp(attr
->name
, "job-sheets-default"))
10569 * Only allow keywords and names...
10572 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10576 * Only allow job-sheets-default to be set when running without a
10577 * system high classification level...
10580 if (Classification
)
10583 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10585 if (attr
->num_values
> 1)
10586 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10588 cupsdSetString(&printer
->job_sheets
[1], "none");
10590 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10592 cupsdFreePrinterUsers(printer
);
10594 printer
->deny_users
= 0;
10596 if (attr
->value_tag
== IPP_TAG_NAME
&&
10597 (attr
->num_values
> 1 ||
10598 strcmp(attr
->values
[0].string
.text
, "all")))
10600 for (i
= 0; i
< attr
->num_values
; i
++)
10601 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10604 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10606 cupsdFreePrinterUsers(printer
);
10608 printer
->deny_users
= 1;
10610 if (attr
->value_tag
== IPP_TAG_NAME
&&
10611 (attr
->num_values
> 1 ||
10612 strcmp(attr
->values
[0].string
.text
, "none")))
10614 for (i
= 0; i
< attr
->num_values
; i
++)
10615 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10618 else if (!strcmp(attr
->name
, "job-quota-period"))
10620 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10623 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10624 attr
->values
[0].integer
);
10625 cupsdFreeQuotas(printer
);
10627 printer
->quota_period
= attr
->values
[0].integer
;
10629 else if (!strcmp(attr
->name
, "job-k-limit"))
10631 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10634 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10635 attr
->values
[0].integer
);
10636 cupsdFreeQuotas(printer
);
10638 printer
->k_limit
= attr
->values
[0].integer
;
10640 else if (!strcmp(attr
->name
, "job-page-limit"))
10642 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10645 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10646 attr
->values
[0].integer
);
10647 cupsdFreeQuotas(printer
);
10649 printer
->page_limit
= attr
->values
[0].integer
;
10651 else if (!strcmp(attr
->name
, "printer-op-policy"))
10653 cupsd_policy_t
*p
; /* Policy */
10656 if (attr
->value_tag
!= IPP_TAG_NAME
)
10659 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10661 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10662 "Setting printer-op-policy to \"%s\"...",
10663 attr
->values
[0].string
.text
);
10664 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10665 printer
->op_policy_ptr
= p
;
10669 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10670 _("Unknown printer-op-policy \"%s\"."),
10671 attr
->values
[0].string
.text
);
10675 else if (!strcmp(attr
->name
, "printer-error-policy"))
10677 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10680 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10681 strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10682 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10683 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
10685 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10686 _("Unknown printer-error-policy \"%s\"."),
10687 attr
->values
[0].string
.text
);
10691 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10692 "Setting printer-error-policy to \"%s\"...",
10693 attr
->values
[0].string
.text
);
10694 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10698 * Skip any other non-default attributes...
10701 namelen
= strlen(attr
->name
);
10702 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10703 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10707 * OK, anything else must be a user-defined default...
10710 strlcpy(name
, attr
->name
, sizeof(name
));
10711 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10713 switch (attr
->value_tag
)
10715 case IPP_TAG_DELETEATTR
:
10716 printer
->num_options
= cupsRemoveOption(name
,
10717 printer
->num_options
,
10718 &(printer
->options
));
10719 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10720 "Deleting %s", attr
->name
);
10723 case IPP_TAG_NAME
:
10724 case IPP_TAG_KEYWORD
:
10726 printer
->num_options
= cupsAddOption(name
,
10727 attr
->values
[0].string
.text
,
10728 printer
->num_options
,
10729 &(printer
->options
));
10730 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10731 "Setting %s to \"%s\"...", attr
->name
,
10732 attr
->values
[0].string
.text
);
10735 case IPP_TAG_BOOLEAN
:
10736 printer
->num_options
= cupsAddOption(name
,
10737 attr
->values
[0].boolean
?
10739 printer
->num_options
,
10740 &(printer
->options
));
10741 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10742 "Setting %s to %s...", attr
->name
,
10743 attr
->values
[0].boolean
? "true" : "false");
10746 case IPP_TAG_INTEGER
:
10747 case IPP_TAG_ENUM
:
10748 sprintf(value
, "%d", attr
->values
[0].integer
);
10749 printer
->num_options
= cupsAddOption(name
, value
,
10750 printer
->num_options
,
10751 &(printer
->options
));
10752 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10753 "Setting %s to %s...", attr
->name
, value
);
10756 case IPP_TAG_RANGE
:
10757 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10758 attr
->values
[0].range
.upper
);
10759 printer
->num_options
= cupsAddOption(name
, value
,
10760 printer
->num_options
,
10761 &(printer
->options
));
10762 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10763 "Setting %s to %s...", attr
->name
, value
);
10766 case IPP_TAG_RESOLUTION
:
10767 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10768 attr
->values
[0].resolution
.yres
,
10769 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10771 printer
->num_options
= cupsAddOption(name
, value
,
10772 printer
->num_options
,
10773 &(printer
->options
));
10774 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10775 "Setting %s to %s...", attr
->name
, value
);
10779 /* Do nothing for other values */
10787 * 'start_printer()' - Start a printer.
10791 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10792 ipp_attribute_t
*uri
) /* I - Printer URI */
10794 http_status_t status
; /* Policy status */
10795 cups_ptype_t dtype
; /* Destination type (printer/class) */
10796 cupsd_printer_t
*printer
; /* Printer data */
10799 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10800 con
->http
.fd
, uri
->values
[0].string
.text
);
10803 * Is the destination valid?
10806 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10812 send_ipp_status(con
, IPP_NOT_FOUND
,
10813 _("The printer or class was not found."));
10821 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10823 send_http_error(con
, status
, printer
);
10828 * Start the printer...
10831 printer
->state_message
[0] = '\0';
10833 cupsdStartPrinter(printer
, 1);
10835 if (dtype
& CUPS_PRINTER_CLASS
)
10836 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10837 printer
->name
, get_username(con
));
10839 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10840 printer
->name
, get_username(con
));
10845 * Everything was ok, so return OK status...
10848 con
->response
->request
.status
.status_code
= IPP_OK
;
10853 * 'stop_printer()' - Stop a printer.
10857 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10858 ipp_attribute_t
*uri
) /* I - Printer URI */
10860 http_status_t status
; /* Policy status */
10861 cups_ptype_t dtype
; /* Destination type (printer/class) */
10862 cupsd_printer_t
*printer
; /* Printer data */
10863 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10866 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10867 con
->http
.fd
, uri
->values
[0].string
.text
);
10870 * Is the destination valid?
10873 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10879 send_ipp_status(con
, IPP_NOT_FOUND
,
10880 _("The printer or class was not found."));
10888 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10890 send_http_error(con
, status
, printer
);
10895 * Stop the printer...
10898 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10899 IPP_TAG_TEXT
)) == NULL
)
10900 strcpy(printer
->state_message
, "Paused");
10903 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10904 sizeof(printer
->state_message
));
10907 cupsdStopPrinter(printer
, 1);
10909 if (dtype
& CUPS_PRINTER_CLASS
)
10910 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10911 printer
->name
, get_username(con
));
10913 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10914 printer
->name
, get_username(con
));
10917 * Everything was ok, so return OK status...
10920 con
->response
->request
.status
.status_code
= IPP_OK
;
10925 * 'url_encode_attr()' - URL-encode a string attribute.
10929 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10930 char *buffer
,/* I - String buffer */
10931 int bufsize
)/* I - Size of buffer */
10933 int i
; /* Looping var */
10934 char *bufptr
, /* Pointer into buffer */
10935 *bufend
; /* End of buffer */
10938 strlcpy(buffer
, attr
->name
, bufsize
);
10939 bufptr
= buffer
+ strlen(buffer
);
10940 bufend
= buffer
+ bufsize
- 1;
10942 for (i
= 0; i
< attr
->num_values
; i
++)
10944 if (bufptr
>= bufend
)
10952 if (bufptr
>= bufend
)
10957 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10958 bufptr
, bufend
- bufptr
+ 1);
10960 if (bufptr
>= bufend
)
10971 * 'url_encode_string()' - URL-encode a string.
10974 static char * /* O - End of string */
10975 url_encode_string(const char *s
, /* I - String */
10976 char *buffer
, /* I - String buffer */
10977 int bufsize
) /* I - Size of buffer */
10979 char *bufptr
, /* Pointer into buffer */
10980 *bufend
; /* End of buffer */
10981 static const char *hex
= "0123456789ABCDEF";
10986 bufend
= buffer
+ bufsize
- 1;
10988 while (*s
&& bufptr
< bufend
)
10990 if (*s
== ' ' || *s
== '%')
10992 if (bufptr
>= (bufend
- 2))
10996 *bufptr
++ = hex
[(*s
>> 4) & 15];
10997 *bufptr
++ = hex
[*s
& 15];
11001 else if (*s
== '\'' || *s
== '\\')
11003 if (bufptr
>= (bufend
- 1))
11020 * 'user_allowed()' - See if a user is allowed to print to a queue.
11023 static int /* O - 0 if not allowed, 1 if allowed */
11024 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11025 const char *username
) /* I - Username */
11027 int i
; /* Looping var */
11028 struct passwd
*pw
; /* User password data */
11029 char baseuser
[256], /* Base username */
11030 *baseptr
; /* Pointer to "@" in base username */
11033 if (p
->num_users
== 0)
11036 if (!strcmp(username
, "root"))
11039 if (strchr(username
, '@'))
11042 * Strip @REALM for username check...
11045 strlcpy(baseuser
, username
, sizeof(baseuser
));
11047 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11050 username
= baseuser
;
11053 pw
= getpwnam(username
);
11056 for (i
= 0; i
< p
->num_users
; i
++)
11058 if (p
->users
[i
][0] == '@')
11061 * Check group membership...
11064 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
11067 else if (p
->users
[i
][0] == '#')
11073 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
11076 else if (!strcasecmp(username
, p
->users
[i
]))
11080 return ((i
< p
->num_users
) != p
->deny_users
);
11085 * 'validate_job()' - Validate printer options and destination.
11089 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11090 ipp_attribute_t
*uri
) /* I - Printer URI */
11092 http_status_t status
; /* Policy status */
11093 ipp_attribute_t
*attr
; /* Current attribute */
11094 ipp_attribute_t
*format
; /* Document-format attribute */
11095 cups_ptype_t dtype
; /* Destination type (printer/class) */
11096 char super
[MIME_MAX_SUPER
],
11097 /* Supertype of file */
11098 type
[MIME_MAX_TYPE
];
11099 /* Subtype of file */
11100 cupsd_printer_t
*printer
; /* Printer */
11103 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11104 con
->http
.fd
, uri
->values
[0].string
.text
);
11107 * OK, see if the client is sending the document compressed - CUPS
11108 * doesn't support compression yet...
11111 if ((attr
= ippFindAttribute(con
->request
, "compression",
11112 IPP_TAG_KEYWORD
)) != NULL
&&
11113 !strcmp(attr
->values
[0].string
.text
, "none"))
11115 send_ipp_status(con
, IPP_ATTRIBUTES
,
11116 _("Unsupported compression attribute %s!"),
11117 attr
->values
[0].string
.text
);
11118 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11119 "compression", NULL
, attr
->values
[0].string
.text
);
11124 * Is it a format we support?
11127 if ((format
= ippFindAttribute(con
->request
, "document-format",
11128 IPP_TAG_MIMETYPE
)) != NULL
)
11130 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
11133 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
11134 format
->values
[0].string
.text
);
11138 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11139 !mimeType(MimeDatabase
, super
, type
))
11141 cupsdLogMessage(CUPSD_LOG_INFO
,
11142 "Hint: Do you have the raw file printing rules enabled?");
11143 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11144 _("Unsupported format \"%s\"!"),
11145 format
->values
[0].string
.text
);
11146 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11147 "document-format", NULL
, format
->values
[0].string
.text
);
11153 * Is the destination valid?
11156 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11162 send_ipp_status(con
, IPP_NOT_FOUND
,
11163 _("The printer or class was not found."));
11171 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11173 send_http_error(con
, status
, printer
);
11178 * Everything was ok, so return OK status...
11181 con
->response
->request
.status
.status_code
= IPP_OK
;
11186 * 'validate_name()' - Make sure the printer name only contains valid chars.
11189 static int /* O - 0 if name is no good, 1 if good */
11190 validate_name(const char *name
) /* I - Name to check */
11192 const char *ptr
; /* Pointer into name */
11196 * Scan the whole name...
11199 for (ptr
= name
; *ptr
; ptr
++)
11200 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11204 * All the characters are good; validate the length, too...
11207 return ((ptr
- name
) < 128);
11212 * 'validate_user()' - Validate the user for the request.
11215 static int /* O - 1 if permitted, 0 otherwise */
11216 validate_user(cupsd_job_t
*job
, /* I - Job */
11217 cupsd_client_t
*con
, /* I - Client connection */
11218 const char *owner
, /* I - Owner of job/resource */
11219 char *username
, /* O - Authenticated username */
11220 int userlen
) /* I - Length of username */
11222 cupsd_printer_t
*printer
; /* Printer for job */
11225 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11226 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11228 job
->id
, con
? con
->http
.fd
: 0,
11229 owner
? owner
: "(null)", username
, userlen
);
11232 * Validate input...
11235 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11239 * Get the best authenticated username that is available.
11242 strlcpy(username
, get_username(con
), userlen
);
11245 * Check the username against the owner...
11248 printer
= cupsdFindDest(job
->dest
);
11250 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11251 con
, owner
) == HTTP_OK
);
11256 * End of "$Id: ipp.c 7944 2008-09-16 22:32:42Z mike $".