2 * "$Id: ipp.c 7682 2008-06-21 00:06:02Z 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 subcriptions 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_ps_job_ticket() - Reads a job ticket embedded in a PS 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 move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static int ppd_parse_line(const char *line
, char *option
, int olen
,
202 char *choice
, int clen
);
203 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
204 static void read_ps_job_ticket(cupsd_client_t
*con
);
205 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
206 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
207 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
208 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
209 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
210 ipp_attribute_t
*auth_info
);
211 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
212 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
213 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
214 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
215 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
216 cupsd_printer_t
*printer
);
217 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
218 const char *message
, ...)
220 __attribute__ ((__format__ (__printf__
, 3, 4)))
221 # endif /* __GNUC__ */
223 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
224 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
225 static void set_printer_defaults(cupsd_client_t
*con
,
226 cupsd_printer_t
*printer
);
227 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
228 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
229 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
231 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
232 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
233 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
234 static int validate_name(const char *name
);
235 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
236 const char *owner
, char *username
,
241 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
244 int /* O - 1 on success, 0 on failure */
245 cupsdProcessIPPRequest(
246 cupsd_client_t
*con
) /* I - Client connection */
248 ipp_tag_t group
; /* Current group tag */
249 ipp_attribute_t
*attr
; /* Current attribute */
250 ipp_attribute_t
*charset
; /* Character set attribute */
251 ipp_attribute_t
*language
; /* Language attribute */
252 ipp_attribute_t
*uri
; /* Printer URI attribute */
253 ipp_attribute_t
*username
; /* requesting-user-name attr */
254 int sub_id
; /* Subscription ID */
257 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
258 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
259 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
262 * First build an empty response message for this request...
265 con
->response
= ippNew();
267 con
->response
->request
.status
.version
[0] =
268 con
->request
->request
.op
.version
[0];
269 con
->response
->request
.status
.version
[1] =
270 con
->request
->request
.op
.version
[1];
271 con
->response
->request
.status
.request_id
=
272 con
->request
->request
.op
.request_id
;
275 * Then validate the request header and required attributes...
278 if (con
->request
->request
.any
.version
[0] != 1)
281 * Return an error, since we only support IPP 1.x.
284 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
285 "%04X %s Bad request version number %d.%d",
286 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
287 con
->request
->request
.any
.version
[0],
288 con
->request
->request
.any
.version
[1]);
290 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
291 _("Bad request version number %d.%d!"),
292 con
->request
->request
.any
.version
[0],
293 con
->request
->request
.any
.version
[1]);
295 else if (!con
->request
->attrs
)
297 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
298 "%04X %s No attributes in request",
299 IPP_BAD_REQUEST
, con
->http
.hostname
);
301 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
306 * Make sure that the attributes are provided in the correct order and
307 * don't repeat groups...
310 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
313 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
316 * Out of order; return an error...
319 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
320 "%04X %s Attribute groups are out of order",
321 IPP_BAD_REQUEST
, con
->http
.hostname
);
323 send_ipp_status(con
, IPP_BAD_REQUEST
,
324 _("Attribute groups are out of order (%x < %x)!"),
325 attr
->group_tag
, group
);
329 group
= attr
->group_tag
;
334 * Then make sure that the first three attributes are:
337 * attributes-natural-language
338 * printer-uri/job-uri
341 attr
= con
->request
->attrs
;
342 if (attr
&& !strcmp(attr
->name
, "attributes-charset") &&
343 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
351 if (attr
&& !strcmp(attr
->name
, "attributes-natural-language") &&
352 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
357 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
358 IPP_TAG_URI
)) != NULL
)
360 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
361 IPP_TAG_URI
)) != NULL
)
363 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
364 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
369 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
370 "attributes-charset", NULL
,
371 charset
->values
[0].string
.text
);
373 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
374 "attributes-charset", NULL
, DefaultCharset
);
377 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
378 "attributes-natural-language", NULL
,
379 language
->values
[0].string
.text
);
381 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
382 "attributes-natural-language", NULL
, DefaultLanguage
);
385 strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
386 strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
389 * Bad character set...
392 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"!",
393 charset
->values
[0].string
.text
);
394 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
395 "%04X %s Unsupported attributes-charset value \"%s\"",
396 IPP_CHARSET
, con
->http
.hostname
,
397 charset
->values
[0].string
.text
);
398 send_ipp_status(con
, IPP_BAD_REQUEST
,
399 _("Unsupported character set \"%s\"!"),
400 charset
->values
[0].string
.text
);
402 else if (!charset
|| !language
||
404 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
405 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
406 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
407 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
408 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
411 * Return an error, since attributes-charset,
412 * attributes-natural-language, and printer-uri/job-uri are required
413 * for all operations.
418 cupsdLogMessage(CUPSD_LOG_ERROR
,
419 "Missing attributes-charset attribute!");
421 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
422 "%04X %s Missing attributes-charset attribute",
423 IPP_BAD_REQUEST
, con
->http
.hostname
);
428 cupsdLogMessage(CUPSD_LOG_ERROR
,
429 "Missing attributes-natural-language attribute!");
431 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
432 "%04X %s Missing attributes-natural-language attribute",
433 IPP_BAD_REQUEST
, con
->http
.hostname
);
438 cupsdLogMessage(CUPSD_LOG_ERROR
,
439 "Missing printer-uri, job-uri, or ppd-name "
442 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
443 "%04X %s Missing printer-uri, job-uri, or ppd-name "
444 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
447 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
449 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
450 cupsdLogMessage(CUPSD_LOG_DEBUG
,
451 "attr \"%s\": group_tag = %x, value_tag = %x",
452 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
455 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
457 send_ipp_status(con
, IPP_BAD_REQUEST
,
458 _("Missing required attributes!"));
463 * OK, all the checks pass so far; make sure requesting-user-name is
464 * not "root" from a remote host...
467 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
468 IPP_TAG_NAME
)) != NULL
)
471 * Check for root user...
474 if (!strcmp(username
->values
[0].string
.text
, "root") &&
475 strcasecmp(con
->http
.hostname
, "localhost") &&
476 strcmp(con
->username
, "root"))
479 * Remote unauthenticated user masquerading as local root...
482 _cupsStrFree(username
->values
[0].string
.text
);
483 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
487 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
488 IPP_TAG_INTEGER
)) != NULL
)
489 sub_id
= attr
->values
[0].integer
;
494 * Then try processing the operation...
498 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
499 ippOpString(con
->request
->request
.op
.operation_id
),
500 uri
->values
[0].string
.text
);
502 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
503 ippOpString(con
->request
->request
.op
.operation_id
));
505 switch (con
->request
->request
.op
.operation_id
)
511 case IPP_VALIDATE_JOB
:
512 validate_job(con
, uri
);
515 case IPP_CREATE_JOB
:
516 create_job(con
, uri
);
519 case IPP_SEND_DOCUMENT
:
520 send_document(con
, uri
);
523 case IPP_CANCEL_JOB
:
524 cancel_job(con
, uri
);
527 case IPP_GET_JOB_ATTRIBUTES
:
528 get_job_attrs(con
, uri
);
535 case IPP_GET_PRINTER_ATTRIBUTES
:
536 get_printer_attrs(con
, uri
);
543 case IPP_RELEASE_JOB
:
544 release_job(con
, uri
);
547 case IPP_RESTART_JOB
:
548 restart_job(con
, uri
);
551 case IPP_PAUSE_PRINTER
:
552 stop_printer(con
, uri
);
555 case IPP_RESUME_PRINTER
:
556 start_printer(con
, uri
);
559 case IPP_PURGE_JOBS
:
560 cancel_all_jobs(con
, uri
);
563 case IPP_SET_JOB_ATTRIBUTES
:
564 set_job_attrs(con
, uri
);
567 case CUPS_GET_DEFAULT
:
571 case CUPS_GET_PRINTERS
:
572 get_printers(con
, 0);
575 case CUPS_GET_CLASSES
:
576 get_printers(con
, CUPS_PRINTER_CLASS
);
579 case CUPS_ADD_PRINTER
:
580 add_printer(con
, uri
);
583 case CUPS_DELETE_PRINTER
:
584 delete_printer(con
, uri
);
587 case CUPS_ADD_CLASS
:
591 case CUPS_DELETE_CLASS
:
592 delete_printer(con
, uri
);
595 case CUPS_ACCEPT_JOBS
:
596 case IPP_ENABLE_PRINTER
:
597 accept_jobs(con
, uri
);
600 case CUPS_REJECT_JOBS
:
601 case IPP_DISABLE_PRINTER
:
602 reject_jobs(con
, uri
);
605 case CUPS_SET_DEFAULT
:
606 set_default(con
, uri
);
609 case CUPS_GET_DEVICES
:
613 case CUPS_GET_DOCUMENT
:
614 get_document(con
, uri
);
629 case CUPS_AUTHENTICATE_JOB
:
630 authenticate_job(con
, uri
);
633 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
634 case IPP_CREATE_JOB_SUBSCRIPTION
:
635 create_subscription(con
, uri
);
638 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
639 get_subscription_attrs(con
, sub_id
);
642 case IPP_GET_SUBSCRIPTIONS
:
643 get_subscriptions(con
, uri
);
646 case IPP_RENEW_SUBSCRIPTION
:
647 renew_subscription(con
, sub_id
);
650 case IPP_CANCEL_SUBSCRIPTION
:
651 cancel_subscription(con
, sub_id
);
654 case IPP_GET_NOTIFICATIONS
:
655 get_notifications(con
);
659 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
660 "%04X %s Operation %04X (%s) not supported",
661 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
662 con
->request
->request
.op
.operation_id
,
663 ippOpString(con
->request
->request
.op
.operation_id
));
665 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
666 _("%s not supported!"),
668 con
->request
->request
.op
.operation_id
));
678 * Sending data from the scheduler...
681 cupsdLogMessage(CUPSD_LOG_DEBUG
,
682 "cupsdProcessIPPRequest: %d status_code=%x (%s)",
683 con
->http
.fd
, con
->response
->request
.status
.status_code
,
684 ippErrorString(con
->response
->request
.status
.status_code
));
686 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
688 #ifdef CUPSD_USE_CHUNKING
690 * Because older versions of CUPS (1.1.17 and older) and some IPP
691 * clients do not implement chunking properly, we cannot use
692 * chunking by default. This may become the default in future
693 * CUPS releases, or we might add a configuration directive for
697 if (con
->http
.version
== HTTP_1_1
)
699 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
702 if (cupsdFlushHeader(con
) < 0)
705 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
708 #endif /* CUPSD_USE_CHUNKING */
710 size_t length
; /* Length of response */
713 length
= ippLength(con
->response
);
715 if (con
->file
>= 0 && !con
->pipe_pid
)
717 struct stat fileinfo
; /* File information */
720 if (!fstat(con
->file
, &fileinfo
))
721 length
+= fileinfo
.st_size
;
724 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
725 CUPS_LLCAST length
) < 0)
728 if (cupsdFlushHeader(con
) < 0)
731 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
732 con
->http
.data_remaining
= length
;
734 if (con
->http
.data_remaining
<= INT_MAX
)
735 con
->http
._data_remaining
= con
->http
.data_remaining
;
737 con
->http
._data_remaining
= INT_MAX
;
740 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
741 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
744 * Tell the caller the response header was sent successfully...
752 * Tell the caller the response header could not be sent...
761 * Sending data from a subprocess like cups-deviced; tell the caller
762 * everything is A-OK so far...
771 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
774 int /* O - 0 on success, -1 on error */
775 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
777 cupsd_printer_t
*printer
; /* Destination printer or class */
778 ipp_attribute_t
*attr
; /* job-sheets attribute */
779 int kbytes
; /* Kilobytes in banner */
782 job
->pending_timeout
= 0;
785 * See if we need to add the ending sheet...
788 printer
= cupsdFindDest(job
->dest
);
789 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
792 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
793 attr
&& attr
->num_values
> 1)
799 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
800 attr
->values
[1].string
.text
);
802 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
805 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
813 * 'accept_jobs()' - Accept print jobs to a printer.
817 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
818 ipp_attribute_t
*uri
) /* I - Printer or class URI */
820 http_status_t status
; /* Policy status */
821 cups_ptype_t dtype
; /* Destination type (printer/class) */
822 cupsd_printer_t
*printer
; /* Printer data */
825 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
826 con
->http
.fd
, uri
->values
[0].string
.text
);
829 * Is the destination valid?
832 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
838 send_ipp_status(con
, IPP_NOT_FOUND
,
839 _("The printer or class was not found."));
847 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
849 send_http_error(con
, status
, printer
);
854 * Accept jobs sent to the printer...
857 printer
->accepting
= 1;
858 printer
->state_message
[0] = '\0';
860 cupsdAddPrinterHistory(printer
);
862 if (dtype
& CUPS_PRINTER_CLASS
)
864 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
866 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
867 printer
->name
, get_username(con
));
871 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
873 cupsdLogMessage(CUPSD_LOG_INFO
,
874 "Printer \"%s\" now accepting jobs (\"%s\").",
875 printer
->name
, get_username(con
));
879 * Everything was ok, so return OK status...
882 con
->response
->request
.status
.status_code
= IPP_OK
;
887 * 'add_class()' - Add a class to the system.
891 add_class(cupsd_client_t
*con
, /* I - Client connection */
892 ipp_attribute_t
*uri
) /* I - URI of class */
894 http_status_t status
; /* Policy status */
895 int i
; /* Looping var */
896 char method
[HTTP_MAX_URI
], /* Method portion of URI */
897 username
[HTTP_MAX_URI
], /* Username portion of URI */
898 host
[HTTP_MAX_URI
], /* Host portion of URI */
899 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
900 int port
; /* Port portion of URI */
901 cupsd_printer_t
*pclass
, /* Class */
902 *member
; /* Member printer/class */
903 cups_ptype_t dtype
; /* Destination type */
904 ipp_attribute_t
*attr
; /* Printer attribute */
905 int modify
; /* Non-zero if we just modified */
906 char newname
[IPP_MAX_NAME
]; /* New class name */
907 int need_restart_job
; /* Need to restart job? */
910 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
911 con
->http
.fd
, uri
->values
[0].string
.text
);
914 * Do we have a valid URI?
917 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
918 sizeof(method
), username
, sizeof(username
), host
,
919 sizeof(host
), &port
, resource
, sizeof(resource
));
922 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
925 * No, return an error...
928 send_ipp_status(con
, IPP_BAD_REQUEST
,
929 _("The printer-uri must be of the form "
930 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
935 * Do we have a valid printer name?
938 if (!validate_name(resource
+ 9))
941 * No, return an error...
944 send_ipp_status(con
, IPP_BAD_REQUEST
,
945 _("The printer-uri \"%s\" contains invalid characters."),
946 uri
->values
[0].string
.text
);
951 * See if the class already exists; if not, create a new class...
954 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
957 * Class doesn't exist; see if we have a printer of the same name...
960 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
961 !(pclass
->type
& CUPS_PRINTER_DISCOVERED
))
964 * Yes, return an error...
967 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
968 _("A printer named \"%s\" already exists!"),
974 * No, check the default policy and then add the class...
977 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
979 send_http_error(con
, status
, NULL
);
983 pclass
= cupsdAddClass(resource
+ 9);
986 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
989 * Check the default policy, then rename the implicit class to "AnyClass"
993 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
995 send_http_error(con
, status
, NULL
);
999 if (ImplicitAnyClasses
)
1001 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
1002 cupsdRenamePrinter(pclass
, newname
);
1005 cupsdDeletePrinter(pclass
, 1);
1008 * Add the class as a new local class...
1011 pclass
= cupsdAddClass(resource
+ 9);
1014 else if (pclass
->type
& CUPS_PRINTER_DISCOVERED
)
1017 * Check the default policy, then rename the remote class to "Class"...
1020 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1022 send_http_error(con
, status
, NULL
);
1026 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
1027 cupsdRenamePrinter(pclass
, newname
);
1030 * Add the class as a new local class...
1033 pclass
= cupsdAddClass(resource
+ 9);
1036 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
1039 send_http_error(con
, status
, pclass
);
1046 * Look for attributes and copy them over as needed...
1049 need_restart_job
= 0;
1051 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1052 IPP_TAG_TEXT
)) != NULL
)
1053 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
1055 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1056 IPP_TAG_TEXT
)) != NULL
)
1057 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
1059 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1060 IPP_TAG_BOOLEAN
)) != NULL
)
1062 cupsdLogMessage(CUPSD_LOG_INFO
,
1063 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1064 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
1066 pclass
->accepting
= attr
->values
[0].boolean
;
1067 cupsdAddPrinterHistory(pclass
);
1070 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1071 IPP_TAG_BOOLEAN
)) != NULL
)
1073 if (pclass
->shared
&& !attr
->values
[0].boolean
)
1074 cupsdDeregisterPrinter(pclass
, 1);
1076 cupsdLogMessage(CUPSD_LOG_INFO
,
1077 "Setting %s printer-is-shared to %d (was %d.)",
1078 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1080 pclass
->shared
= attr
->values
[0].boolean
;
1083 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1084 IPP_TAG_ENUM
)) != NULL
)
1086 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1087 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1089 send_ipp_status(con
, IPP_BAD_REQUEST
,
1090 _("Attempt to set %s printer-state to bad value %d!"),
1091 pclass
->name
, attr
->values
[0].integer
);
1095 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1096 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1098 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1099 cupsdStopPrinter(pclass
, 0);
1102 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1103 need_restart_job
= 1;
1106 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1107 IPP_TAG_TEXT
)) != NULL
)
1109 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1110 sizeof(pclass
->state_message
));
1111 cupsdAddPrinterHistory(pclass
);
1113 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1114 IPP_TAG_URI
)) != NULL
)
1117 * Clear the printer array as needed...
1120 need_restart_job
= 1;
1122 if (pclass
->num_printers
> 0)
1124 free(pclass
->printers
);
1125 pclass
->num_printers
= 0;
1129 * Add each printer or class that is listed...
1132 for (i
= 0; i
< attr
->num_values
; i
++)
1135 * Search for the printer or class URI...
1138 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1144 send_ipp_status(con
, IPP_NOT_FOUND
,
1145 _("The printer or class was not found."));
1150 * Add it to the class...
1153 cupsdAddPrinterToClass(pclass
, member
);
1157 set_printer_defaults(con
, pclass
);
1159 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1160 IPP_TAG_KEYWORD
)) != NULL
)
1161 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1164 * Update the printer class attributes and return...
1167 cupsdSetPrinterAttrs(pclass
);
1168 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1170 if (need_restart_job
&& pclass
->job
)
1175 * Stop the current job and then restart it below...
1178 job
= (cupsd_job_t
*)pclass
->job
;
1180 cupsdStopJob(job
, 1);
1182 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1183 job
->state_value
= IPP_JOB_PENDING
;
1186 if (need_restart_job
)
1189 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1193 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1194 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1197 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1198 pclass
->name
, get_username(con
));
1202 cupsdAddPrinterHistory(pclass
);
1204 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1205 "New class \"%s\" added by \"%s\".", pclass
->name
,
1208 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1209 pclass
->name
, get_username(con
));
1212 con
->response
->request
.status
.status_code
= IPP_OK
;
1217 * 'add_file()' - Add a file to a job.
1220 static int /* O - 0 on success, -1 on error */
1221 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1222 cupsd_job_t
*job
, /* I - Job to add to */
1223 mime_type_t
*filetype
, /* I - Type of file */
1224 int compression
) /* I - Compression */
1226 mime_type_t
**filetypes
; /* New filetypes array... */
1227 int *compressions
; /* New compressions array... */
1230 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1231 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1232 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1233 filetype
->super
, filetype
->type
, compression
);
1236 * Add the file to the job...
1239 if (job
->num_files
== 0)
1241 compressions
= (int *)malloc(sizeof(int));
1242 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1246 compressions
= (int *)realloc(job
->compressions
,
1247 (job
->num_files
+ 1) * sizeof(int));
1248 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1249 (job
->num_files
+ 1) *
1250 sizeof(mime_type_t
*));
1253 if (!compressions
|| !filetypes
)
1255 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
1258 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1259 _("Unable to allocate memory for file types!"));
1264 job
->compressions
= compressions
;
1265 job
->compressions
[job
->num_files
] = compression
;
1266 job
->filetypes
= filetypes
;
1267 job
->filetypes
[job
->num_files
] = filetype
;
1272 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1279 * 'add_job()' - Add a job to a print queue.
1282 static cupsd_job_t
* /* O - Job object */
1283 add_job(cupsd_client_t
*con
, /* I - Client connection */
1284 cupsd_printer_t
*printer
, /* I - Destination printer */
1285 mime_type_t
*filetype
) /* I - First print file type, if any */
1287 http_status_t status
; /* Policy status */
1288 ipp_attribute_t
*attr
, /* Current attribute */
1289 *auth_info
; /* auth-info attribute */
1290 const char *val
; /* Default option value */
1291 int priority
; /* Job priority */
1292 char *title
; /* Job name/title */
1293 cupsd_job_t
*job
; /* Current job */
1294 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1295 int kbytes
; /* Size of print file */
1296 int i
; /* Looping var */
1297 int lowerpagerange
; /* Page range bound */
1300 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1301 con
, con
->http
.fd
, printer
, printer
->name
,
1302 filetype
, filetype
? filetype
->super
: "none",
1303 filetype
? filetype
->type
: "none");
1306 * Check remote printing to non-shared printer...
1309 if (!printer
->shared
&&
1310 strcasecmp(con
->http
.hostname
, "localhost") &&
1311 strcasecmp(con
->http
.hostname
, ServerName
))
1313 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1314 _("The printer or class is not shared!"));
1322 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1324 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1326 send_http_error(con
, status
, printer
);
1329 else if (printer
->num_auth_info_required
> 0 &&
1330 strcmp(printer
->auth_info_required
[0], "none") &&
1331 !con
->username
[0] && !auth_info
)
1333 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1337 else if (auth_info
&& !con
->http
.tls
&&
1338 !httpAddrLocalhost(con
->http
.hostaddr
))
1341 * Require encryption of auth-info over non-local connections...
1344 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1347 #endif /* HAVE_SSL */
1350 * See if the printer is accepting jobs...
1353 if (!printer
->accepting
)
1355 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1356 _("Destination \"%s\" is not accepting jobs."),
1362 * Validate job template attributes; for now just document-format,
1363 * copies, number-up, and page-ranges...
1366 if (filetype
&& printer
->filetypes
&&
1367 !cupsArrayFind(printer
->filetypes
, filetype
))
1369 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1370 /* MIME media type string */
1373 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1376 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1377 _("Unsupported format \'%s\'!"), mimetype
);
1379 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1380 "document-format", NULL
, mimetype
);
1385 if ((attr
= ippFindAttribute(con
->request
, "copies",
1386 IPP_TAG_INTEGER
)) != NULL
)
1388 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1390 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1391 attr
->values
[0].integer
);
1392 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1393 "copies", attr
->values
[0].integer
);
1398 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1399 IPP_TAG_ZERO
)) != NULL
)
1401 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1402 attr
->value_tag
!= IPP_TAG_NAME
)
1404 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type!"));
1408 if (attr
->num_values
> 2)
1410 send_ipp_status(con
, IPP_BAD_REQUEST
,
1411 _("Too many job-sheets values (%d > 2)!"),
1416 for (i
= 0; i
< attr
->num_values
; i
++)
1417 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1418 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1420 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"!"),
1421 attr
->values
[i
].string
.text
);
1426 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1427 IPP_TAG_INTEGER
)) != NULL
)
1429 if (attr
->values
[0].integer
!= 1 &&
1430 attr
->values
[0].integer
!= 2 &&
1431 attr
->values
[0].integer
!= 4 &&
1432 attr
->values
[0].integer
!= 6 &&
1433 attr
->values
[0].integer
!= 9 &&
1434 attr
->values
[0].integer
!= 16)
1436 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1437 attr
->values
[0].integer
);
1438 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1439 "number-up", attr
->values
[0].integer
);
1444 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1445 IPP_TAG_RANGE
)) != NULL
)
1447 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1449 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1450 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1452 send_ipp_status(con
, IPP_BAD_REQUEST
,
1453 _("Bad page-ranges values %d-%d."),
1454 attr
->values
[i
].range
.lower
,
1455 attr
->values
[i
].range
.upper
);
1459 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1464 * Make sure we aren't over our limit...
1467 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1470 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1472 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1473 _("Too many active jobs."));
1477 if ((i
= check_quotas(con
, printer
)) < 0)
1479 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1484 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1489 * Create the job and set things up...
1492 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1493 IPP_TAG_INTEGER
)) != NULL
)
1494 priority
= attr
->values
[0].integer
;
1497 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1498 printer
->options
)) != NULL
)
1499 priority
= atoi(val
);
1503 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1507 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1508 IPP_TAG_NAME
)) != NULL
)
1509 title
= attr
->values
[0].string
.text
;
1511 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1512 title
= "Untitled");
1514 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1516 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1517 _("Unable to add job for destination \"%s\"!"),
1522 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1523 CUPS_PRINTER_REMOTE
);
1524 job
->attrs
= con
->request
;
1526 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1528 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1530 add_job_uuid(con
, job
);
1531 apply_printer_defaults(printer
, job
);
1533 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1535 if (con
->username
[0])
1537 cupsdSetString(&job
->username
, con
->username
);
1540 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1544 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1545 "add_job: requesting-user-name=\"%s\"",
1546 attr
->values
[0].string
.text
);
1548 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1551 cupsdSetString(&job
->username
, "anonymous");
1554 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1555 "job-originating-user-name", NULL
, job
->username
);
1558 attr
->group_tag
= IPP_TAG_JOB
;
1559 _cupsStrFree(attr
->name
);
1560 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1563 if (con
->username
[0] || auth_info
)
1565 save_auth_info(con
, job
, auth_info
);
1568 * Remove the auth-info attribute from the attribute data...
1572 ippDeleteAttribute(job
->attrs
, auth_info
);
1575 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1576 IPP_TAG_ZERO
)) != NULL
)
1579 * Request contains a job-originating-host-name attribute; validate it...
1582 if (attr
->value_tag
!= IPP_TAG_NAME
||
1583 attr
->num_values
!= 1 ||
1584 strcmp(con
->http
.hostname
, "localhost"))
1587 * Can't override the value if we aren't connected via localhost.
1588 * Also, we can only have 1 value and it must be a name value.
1591 switch (attr
->value_tag
)
1593 case IPP_TAG_STRING
:
1594 case IPP_TAG_TEXTLANG
:
1595 case IPP_TAG_NAMELANG
:
1598 case IPP_TAG_KEYWORD
:
1600 case IPP_TAG_URISCHEME
:
1601 case IPP_TAG_CHARSET
:
1602 case IPP_TAG_LANGUAGE
:
1603 case IPP_TAG_MIMETYPE
:
1605 * Free old strings...
1608 for (i
= 0; i
< attr
->num_values
; i
++)
1610 _cupsStrFree(attr
->values
[i
].string
.text
);
1611 attr
->values
[i
].string
.text
= NULL
;
1612 if (attr
->values
[i
].string
.charset
)
1614 _cupsStrFree(attr
->values
[i
].string
.charset
);
1615 attr
->values
[i
].string
.charset
= NULL
;
1624 * Use the default connection hostname instead...
1627 attr
->value_tag
= IPP_TAG_NAME
;
1628 attr
->num_values
= 1;
1629 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1632 attr
->group_tag
= IPP_TAG_JOB
;
1637 * No job-originating-host-name attribute, so use the hostname from
1641 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1642 "job-originating-host-name", NULL
, con
->http
.hostname
);
1645 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1647 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1648 "time-at-processing", 0);
1649 attr
->value_tag
= IPP_TAG_NOVALUE
;
1650 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1651 "time-at-completed", 0);
1652 attr
->value_tag
= IPP_TAG_NOVALUE
;
1655 * Add remaining job attributes...
1658 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1659 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1660 "job-state", IPP_JOB_STOPPED
);
1661 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1662 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1663 "job-media-sheets-completed", 0);
1664 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1666 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1669 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1670 IPP_TAG_INTEGER
)) != NULL
)
1671 attr
->values
[0].integer
= 0;
1673 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1675 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1676 IPP_TAG_KEYWORD
)) == NULL
)
1677 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1680 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1681 printer
->options
)) == NULL
)
1684 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1685 "job-hold-until", NULL
, val
);
1687 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1688 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1691 * Hold job until specified time...
1694 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1696 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1697 job
->state_value
= IPP_JOB_HELD
;
1699 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1701 job
->hold_until
= time(NULL
) + 60;
1702 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1703 job
->state_value
= IPP_JOB_HELD
;
1707 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1708 job
->state_value
= IPP_JOB_PENDING
;
1711 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1715 * Add job sheets options...
1718 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1719 IPP_TAG_ZERO
)) == NULL
)
1721 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1722 "Adding default job-sheets values \"%s,%s\"...",
1723 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1725 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1727 attr
->values
[0].string
.text
= _cupsStrAlloc(printer
->job_sheets
[0]);
1728 attr
->values
[1].string
.text
= _cupsStrAlloc(printer
->job_sheets
[1]);
1731 job
->job_sheets
= attr
;
1734 * Enforce classification level if set...
1739 cupsdLogMessage(CUPSD_LOG_INFO
,
1740 "Classification=\"%s\", ClassifyOverride=%d",
1741 Classification
? Classification
: "(null)",
1744 if (ClassifyOverride
)
1746 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1747 (attr
->num_values
== 1 ||
1748 !strcmp(attr
->values
[1].string
.text
, "none")))
1751 * Force the leading banner to have the classification on it...
1754 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1756 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1757 "job-sheets=\"%s,none\", "
1758 "job-originating-user-name=\"%s\"",
1759 Classification
, job
->username
);
1761 else if (attr
->num_values
== 2 &&
1762 strcmp(attr
->values
[0].string
.text
,
1763 attr
->values
[1].string
.text
) &&
1764 strcmp(attr
->values
[0].string
.text
, "none") &&
1765 strcmp(attr
->values
[1].string
.text
, "none"))
1768 * Can't put two different security markings on the same document!
1771 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1773 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1774 "job-sheets=\"%s,%s\", "
1775 "job-originating-user-name=\"%s\"",
1776 attr
->values
[0].string
.text
,
1777 attr
->values
[1].string
.text
, job
->username
);
1779 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1780 strcmp(attr
->values
[0].string
.text
, "none") &&
1781 (attr
->num_values
== 1 ||
1782 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1783 strcmp(attr
->values
[1].string
.text
, "none"))))
1785 if (attr
->num_values
== 1)
1786 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1787 "CLASSIFICATION OVERRIDDEN "
1788 "job-sheets=\"%s\", "
1789 "job-originating-user-name=\"%s\"",
1790 attr
->values
[0].string
.text
, job
->username
);
1792 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1793 "CLASSIFICATION OVERRIDDEN "
1794 "job-sheets=\"%s,%s\",fffff "
1795 "job-originating-user-name=\"%s\"",
1796 attr
->values
[0].string
.text
,
1797 attr
->values
[1].string
.text
, job
->username
);
1800 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1801 (attr
->num_values
== 1 ||
1802 strcmp(attr
->values
[1].string
.text
, Classification
)))
1805 * Force the banner to have the classification on it...
1808 if (attr
->num_values
> 1 &&
1809 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1811 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1812 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1816 if (attr
->num_values
== 1 ||
1817 strcmp(attr
->values
[0].string
.text
, "none"))
1818 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1820 if (attr
->num_values
> 1 &&
1821 strcmp(attr
->values
[1].string
.text
, "none"))
1822 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1825 if (attr
->num_values
> 1)
1826 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1827 "CLASSIFICATION FORCED "
1828 "job-sheets=\"%s,%s\", "
1829 "job-originating-user-name=\"%s\"",
1830 attr
->values
[0].string
.text
,
1831 attr
->values
[1].string
.text
, job
->username
);
1833 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1834 "CLASSIFICATION FORCED "
1835 "job-sheets=\"%s\", "
1836 "job-originating-user-name=\"%s\"",
1837 Classification
, job
->username
);
1842 * See if we need to add the starting sheet...
1845 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1847 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1848 attr
->values
[0].string
.text
);
1850 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1852 cupsdDeleteJob(job
);
1856 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1859 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1860 IPP_TAG_ZERO
)) != NULL
)
1864 * Fill in the response info...
1867 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1868 LocalPort
, job
->id
);
1870 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1873 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1875 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1877 add_job_state_reasons(con
, job
);
1879 con
->response
->request
.status
.status_code
= IPP_OK
;
1882 * Add any job subscriptions...
1885 add_job_subscriptions(con
, job
);
1888 * Set all but the first two attributes to the job attributes group...
1891 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1892 attr
->group_tag
= IPP_TAG_JOB
;
1895 * Fire the "job created" event...
1898 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1901 * Return the new job...
1909 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1910 * upon the job and printer state...
1914 add_job_state_reasons(
1915 cupsd_client_t
*con
, /* I - Client connection */
1916 cupsd_job_t
*job
) /* I - Job info */
1918 cupsd_printer_t
*dest
; /* Destination printer */
1921 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1922 con
, con
->http
.fd
, job
? job
->id
: 0);
1924 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1926 case IPP_JOB_PENDING
:
1927 dest
= cupsdFindDest(job
->dest
);
1929 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1930 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1931 "job-state-reasons", NULL
, "printer-stopped");
1933 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1934 "job-state-reasons", NULL
, "none");
1938 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1939 IPP_TAG_KEYWORD
) != NULL
||
1940 ippFindAttribute(job
->attrs
, "job-hold-until",
1941 IPP_TAG_NAME
) != NULL
)
1942 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1943 "job-state-reasons", NULL
, "job-hold-until-specified");
1945 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1946 "job-state-reasons", NULL
, "job-incoming");
1949 case IPP_JOB_PROCESSING
:
1950 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1951 "job-state-reasons", NULL
, "job-printing");
1954 case IPP_JOB_STOPPED
:
1955 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1956 "job-state-reasons", NULL
, "job-stopped");
1959 case IPP_JOB_CANCELED
:
1960 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1961 "job-state-reasons", NULL
, "job-canceled-by-user");
1964 case IPP_JOB_ABORTED
:
1965 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1966 "job-state-reasons", NULL
, "aborted-by-system");
1969 case IPP_JOB_COMPLETED
:
1970 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1971 "job-state-reasons", NULL
, "job-completed-successfully");
1978 * 'add_job_subscriptions()' - Add any subcriptions for a job.
1982 add_job_subscriptions(
1983 cupsd_client_t
*con
, /* I - Client connection */
1984 cupsd_job_t
*job
) /* I - Newly created job */
1986 int i
; /* Looping var */
1987 ipp_attribute_t
*prev
, /* Previous attribute */
1988 *next
, /* Next attribute */
1989 *attr
; /* Current attribute */
1990 cupsd_subscription_t
*sub
; /* Subscription object */
1991 const char *recipient
, /* notify-recipient-uri */
1992 *pullmethod
; /* notify-pull-method */
1993 ipp_attribute_t
*user_data
; /* notify-user-data */
1994 int interval
; /* notify-time-interval */
1995 unsigned mask
; /* notify-events */
1999 * Find the first subscription group attribute; return if we have
2003 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
2004 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2011 * Process the subscription attributes in the request...
2020 mask
= CUPSD_EVENT_NONE
;
2022 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2024 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2025 attr
->value_tag
== IPP_TAG_URI
)
2028 * Validate the recipient scheme against the ServerBin/notifier
2032 char notifier
[1024], /* Notifier filename */
2033 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2034 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2035 host
[HTTP_MAX_URI
], /* Host portion of URI */
2036 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2037 int port
; /* Port portion of URI */
2040 recipient
= attr
->values
[0].string
.text
;
2042 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2043 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2044 host
, sizeof(host
), &port
,
2045 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2047 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2048 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
2049 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2050 "notify-status-code", IPP_URI_SCHEME
);
2054 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2056 if (access(notifier
, X_OK
))
2058 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2059 _("notify-recipient-uri URI \"%s\" uses unknown "
2060 "scheme!"), recipient
);
2061 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2062 "notify-status-code", IPP_URI_SCHEME
);
2066 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2068 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2069 _("notify-recipient-uri URI \"%s\" is already used!"),
2071 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2072 "notify-status-code", IPP_ATTRIBUTES
);
2076 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2077 attr
->value_tag
== IPP_TAG_KEYWORD
)
2079 pullmethod
= attr
->values
[0].string
.text
;
2081 if (strcmp(pullmethod
, "ippget"))
2083 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2084 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
2085 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2086 "notify-status-code", IPP_ATTRIBUTES
);
2090 else if (!strcmp(attr
->name
, "notify-charset") &&
2091 attr
->value_tag
== IPP_TAG_CHARSET
&&
2092 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2093 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2095 send_ipp_status(con
, IPP_CHARSET
,
2096 _("Character set \"%s\" not supported!"),
2097 attr
->values
[0].string
.text
);
2100 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2101 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2102 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2104 send_ipp_status(con
, IPP_CHARSET
,
2105 _("Language \"%s\" not supported!"),
2106 attr
->values
[0].string
.text
);
2109 else if (!strcmp(attr
->name
, "notify-user-data") &&
2110 attr
->value_tag
== IPP_TAG_STRING
)
2112 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2114 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2115 _("The notify-user-data value is too large "
2116 "(%d > 63 octets)!"),
2117 attr
->values
[0].unknown
.length
);
2123 else if (!strcmp(attr
->name
, "notify-events") &&
2124 attr
->value_tag
== IPP_TAG_KEYWORD
)
2126 for (i
= 0; i
< attr
->num_values
; i
++)
2127 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2129 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2131 send_ipp_status(con
, IPP_BAD_REQUEST
,
2132 _("The notify-lease-duration attribute cannot be "
2133 "used with job subscriptions."));
2136 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2137 attr
->value_tag
== IPP_TAG_INTEGER
)
2138 interval
= attr
->values
[0].integer
;
2143 if (!recipient
&& !pullmethod
)
2146 if (mask
== CUPSD_EVENT_NONE
)
2147 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2149 sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
, recipient
,
2152 sub
->interval
= interval
;
2154 cupsdSetString(&sub
->owner
, job
->username
);
2158 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2159 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2160 sub
->user_data_len
);
2163 ippAddSeparator(con
->response
);
2164 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2165 "notify-subscription-id", sub
->id
);
2171 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2174 * Remove all of the subscription attributes from the job request...
2176 * TODO: Optimize this since subscription groups have to come at the
2177 * end of the request...
2180 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2184 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2185 attr
->group_tag
== IPP_TAG_ZERO
)
2188 * Free and remove this attribute...
2196 job
->attrs
->attrs
= next
;
2202 job
->attrs
->last
= prev
;
2203 job
->attrs
->current
= prev
;
2208 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2210 * See RFC 4122 for the definition of UUIDs and the format.
2214 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
2215 cupsd_job_t
*job
) /* I - Job */
2217 char uuid
[1024]; /* job-uuid string */
2218 _cups_md5_state_t md5state
; /* MD5 state */
2219 unsigned char md5sum
[16]; /* MD5 digest/sum */
2223 * First see if the job already has a job-uuid attribute; if so, return...
2226 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2230 * No job-uuid attribute, so build a version 3 UUID with the local job
2231 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2232 * the ServerName, server name and port that the client connected to,
2233 * and local job ID...
2236 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2237 con
->serverport
, job
->id
);
2239 _cupsMD5Init(&md5state
);
2240 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2241 _cupsMD5Finish(&md5state
, md5sum
);
2244 * Format the UUID URI using the MD5 sum and job ID.
2247 snprintf(uuid
, sizeof(uuid
),
2248 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2249 "%02x%02x%02x%02x%02x%02x",
2250 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2251 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2252 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2253 md5sum
[14], md5sum
[15]);
2255 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2260 * 'add_printer()' - Add a printer to the system.
2264 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2265 ipp_attribute_t
*uri
) /* I - URI of printer */
2267 http_status_t status
; /* Policy status */
2268 int i
; /* Looping var */
2269 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2270 username
[HTTP_MAX_URI
], /* Username portion of URI */
2271 host
[HTTP_MAX_URI
], /* Host portion of URI */
2272 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2273 int port
; /* Port portion of URI */
2274 cupsd_printer_t
*printer
; /* Printer/class */
2275 ipp_attribute_t
*attr
; /* Printer attribute */
2276 cups_file_t
*fp
; /* Script/PPD file */
2277 char line
[1024]; /* Line from file... */
2278 char srcfile
[1024], /* Source Script/PPD file */
2279 dstfile
[1024]; /* Destination Script/PPD file */
2280 int modify
; /* Non-zero if we are modifying */
2281 char newname
[IPP_MAX_NAME
]; /* New printer name */
2282 int need_restart_job
; /* Need to restart job? */
2283 int set_device_uri
, /* Did we set the device URI? */
2284 set_port_monitor
; /* Did we set the port monitor? */
2287 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2288 con
->http
.fd
, uri
->values
[0].string
.text
);
2291 * Do we have a valid URI?
2294 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2295 sizeof(scheme
), username
, sizeof(username
), host
,
2296 sizeof(host
), &port
, resource
, sizeof(resource
));
2298 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2301 * No, return an error...
2304 send_ipp_status(con
, IPP_BAD_REQUEST
,
2305 _("The printer-uri must be of the form "
2306 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2311 * Do we have a valid printer name?
2314 if (!validate_name(resource
+ 10))
2317 * No, return an error...
2320 send_ipp_status(con
, IPP_BAD_REQUEST
,
2321 _("The printer-uri \"%s\" contains invalid characters."),
2322 uri
->values
[0].string
.text
);
2327 * See if the printer already exists; if not, create a new printer...
2330 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2333 * Printer doesn't exist; see if we have a class of the same name...
2336 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2337 !(printer
->type
& CUPS_PRINTER_DISCOVERED
))
2340 * Yes, return an error...
2343 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2344 _("A class named \"%s\" already exists!"),
2350 * No, check the default policy then add the printer...
2353 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2355 send_http_error(con
, status
, NULL
);
2359 printer
= cupsdAddPrinter(resource
+ 10);
2362 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2365 * Check the default policy, then rename the implicit printer to
2366 * "AnyPrinter" or delete it...
2369 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2371 send_http_error(con
, status
, NULL
);
2375 if (ImplicitAnyClasses
)
2377 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2378 cupsdRenamePrinter(printer
, newname
);
2381 cupsdDeletePrinter(printer
, 1);
2384 * Add the printer as a new local printer...
2387 printer
= cupsdAddPrinter(resource
+ 10);
2390 else if (printer
->type
& CUPS_PRINTER_DISCOVERED
)
2393 * Check the default policy, then rename the remote printer to
2394 * "Printer@server"...
2397 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2399 send_http_error(con
, status
, NULL
);
2403 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2405 cupsdRenamePrinter(printer
, newname
);
2408 * Add the printer as a new local printer...
2411 printer
= cupsdAddPrinter(resource
+ 10);
2414 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2417 send_http_error(con
, status
, printer
);
2424 * Look for attributes and copy them over as needed...
2427 need_restart_job
= 0;
2429 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2430 IPP_TAG_TEXT
)) != NULL
)
2431 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2433 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2434 IPP_TAG_TEXT
)) != NULL
)
2435 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2439 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2440 IPP_TAG_URI
)) != NULL
)
2443 * Do we have a valid device URI?
2446 http_uri_status_t uri_status
; /* URI separation status */
2449 need_restart_job
= 1;
2451 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2452 attr
->values
[0].string
.text
,
2453 scheme
, sizeof(scheme
),
2454 username
, sizeof(username
),
2455 host
, sizeof(host
), &port
,
2456 resource
, sizeof(resource
));
2458 if (uri_status
< HTTP_URI_OK
)
2460 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2461 attr
->values
[0].string
.text
);
2462 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2463 "add_printer: httpSeparateURI returned %d", uri_status
);
2467 if (!strcmp(scheme
, "file"))
2470 * See if the administrator has enabled file devices...
2473 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2476 * File devices are disabled and the URL is not file:/dev/null...
2479 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2480 _("File device URIs have been disabled! "
2481 "To enable, see the FileDevice directive in "
2482 "\"%s/cupsd.conf\"."),
2490 * See if the backend exists and is executable...
2493 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2494 if (access(srcfile
, X_OK
))
2497 * Could not find device in list!
2500 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2501 attr
->values
[0].string
.text
);
2506 cupsdLogMessage(CUPSD_LOG_INFO
,
2507 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2509 cupsdSanitizeURI(attr
->values
[0].string
.text
, line
,
2511 cupsdSanitizeURI(printer
->device_uri
, resource
,
2514 cupsdSetString(&printer
->device_uri
, attr
->values
[0].string
.text
);
2518 set_port_monitor
= 0;
2520 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2521 IPP_TAG_NAME
)) != NULL
)
2523 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2526 need_restart_job
= 1;
2528 supported
= ippFindAttribute(printer
->attrs
, "port-monitor-supported",
2532 for (i
= 0; i
< supported
->num_values
; i
++)
2533 if (!strcmp(supported
->values
[i
].string
.text
,
2534 attr
->values
[0].string
.text
))
2538 if (!supported
|| i
>= supported
->num_values
)
2540 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2541 attr
->values
[0].string
.text
);
2545 cupsdLogMessage(CUPSD_LOG_INFO
,
2546 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2547 printer
->name
, attr
->values
[0].string
.text
,
2548 printer
->port_monitor
? printer
->port_monitor
: "none");
2550 if (strcmp(attr
->values
[0].string
.text
, "none"))
2551 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2553 cupsdClearString(&printer
->port_monitor
);
2555 set_port_monitor
= 1;
2558 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2559 IPP_TAG_BOOLEAN
)) != NULL
)
2561 cupsdLogMessage(CUPSD_LOG_INFO
,
2562 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2563 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2565 printer
->accepting
= attr
->values
[0].boolean
;
2566 cupsdAddPrinterHistory(printer
);
2569 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2570 IPP_TAG_BOOLEAN
)) != NULL
)
2572 if (printer
->shared
&& !attr
->values
[0].boolean
)
2573 cupsdDeregisterPrinter(printer
, 1);
2575 cupsdLogMessage(CUPSD_LOG_INFO
,
2576 "Setting %s printer-is-shared to %d (was %d.)",
2577 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2579 printer
->shared
= attr
->values
[0].boolean
;
2582 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2583 IPP_TAG_ENUM
)) != NULL
)
2585 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2586 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2588 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2589 attr
->values
[0].integer
);
2593 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2594 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2596 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2597 cupsdStopPrinter(printer
, 0);
2600 need_restart_job
= 1;
2601 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2604 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2605 IPP_TAG_TEXT
)) != NULL
)
2607 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2608 sizeof(printer
->state_message
));
2609 cupsdAddPrinterHistory(printer
);
2612 set_printer_defaults(con
, printer
);
2614 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2615 IPP_TAG_KEYWORD
)) != NULL
)
2616 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2619 * See if we have all required attributes...
2622 if (!printer
->device_uri
)
2623 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2626 * See if we have an interface script or PPD file attached to the request...
2631 need_restart_job
= 1;
2633 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2635 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2638 * Yes; get the first line from it...
2642 cupsFileGets(fp
, line
, sizeof(line
));
2646 * Then see what kind of file it is...
2649 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2652 if (!strncmp(line
, "*PPD-Adobe", 10))
2655 * The new file is a PPD file, so remove any old interface script
2656 * that might be lying around...
2664 * This must be an interface script, so move the file over to the
2665 * interfaces directory and make it executable...
2668 if (copy_file(srcfile
, dstfile
))
2670 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2671 _("Unable to copy interface script - %s!"),
2676 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2677 "Copied interface script successfully!");
2678 chmod(dstfile
, 0755);
2681 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2684 if (!strncmp(line
, "*PPD-Adobe", 10))
2687 * The new file is a PPD file, so move the file over to the
2688 * ppd directory and make it readable by all...
2691 if (copy_file(srcfile
, dstfile
))
2693 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2694 _("Unable to copy PPD file - %s!"),
2699 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2700 "Copied PPD file successfully!");
2701 chmod(dstfile
, 0644);
2705 * (Re)register color profiles...
2708 apple_unregister_profiles(printer
);
2709 apple_register_profiles(printer
);
2710 #endif /* __APPLE__ */
2715 * This must be an interface script, so remove any old PPD file that
2716 * may be lying around...
2723 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2724 IPP_TAG_NAME
)) != NULL
)
2726 need_restart_job
= 1;
2728 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2731 * Raw driver, remove any existing PPD or interface script files.
2734 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2738 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2748 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2752 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2755 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2757 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2761 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2762 "Copied PPD file successfully!");
2763 chmod(dstfile
, 0644);
2767 * (Re)register color profiles...
2770 apple_unregister_profiles(printer
);
2771 apple_register_profiles(printer
);
2772 #endif /* __APPLE__ */
2777 * If we set the device URI but not the port monitor, check which port
2778 * monitor to use by default...
2781 if (set_device_uri
&& !set_port_monitor
)
2783 ppd_file_t
*ppd
; /* PPD file */
2784 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2787 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2788 sizeof(scheme
), username
, sizeof(username
), host
,
2789 sizeof(host
), &port
, resource
, sizeof(resource
));
2791 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2793 if ((ppd
= ppdOpenFile(srcfile
)) != NULL
)
2795 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2797 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2798 if (!strcmp(scheme
, ppdattr
->spec
))
2800 cupsdLogMessage(CUPSD_LOG_INFO
,
2801 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2802 printer
->name
, ppdattr
->value
,
2803 printer
->port_monitor
? printer
->port_monitor
2806 if (strcmp(ppdattr
->value
, "none"))
2807 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2809 cupsdClearString(&printer
->port_monitor
);
2819 * Update the printer attributes and return...
2822 cupsdSetPrinterAttrs(printer
);
2823 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2825 if (need_restart_job
&& printer
->job
)
2830 * Stop the current job and then restart it below...
2833 job
= (cupsd_job_t
*)printer
->job
;
2835 cupsdStopJob(job
, 1);
2837 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2838 job
->state_value
= IPP_JOB_PENDING
;
2841 if (need_restart_job
)
2844 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2848 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2849 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2852 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2853 printer
->name
, get_username(con
));
2857 cupsdAddPrinterHistory(printer
);
2859 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2860 "New printer \"%s\" added by \"%s\".", printer
->name
,
2863 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2864 printer
->name
, get_username(con
));
2867 con
->response
->request
.status
.status_code
= IPP_OK
;
2872 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2873 * based upon the printer state...
2877 add_printer_state_reasons(
2878 cupsd_client_t
*con
, /* I - Client connection */
2879 cupsd_printer_t
*p
) /* I - Printer info */
2881 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2882 "add_printer_state_reasons(%p[%d], %p[%s])",
2883 con
, con
->http
.fd
, p
, p
->name
);
2885 if (p
->num_reasons
== 0)
2886 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2887 "printer-state-reasons", NULL
,
2888 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2890 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2891 "printer-state-reasons", p
->num_reasons
, NULL
,
2892 (const char * const *)p
->reasons
);
2897 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2898 * the specified printer or class.
2902 add_queued_job_count(
2903 cupsd_client_t
*con
, /* I - Client connection */
2904 cupsd_printer_t
*p
) /* I - Printer or class */
2906 int count
; /* Number of jobs on destination */
2909 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2910 con
, con
->http
.fd
, p
, p
->name
);
2912 count
= cupsdGetPrinterJobCount(p
->name
);
2914 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2915 "queued-job-count", count
);
2921 * 'apple_init_profile()' - Initialize a color profile.
2926 ppd_file_t
*ppd
, /* I - PPD file */
2927 cups_array_t
*languages
, /* I - Languages in the PPD file */
2928 CMDeviceProfileInfo
*profile
, /* I - Profile record */
2929 unsigned id
, /* I - Profile ID */
2930 const char *name
, /* I - Profile name */
2931 const char *text
, /* I - Profile UI text */
2932 const char *iccfile
) /* I - ICC filename */
2934 char url
[1024]; /* URL for profile filename */
2935 CFMutableDictionaryRef dict
; /* Dictionary for name */
2936 char *language
; /* Current language */
2937 ppd_attr_t
*attr
; /* Profile attribute */
2938 CFStringRef cflang
, /* Language string */
2939 cftext
; /* Localized text */
2943 * Build the profile name dictionary...
2946 dict
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
2947 &kCFTypeDictionaryKeyCallBacks
,
2948 &kCFTypeDictionaryValueCallBacks
);
2950 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, text
,
2951 kCFStringEncodingUTF8
);
2955 CFDictionarySetValue(dict
, CFSTR("en"), cftext
);
2962 * Find localized names for the color profiles...
2965 cupsArraySave(ppd
->sorted_attrs
);
2967 for (language
= (char *)cupsArrayFirst(languages
);
2969 language
= (char *)cupsArrayNext(languages
))
2973 if ((attr
= _ppdLocalizedAttr(ppd
, "cupsICCProfile", name
,
2975 attr
= _ppdLocalizedAttr(ppd
, "APTiogaProfile", name
, language
);
2978 attr
= _ppdLocalizedAttr(ppd
, "ColorModel", name
, language
);
2980 if (attr
&& attr
->text
[0])
2982 cflang
= CFStringCreateWithCString(kCFAllocatorDefault
, language
,
2983 kCFStringEncodingUTF8
);
2984 cftext
= CFStringCreateWithCString(kCFAllocatorDefault
, attr
->text
,
2985 kCFStringEncodingUTF8
);
2987 if (cflang
&& cftext
)
2988 CFDictionarySetValue(dict
, cflang
, cftext
);
2998 cupsArrayRestore(ppd
->sorted_attrs
);
3002 * Fill in the profile data...
3006 httpAssembleURI(HTTP_URI_CODING_ALL
, url
, sizeof(url
), "file", NULL
, "", 0,
3009 profile
->dataVersion
= cmDeviceProfileInfoVersion1
;
3010 profile
->profileID
= id
;
3011 profile
->profileLoc
.locType
= iccfile
? cmPathBasedProfile
: cmNoProfileBase
;
3012 profile
->profileName
= dict
;
3015 strlcpy(profile
->profileLoc
.u
.pathLoc
.path
, iccfile
,
3016 sizeof(profile
->profileLoc
.u
.pathLoc
.path
));
3021 * 'apple_register_profiles()' - Register color profiles for a printer.
3025 apple_register_profiles(
3026 cupsd_printer_t
*p
) /* I - Printer */
3028 int i
; /* Looping var */
3029 char ppdfile
[1024], /* PPD filename */
3030 iccfile
[1024], /* ICC filename */
3031 selector
[PPD_MAX_NAME
];
3032 /* Profile selection string */
3033 ppd_file_t
*ppd
; /* PPD file */
3034 ppd_attr_t
*attr
, /* Profile attributes */
3035 *profileid_attr
,/* cupsProfileID attribute */
3036 *q1_attr
, /* ColorModel (or other) qualifier */
3037 *q2_attr
, /* MediaType (or other) qualifier */
3038 *q3_attr
; /* Resolution (or other) qualifier */
3039 char q_keyword
[PPD_MAX_NAME
];
3040 /* Qualifier keyword */
3041 const char *q1_choice
, /* ColorModel (or other) choice */
3042 *q2_choice
, /* MediaType (or other) choice */
3043 *q3_choice
; /* Resolution (or other) choice */
3044 const char *profile_key
; /* Profile keyword */
3045 ppd_option_t
*cm_option
; /* Color model option */
3046 ppd_choice_t
*cm_choice
; /* Color model choice */
3047 int num_profiles
; /* Number of profiles */
3048 CMError error
; /* Last error */
3049 unsigned device_id
, /* Printer device ID */
3050 profile_id
, /* Profile ID */
3051 default_profile_id
= 0;
3052 /* Default profile ID */
3053 CFMutableDictionaryRef device_name
; /* Printer device name dictionary */
3054 CFStringRef printer_name
; /* Printer name string */
3055 CMDeviceScope scope
= /* Scope of the registration */
3057 kCFPreferencesAnyUser
,
3058 kCFPreferencesCurrentHost
3060 CMDeviceProfileArrayPtr profiles
; /* Profiles */
3061 CMDeviceProfileInfo
*profile
; /* Current profile */
3062 cups_array_t
*languages
; /* Languages array */
3066 * Make sure ColorSync is available...
3069 if (CMRegisterColorDevice
== NULL
)
3073 * Try opening the PPD file for this printer...
3076 snprintf(ppdfile
, sizeof(ppdfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3077 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
3081 * See if we have any profiles...
3084 if ((attr
= ppdFindAttr(ppd
, "APTiogaProfile", NULL
)) != NULL
)
3085 profile_key
= "APTiogaProfile";
3088 attr
= ppdFindAttr(ppd
, "cupsICCProfile", NULL
);
3089 profile_key
= "cupsICCProfile";
3092 for (num_profiles
= 0; attr
; attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3093 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3095 if (attr
->value
[0] != '/')
3096 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3099 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3101 if (access(iccfile
, 0))
3109 * If we have profiles, add them...
3112 if (num_profiles
> 0)
3114 if (profile_key
[0] == 'A')
3117 * For Tioga PPDs, get the default profile using the DefaultAPTiogaProfile
3121 if ((attr
= ppdFindAttr(ppd
, "DefaultAPTiogaProfile", NULL
)) != NULL
&&
3123 default_profile_id
= atoi(attr
->value
);
3125 q1_choice
= q2_choice
= q3_choice
= NULL
;
3130 * For CUPS PPDs, figure out the default profile selector values...
3133 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier1", NULL
)) != NULL
&&
3134 attr
->value
&& attr
->value
[0])
3136 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3137 q1_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3139 else if ((q1_attr
= ppdFindAttr(ppd
, "DefaultColorModel", NULL
)) == NULL
)
3140 q1_attr
= ppdFindAttr(ppd
, "DefaultColorSpace", NULL
);
3142 if (q1_attr
&& q1_attr
->value
&& q1_attr
->value
[0])
3143 q1_choice
= q1_attr
->value
;
3147 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier2", NULL
)) != NULL
&&
3148 attr
->value
&& attr
->value
[0])
3150 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3151 q2_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3154 q2_attr
= ppdFindAttr(ppd
, "DefaultMediaType", NULL
);
3156 if (q2_attr
&& q2_attr
->value
&& q2_attr
->value
[0])
3157 q2_choice
= q2_attr
->value
;
3161 if ((attr
= ppdFindAttr(ppd
, "cupsICCQualifier3", NULL
)) != NULL
&&
3162 attr
->value
&& attr
->value
[0])
3164 snprintf(q_keyword
, sizeof(q_keyword
), "Default%s", attr
->value
);
3165 q3_attr
= ppdFindAttr(ppd
, q_keyword
, NULL
);
3168 q3_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
);
3170 if (q3_attr
&& q3_attr
->value
&& q3_attr
->value
[0])
3171 q3_choice
= q3_attr
->value
;
3177 * Build the array of profiles...
3179 * Note: This calloc actually requests slightly more memory than needed.
3182 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3184 cupsdLogMessage(CUPSD_LOG_ERROR
,
3185 "Unable to allocate memory for %d profiles!",
3191 profiles
->profileCount
= num_profiles
;
3192 languages
= _ppdGetLanguages(ppd
);
3194 for (profile
= profiles
->profiles
,
3195 attr
= ppdFindAttr(ppd
, profile_key
, NULL
);
3197 attr
= ppdFindNextAttr(ppd
, profile_key
, NULL
))
3198 if (attr
->spec
[0] && attr
->value
&& attr
->value
[0])
3201 * Add this profile...
3204 if (attr
->value
[0] != '/')
3205 snprintf(iccfile
, sizeof(iccfile
), "%s/profiles/%s", DataDir
,
3208 strlcpy(iccfile
, attr
->value
, sizeof(iccfile
));
3210 if (access(iccfile
, 0))
3213 if (profile_key
[0] == 'c')
3215 cupsArraySave(ppd
->sorted_attrs
);
3217 if ((profileid_attr
= ppdFindAttr(ppd
, "cupsProfileID",
3218 attr
->spec
)) != NULL
&&
3219 profileid_attr
->value
&& isdigit(profileid_attr
->value
[0] & 255))
3220 profile_id
= (unsigned)strtoul(profileid_attr
->value
, NULL
, 10);
3222 profile_id
= _ppdHashName(attr
->spec
);
3224 cupsArrayRestore(ppd
->sorted_attrs
);
3227 profile_id
= atoi(attr
->spec
);
3229 apple_init_profile(ppd
, languages
, profile
, profile_id
, attr
->spec
,
3230 attr
->text
[0] ? attr
->text
: attr
->spec
, iccfile
);
3235 * See if this is the default profile...
3238 if (!default_profile_id
)
3244 snprintf(selector
, sizeof(selector
), "%s.%s.%s",
3245 q1_choice
, q2_choice
, q3_choice
);
3246 if (!strcmp(selector
, attr
->spec
))
3247 default_profile_id
= profile_id
;
3250 if (!default_profile_id
)
3252 snprintf(selector
, sizeof(selector
), "%s.%s.", q1_choice
,
3254 if (!strcmp(selector
, attr
->spec
))
3255 default_profile_id
= profile_id
;
3259 if (!default_profile_id
&& q3_choice
)
3261 snprintf(selector
, sizeof(selector
), "%s..%s", q1_choice
,
3263 if (!strcmp(selector
, attr
->spec
))
3264 default_profile_id
= profile_id
;
3267 if (!default_profile_id
)
3269 snprintf(selector
, sizeof(selector
), "%s..", q1_choice
);
3270 if (!strcmp(selector
, attr
->spec
))
3271 default_profile_id
= profile_id
;
3276 _ppdFreeLanguages(languages
);
3278 else if ((cm_option
= ppdFindOption(ppd
, "ColorModel")) != NULL
)
3281 * Extract profiles from ColorModel option...
3284 const char *profile_name
; /* Name of generic profile */
3287 num_profiles
= cm_option
->num_choices
;
3289 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3291 cupsdLogMessage(CUPSD_LOG_ERROR
,
3292 "Unable to allocate memory for %d profiles!",
3298 profiles
->profileCount
= num_profiles
;
3300 for (profile
= profiles
->profiles
, i
= cm_option
->num_choices
,
3301 cm_choice
= cm_option
->choices
;
3303 i
--, cm_choice
++, profile
++)
3305 if (!strcmp(cm_choice
->choice
, "Gray") ||
3306 !strcmp(cm_choice
->choice
, "Black"))
3307 profile_name
= "Gray";
3308 else if (!strcmp(cm_choice
->choice
, "RGB") ||
3309 !strcmp(cm_choice
->choice
, "CMY"))
3310 profile_name
= "RGB";
3311 else if (!strcmp(cm_choice
->choice
, "CMYK") ||
3312 !strcmp(cm_choice
->choice
, "KCMY"))
3313 profile_name
= "CMYK";
3315 profile_name
= "DeviceN";
3317 snprintf(selector
, sizeof(selector
), "%s..", profile_name
);
3318 profile_id
= _ppdHashName(selector
);
3320 apple_init_profile(ppd
, NULL
, profile
, profile_id
, cm_choice
->choice
,
3321 cm_choice
->text
, NULL
);
3323 if (cm_choice
->marked
)
3324 default_profile_id
= profile_id
;
3330 * Use the default colorspace...
3333 num_profiles
= 1 + ppd
->colorspace
!= PPD_CS_GRAY
;
3335 if ((profiles
= calloc(num_profiles
, sizeof(CMDeviceProfileArray
))) == NULL
)
3337 cupsdLogMessage(CUPSD_LOG_ERROR
,
3338 "Unable to allocate memory for %d profiles!",
3344 profiles
->profileCount
= num_profiles
;
3346 apple_init_profile(ppd
, NULL
, profiles
->profiles
, _ppdHashName("Gray.."),
3347 "Gray", "Gray", NULL
);
3349 switch (ppd
->colorspace
)
3353 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3354 _ppdHashName("RGB.."), "RGB", "RGB", NULL
);
3358 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3359 _ppdHashName("CMYK.."), "CMYK", "CMYK", NULL
);
3363 apple_init_profile(ppd
, NULL
, profiles
->profiles
+ 1,
3364 _ppdHashName("DeviceN.."), "DeviceN", "DeviceN",
3373 if (num_profiles
> 0)
3376 * Make sure we have a default profile ID...
3379 if (!default_profile_id
)
3380 default_profile_id
= profiles
->profiles
[num_profiles
- 1].profileID
;
3383 * Get the device ID hash and pathelogical name dictionary.
3386 cupsdLogMessage(CUPSD_LOG_INFO
, "Registering ICC color profiles for \"%s\"",
3389 device_id
= _ppdHashName(p
->name
);
3390 device_name
= CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
3391 &kCFTypeDictionaryKeyCallBacks
,
3392 &kCFTypeDictionaryValueCallBacks
);
3393 printer_name
= CFStringCreateWithCString(kCFAllocatorDefault
, p
->name
,
3394 kCFStringEncodingUTF8
);
3396 if (device_name
&& printer_name
)
3398 CFDictionarySetValue(device_name
, CFSTR("en"), printer_name
);
3401 * Register the device with ColorSync...
3404 error
= CMRegisterColorDevice(cmPrinterDeviceClass
, device_id
,
3405 device_name
, &scope
);
3408 * Register the profiles...
3412 error
= CMSetDeviceFactoryProfiles(cmPrinterDeviceClass
, device_id
,
3413 default_profile_id
, profiles
);
3423 cupsdLogMessage(CUPSD_LOG_ERROR
,
3424 "Unable to register ICC color profiles for \"%s\" - %d",
3425 p
->name
, (int)error
);
3427 for (profile
= profiles
->profiles
;
3429 profile
++, num_profiles
--)
3430 CFRelease(profile
->profileName
);
3435 CFRelease(printer_name
);
3438 CFRelease(device_name
);
3446 * 'apple_unregister_profiles()' - Remove color profiles for the specified
3451 apple_unregister_profiles(
3452 cupsd_printer_t
*p
) /* I - Printer */
3455 * Make sure ColorSync is available...
3458 if (CMUnregisterColorDevice
!= NULL
)
3459 CMUnregisterColorDevice(cmPrinterDeviceClass
, _ppdHashName(p
->name
));
3461 #endif /* __APPLE__ */
3464 * 'apply_printer_defaults()' - Apply printer default options to a job.
3468 apply_printer_defaults(
3469 cupsd_printer_t
*printer
, /* I - Printer */
3470 cupsd_job_t
*job
) /* I - Job */
3472 int i
, /* Looping var */
3473 num_options
; /* Number of default options */
3474 cups_option_t
*options
, /* Default options */
3475 *option
; /* Current option */
3479 * Collect all of the default options and add the missing ones to the
3483 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
3484 option
= printer
->options
;
3487 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3489 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3494 * Encode these options as attributes in the job object...
3497 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3498 cupsFreeOptions(num_options
, options
);
3503 * 'authenticate_job()' - Set job authentication info.
3507 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3508 ipp_attribute_t
*uri
) /* I - Job URI */
3510 ipp_attribute_t
*attr
, /* job-id attribute */
3511 *auth_info
; /* auth-info attribute */
3512 int jobid
; /* Job ID */
3513 cupsd_job_t
*job
; /* Current job */
3514 char method
[HTTP_MAX_URI
],
3515 /* Method portion of URI */
3516 username
[HTTP_MAX_URI
],
3517 /* Username portion of URI */
3519 /* Host portion of URI */
3520 resource
[HTTP_MAX_URI
];
3521 /* Resource portion of URI */
3522 int port
; /* Port portion of URI */
3525 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3526 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3529 * Start with "everything is OK" status...
3532 con
->response
->request
.status
.status_code
= IPP_OK
;
3535 * See if we have a job URI or a printer URI...
3538 if (!strcmp(uri
->name
, "printer-uri"))
3541 * Got a printer URI; see if we also have a job-id attribute...
3544 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3545 IPP_TAG_INTEGER
)) == NULL
)
3547 send_ipp_status(con
, IPP_BAD_REQUEST
,
3548 _("Got a printer-uri attribute but no job-id!"));
3552 jobid
= attr
->values
[0].integer
;
3557 * Got a job URI; parse it to get the job ID...
3560 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
3561 sizeof(method
), username
, sizeof(username
), host
,
3562 sizeof(host
), &port
, resource
, sizeof(resource
));
3564 if (strncmp(resource
, "/jobs/", 6))
3570 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3571 uri
->values
[0].string
.text
);
3575 jobid
= atoi(resource
+ 6);
3579 * See if the job exists...
3582 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3585 * Nope - return a "not found" error...
3588 send_ipp_status(con
, IPP_NOT_FOUND
,
3589 _("Job #%d does not exist!"), jobid
);
3594 * See if the job has been completed...
3597 if (job
->state_value
!= IPP_JOB_HELD
)
3600 * Return a "not-possible" error...
3603 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3604 _("Job #%d is not held for authentication!"),
3610 * See if we have already authenticated...
3613 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3615 if (!con
->username
[0] && !auth_info
)
3617 cupsd_printer_t
*printer
; /* Job destination */
3621 * No auth data. If we need to authenticate via Kerberos, send a
3622 * HTTP auth challenge, otherwise just return an IPP error...
3625 printer
= cupsdFindDest(job
->dest
);
3627 if (printer
&& printer
->num_auth_info_required
> 0 &&
3628 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3629 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3631 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3632 _("No authentication information provided!"));
3637 * See if the job is owned by the requesting user...
3640 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3642 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3647 * Save the authentication information for this job...
3650 save_auth_info(con
, job
, auth_info
);
3653 * Reset the job-hold-until value to "no-hold"...
3656 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3657 IPP_TAG_KEYWORD
)) == NULL
)
3658 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3662 attr
->value_tag
= IPP_TAG_KEYWORD
;
3663 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3667 * Release the job and return...
3670 cupsdReleaseJob(job
);
3672 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3677 * 'cancel_all_jobs()' - Cancel all print jobs.
3681 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3682 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3684 http_status_t status
; /* Policy status */
3685 cups_ptype_t dtype
; /* Destination type */
3686 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3687 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3688 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3689 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3690 int port
; /* Port portion of URI */
3691 ipp_attribute_t
*attr
; /* Attribute in request */
3692 const char *username
; /* Username */
3693 int purge
; /* Purge? */
3694 cupsd_printer_t
*printer
; /* Printer */
3697 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3698 con
->http
.fd
, uri
->values
[0].string
.text
);
3701 * See if we have a printer URI...
3704 if (strcmp(uri
->name
, "printer-uri"))
3706 send_ipp_status(con
, IPP_BAD_REQUEST
,
3707 _("The printer-uri attribute is required!"));
3712 * Get the username (if any) for the jobs we want to cancel (only if
3713 * "my-jobs" is specified...
3716 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3717 IPP_TAG_BOOLEAN
)) != NULL
&&
3718 attr
->values
[0].boolean
)
3720 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3721 IPP_TAG_NAME
)) != NULL
)
3722 username
= attr
->values
[0].string
.text
;
3725 send_ipp_status(con
, IPP_BAD_REQUEST
,
3726 _("Missing requesting-user-name attribute!"));
3734 * Look for the "purge-jobs" attribute...
3737 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3738 IPP_TAG_BOOLEAN
)) != NULL
)
3739 purge
= attr
->values
[0].boolean
;
3744 * And if the destination is valid...
3747 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3753 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3754 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3755 hostname
, sizeof(hostname
), &port
,
3756 resource
, sizeof(resource
));
3758 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3759 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3761 send_ipp_status(con
, IPP_NOT_FOUND
,
3762 _("The printer or class was not found."));
3770 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3772 send_http_error(con
, status
, NULL
);
3777 * Cancel all jobs on all printers...
3780 cupsdCancelJobs(NULL
, username
, purge
);
3782 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3783 purge
? "purged" : "canceled", get_username(con
));
3791 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3794 send_http_error(con
, status
, printer
);
3799 * Cancel all of the jobs on the named printer...
3802 cupsdCancelJobs(printer
->name
, username
, purge
);
3804 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3805 printer
->name
, purge
? "purged" : "canceled",
3809 con
->response
->request
.status
.status_code
= IPP_OK
;
3814 * 'cancel_job()' - Cancel a print job.
3818 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3819 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3821 ipp_attribute_t
*attr
; /* Current attribute */
3822 int jobid
; /* Job ID */
3823 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3824 username
[HTTP_MAX_URI
], /* Username portion of URI */
3825 host
[HTTP_MAX_URI
], /* Host portion of URI */
3826 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3827 int port
; /* Port portion of URI */
3828 cupsd_job_t
*job
; /* Job information */
3829 cups_ptype_t dtype
; /* Destination type (printer/class) */
3830 cupsd_printer_t
*printer
; /* Printer data */
3831 int purge
; /* Purge the job? */
3834 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3835 con
->http
.fd
, uri
->values
[0].string
.text
);
3838 * See if we have a job URI or a printer URI...
3841 if (!strcmp(uri
->name
, "printer-uri"))
3844 * Got a printer URI; see if we also have a job-id attribute...
3847 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3848 IPP_TAG_INTEGER
)) == NULL
)
3850 send_ipp_status(con
, IPP_BAD_REQUEST
,
3851 _("Got a printer-uri attribute but no job-id!"));
3855 if ((jobid
= attr
->values
[0].integer
) == 0)
3858 * Find the current job on the specified printer...
3861 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3867 send_ipp_status(con
, IPP_NOT_FOUND
,
3868 _("The printer or class was not found."));
3873 * See if the printer is currently printing a job...
3877 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
3881 * No, see if there are any pending jobs...
3884 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3886 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3887 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3888 !strcasecmp(job
->dest
, printer
->name
))
3895 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3897 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3898 if (job
->state_value
== IPP_JOB_STOPPED
&&
3899 !strcasecmp(job
->dest
, printer
->name
))
3906 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
3917 * Got a job URI; parse it to get the job ID...
3920 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3921 sizeof(scheme
), username
, sizeof(username
), host
,
3922 sizeof(host
), &port
, resource
, sizeof(resource
));
3924 if (strncmp(resource
, "/jobs/", 6))
3930 send_ipp_status(con
, IPP_BAD_REQUEST
,
3931 _("Bad job-uri attribute \"%s\"!"),
3932 uri
->values
[0].string
.text
);
3936 jobid
= atoi(resource
+ 6);
3940 * Look for the "purge-job" attribute...
3943 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3944 IPP_TAG_BOOLEAN
)) != NULL
)
3945 purge
= attr
->values
[0].boolean
;
3950 * See if the job exists...
3953 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3956 * Nope - return a "not found" error...
3959 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
3964 * See if the job is owned by the requesting user...
3967 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3969 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3974 * See if the job is already completed, canceled, or aborted; if so,
3975 * we can't cancel...
3978 if (job
->state_value
>= IPP_JOB_CANCELED
&& !purge
)
3980 switch (job
->state_value
)
3982 case IPP_JOB_CANCELED
:
3983 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3984 _("Job #%d is already canceled - can\'t cancel."),
3988 case IPP_JOB_ABORTED
:
3989 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3990 _("Job #%d is already aborted - can\'t cancel."),
3995 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3996 _("Job #%d is already completed - can\'t cancel."),
4005 * Cancel the job and return...
4008 cupsdCancelJob(job
, purge
, IPP_JOB_CANCELED
);
4012 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4015 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4018 con
->response
->request
.status
.status_code
= IPP_OK
;
4023 * 'cancel_subscription()' - Cancel a subscription.
4027 cancel_subscription(
4028 cupsd_client_t
*con
, /* I - Client connection */
4029 int sub_id
) /* I - Subscription ID */
4031 http_status_t status
; /* Policy status */
4032 cupsd_subscription_t
*sub
; /* Subscription */
4035 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4036 "cancel_subscription(con=%p[%d], sub_id=%d)",
4037 con
, con
->http
.fd
, sub_id
);
4040 * Is the subscription ID valid?
4043 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4046 * Bad subscription ID...
4049 send_ipp_status(con
, IPP_NOT_FOUND
,
4050 _("notify-subscription-id %d no good!"), sub_id
);
4058 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4060 con
, sub
->owner
)) != HTTP_OK
)
4062 send_http_error(con
, status
, sub
->dest
);
4067 * Cancel the subscription...
4070 cupsdDeleteSubscription(sub
, 1);
4072 con
->response
->request
.status
.status_code
= IPP_OK
;
4077 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4080 static int /* O - 1 if OK, 0 if not */
4081 check_rss_recipient(
4082 const char *recipient
) /* I - Recipient URI */
4084 cupsd_subscription_t
*sub
; /* Current subscription */
4087 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4089 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4093 * Compare the URIs up to the first ?...
4096 const char *r1
, *r2
;
4098 for (r1
= recipient
, r2
= sub
->recipient
;
4099 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4111 * 'check_quotas()' - Check quotas for a printer and user.
4114 static int /* O - 1 if OK, 0 if not */
4115 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4116 cupsd_printer_t
*p
) /* I - Printer or class */
4118 int i
; /* Looping var */
4119 char username
[33]; /* Username */
4120 cupsd_quota_t
*q
; /* Quota data */
4121 #ifdef HAVE_MBR_UID_TO_UUID
4123 * Use Apple membership APIs which require that all names represent
4124 * valid user account or group records accessible by the server.
4127 uuid_t usr_uuid
; /* UUID for job requesting user */
4128 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4129 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4130 int mbr_err
; /* Error from membership function */
4131 int is_member
; /* Is this user a member? */
4134 * Use standard POSIX APIs for checking users and groups...
4137 struct passwd
*pw
; /* User password data */
4138 #endif /* HAVE_MBR_UID_TO_UUID */
4141 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4142 con
, con
->http
.fd
, p
, p
->name
);
4145 * Figure out who is printing...
4148 strlcpy(username
, get_username(con
), sizeof(username
));
4151 * Check global active job limits for printers and users...
4154 if (MaxJobsPerPrinter
)
4157 * Check if there are too many pending jobs on this printer...
4160 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4162 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4171 * Check if there are too many pending jobs for this user...
4174 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4176 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4183 * Check against users...
4186 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4191 #ifdef HAVE_MBR_UID_TO_UUID
4193 * Get UUID for job requesting user...
4196 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4202 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4203 "check_quotas: UUID lookup failed for user \"%s\"",
4205 cupsdLogMessage(CUPSD_LOG_INFO
,
4206 "Denying user \"%s\" access to printer \"%s\" "
4207 "(unknown user)...",
4213 * Get UID and GID of requesting user...
4216 pw
= getpwnam(username
);
4218 #endif /* HAVE_MBR_UID_TO_UUID */
4220 for (i
= 0; i
< p
->num_users
; i
++)
4221 if (p
->users
[i
][0] == '@')
4224 * Check group membership...
4227 #ifdef HAVE_MBR_UID_TO_UUID
4228 if (p
->users
[i
][1] == '#')
4230 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4231 uuid_clear(grp_uuid
);
4233 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4237 * Invalid ACL entries are ignored for matching; just record a
4238 * warning in the log...
4241 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4242 "check_quotas: UUID lookup failed for ACL entry "
4243 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4244 cupsdLogMessage(CUPSD_LOG_WARN
,
4245 "Access control entry \"%s\" not a valid group name; "
4246 "entry ignored", p
->users
[i
]);
4249 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4253 * At this point, there should be no errors, but check anyways...
4256 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4257 "check_quotas: group \"%s\" membership check "
4258 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4263 * Stop if we found a match...
4270 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4272 #endif /* HAVE_MBR_UID_TO_UUID */
4274 #ifdef HAVE_MBR_UID_TO_UUID
4277 if (p
->users
[i
][0] == '#')
4279 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4280 uuid_clear(usr2_uuid
);
4282 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4286 * Invalid ACL entries are ignored for matching; just record a
4287 * warning in the log...
4290 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4291 "check_quotas: UUID lookup failed for ACL entry "
4292 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4293 cupsdLogMessage(CUPSD_LOG_WARN
,
4294 "Access control entry \"%s\" not a valid user name; "
4295 "entry ignored", p
->users
[i
]);
4298 if ((mbr_err
= mbr_check_membership(usr_uuid
, usr2_uuid
,
4301 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4302 "check_quotas: User \"%s\" identity check failed "
4303 "(err=%d)", p
->users
[i
], mbr_err
);
4311 else if (!strcasecmp(username
, p
->users
[i
]))
4313 #endif /* HAVE_MBR_UID_TO_UUID */
4315 if ((i
< p
->num_users
) == p
->deny_users
)
4317 cupsdLogMessage(CUPSD_LOG_INFO
,
4318 "Denying user \"%s\" access to printer \"%s\"...",
4329 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4332 * TODO: Define these special page count values as constants!
4335 if (q
->page_count
== -4) /* special case: unlimited user */
4337 cupsdLogMessage(CUPSD_LOG_INFO
,
4338 "User \"%s\" request approved for printer %s (%s): "
4340 username
, p
->name
, p
->info
);
4341 q
->page_count
= 0; /* allow user to print */
4344 else if (q
->page_count
== -3) /* quota exceeded */
4346 cupsdLogMessage(CUPSD_LOG_INFO
,
4347 "User \"%s\" request denied for printer %s (%s): "
4348 "quota limit exceeded.",
4349 username
, p
->name
, p
->info
);
4350 q
->page_count
= 2; /* force quota exceeded failure */
4353 else if (q
->page_count
== -2) /* quota disabled for user */
4355 cupsdLogMessage(CUPSD_LOG_INFO
,
4356 "User \"%s\" request denied for printer %s (%s): "
4357 "printing disabled for user.",
4358 username
, p
->name
, p
->info
);
4359 q
->page_count
= 2; /* force quota exceeded failure */
4362 else if (q
->page_count
== -1) /* quota access error */
4364 cupsdLogMessage(CUPSD_LOG_INFO
,
4365 "User \"%s\" request denied for printer %s (%s): "
4366 "unable to determine quota limit.",
4367 username
, p
->name
, p
->info
);
4368 q
->page_count
= 2; /* force quota exceeded failure */
4371 else if (q
->page_count
< 0) /* user not found or other error */
4373 cupsdLogMessage(CUPSD_LOG_INFO
,
4374 "User \"%s\" request denied for printer %s (%s): "
4375 "user disabled / missing quota.",
4376 username
, p
->name
, p
->info
);
4377 q
->page_count
= 2; /* force quota exceeded failure */
4380 else /* page within user limits */
4382 q
->page_count
= 0; /* allow user to print */
4387 #endif /* __APPLE__ */
4388 if (p
->k_limit
|| p
->page_limit
)
4390 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4392 cupsdLogMessage(CUPSD_LOG_ERROR
,
4393 "Unable to allocate quota data for user \"%s\"!",
4398 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4399 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4401 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4408 * If we have gotten this far, we're done!
4416 * 'copy_attribute()' - Copy a single attribute.
4419 static ipp_attribute_t
* /* O - New attribute */
4421 ipp_t
*to
, /* O - Destination request/response */
4422 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4423 int quickcopy
) /* I - Do a quick copy? */
4425 int i
; /* Looping var */
4426 ipp_attribute_t
*toattr
; /* Destination attribute */
4429 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4430 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4431 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4434 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4437 toattr
= ippAddSeparator(to
);
4440 case IPP_TAG_INTEGER
:
4442 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4443 attr
->name
, attr
->num_values
, NULL
);
4445 for (i
= 0; i
< attr
->num_values
; i
++)
4446 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4449 case IPP_TAG_BOOLEAN
:
4450 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4451 attr
->num_values
, NULL
);
4453 for (i
= 0; i
< attr
->num_values
; i
++)
4454 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4457 case IPP_TAG_STRING
:
4460 case IPP_TAG_KEYWORD
:
4462 case IPP_TAG_URISCHEME
:
4463 case IPP_TAG_CHARSET
:
4464 case IPP_TAG_LANGUAGE
:
4465 case IPP_TAG_MIMETYPE
:
4466 toattr
= ippAddStrings(to
, attr
->group_tag
,
4467 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4468 attr
->name
, attr
->num_values
, NULL
, NULL
);
4472 for (i
= 0; i
< attr
->num_values
; i
++)
4473 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4477 for (i
= 0; i
< attr
->num_values
; i
++)
4478 toattr
->values
[i
].string
.text
=
4479 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4484 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4485 attr
->values
[0].date
);
4488 case IPP_TAG_RESOLUTION
:
4489 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4490 attr
->num_values
, IPP_RES_PER_INCH
,
4493 for (i
= 0; i
< attr
->num_values
; i
++)
4495 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4496 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4497 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4501 case IPP_TAG_RANGE
:
4502 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4503 attr
->num_values
, NULL
, NULL
);
4505 for (i
= 0; i
< attr
->num_values
; i
++)
4507 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4508 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4512 case IPP_TAG_TEXTLANG
:
4513 case IPP_TAG_NAMELANG
:
4514 toattr
= ippAddStrings(to
, attr
->group_tag
,
4515 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4516 attr
->name
, attr
->num_values
, NULL
, NULL
);
4520 for (i
= 0; i
< attr
->num_values
; i
++)
4522 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4523 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4528 for (i
= 0; i
< attr
->num_values
; i
++)
4531 toattr
->values
[i
].string
.charset
=
4532 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4534 toattr
->values
[i
].string
.charset
=
4535 toattr
->values
[0].string
.charset
;
4537 toattr
->values
[i
].string
.text
=
4538 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4543 case IPP_TAG_BEGIN_COLLECTION
:
4544 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4545 attr
->num_values
, NULL
);
4547 for (i
= 0; i
< attr
->num_values
; i
++)
4549 toattr
->values
[i
].collection
= ippNew();
4550 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4551 NULL
, IPP_TAG_ZERO
, 0);
4556 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4557 attr
->name
, attr
->num_values
, NULL
);
4559 for (i
= 0; i
< attr
->num_values
; i
++)
4561 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4563 if (toattr
->values
[i
].unknown
.length
> 0)
4565 if ((toattr
->values
[i
].unknown
.data
=
4566 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4567 toattr
->values
[i
].unknown
.length
= 0;
4569 memcpy(toattr
->values
[i
].unknown
.data
,
4570 attr
->values
[i
].unknown
.data
,
4571 toattr
->values
[i
].unknown
.length
);
4574 break; /* anti-compiler-warning-code */
4582 * 'copy_attrs()' - Copy attributes from one request to another.
4586 copy_attrs(ipp_t
*to
, /* I - Destination request */
4587 ipp_t
*from
, /* I - Source request */
4588 cups_array_t
*ra
, /* I - Requested attributes */
4589 ipp_tag_t group
, /* I - Group to copy */
4590 int quickcopy
) /* I - Do a quick copy? */
4592 ipp_attribute_t
*fromattr
; /* Source attribute */
4595 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4596 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4597 to
, from
, ra
, group
, quickcopy
);
4602 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4605 * Filter attributes as needed...
4608 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4609 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4612 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4613 copy_attribute(to
, fromattr
, quickcopy
);
4619 * 'copy_banner()' - Copy a banner file to the requests directory for the
4623 static int /* O - Size of banner file in kbytes */
4624 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4625 cupsd_job_t
*job
, /* I - Job information */
4626 const char *name
) /* I - Name of banner */
4628 int i
; /* Looping var */
4629 int kbytes
; /* Size of banner file in kbytes */
4630 char filename
[1024]; /* Job filename */
4631 cupsd_banner_t
*banner
; /* Pointer to banner */
4632 cups_file_t
*in
; /* Input file */
4633 cups_file_t
*out
; /* Output file */
4634 int ch
; /* Character from file */
4635 char attrname
[255], /* Name of attribute */
4636 *s
; /* Pointer into name */
4637 ipp_attribute_t
*attr
; /* Attribute */
4640 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4641 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4642 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4643 name
? name
: "(null)");
4646 * Find the banner; return if not found or "none"...
4649 if (!name
|| !strcmp(name
, "none") ||
4650 (banner
= cupsdFindBanner(name
)) == NULL
)
4654 * Open the banner and job files...
4657 if (add_file(con
, job
, banner
->filetype
, 0))
4660 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4662 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4664 cupsdLogMessage(CUPSD_LOG_ERROR
,
4665 "Unable to create banner job file %s - %s",
4666 filename
, strerror(errno
));
4671 fchmod(cupsFileNumber(out
), 0640);
4672 fchown(cupsFileNumber(out
), RunUser
, Group
);
4675 * Try the localized banner file under the subdirectory...
4678 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4680 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4683 * Convert ll-cc to ll_CC...
4687 attrname
[3] = toupper(attrname
[3] & 255);
4688 attrname
[4] = toupper(attrname
[4] & 255);
4691 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4694 if (access(filename
, 0) && strlen(attrname
) > 2)
4697 * Wasn't able to find "ll_CC" locale file; try the non-national
4698 * localization banner directory.
4703 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4707 if (access(filename
, 0))
4710 * Use the non-localized banner file.
4713 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4716 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4720 cupsdLogMessage(CUPSD_LOG_ERROR
,
4721 "Unable to open banner template file %s - %s",
4722 filename
, strerror(errno
));
4728 * Parse the file to the end...
4731 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4735 * Get an attribute name...
4738 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4739 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4741 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4751 * Ignore { followed by stuff that is not an attribute name...
4754 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4759 * See if it is defined...
4762 if (attrname
[0] == '?')
4767 if (!strcmp(s
, "printer-name"))
4769 cupsFilePuts(out
, job
->dest
);
4772 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4775 * See if we have a leading question mark...
4778 if (attrname
[0] != '?')
4781 * Nope, write to file as-is; probably a PostScript procedure...
4784 cupsFilePrintf(out
, "{%s}", attrname
);
4791 * Output value(s)...
4794 for (i
= 0; i
< attr
->num_values
; i
++)
4797 cupsFilePutChar(out
, ',');
4799 switch (attr
->value_tag
)
4801 case IPP_TAG_INTEGER
:
4803 if (!strncmp(s
, "time-at-", 8))
4804 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
4806 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4809 case IPP_TAG_BOOLEAN
:
4810 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4813 case IPP_TAG_NOVALUE
:
4814 cupsFilePuts(out
, "novalue");
4817 case IPP_TAG_RANGE
:
4818 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4819 attr
->values
[i
].range
.upper
);
4822 case IPP_TAG_RESOLUTION
:
4823 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4824 attr
->values
[i
].resolution
.yres
,
4825 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4830 case IPP_TAG_STRING
:
4833 case IPP_TAG_KEYWORD
:
4834 case IPP_TAG_CHARSET
:
4835 case IPP_TAG_LANGUAGE
:
4836 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4839 * Need to quote strings for PS banners...
4844 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4846 if (*p
== '(' || *p
== ')' || *p
== '\\')
4848 cupsFilePutChar(out
, '\\');
4849 cupsFilePutChar(out
, *p
);
4851 else if (*p
< 32 || *p
> 126)
4852 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4854 cupsFilePutChar(out
, *p
);
4858 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4862 break; /* anti-compiler-warning-code */
4866 else if (ch
== '\\') /* Quoted char */
4868 ch
= cupsFileGetChar(in
);
4870 if (ch
!= '{') /* Only do special handling for \{ */
4871 cupsFilePutChar(out
, '\\');
4873 cupsFilePutChar(out
, ch
);
4876 cupsFilePutChar(out
, ch
);
4880 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4882 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4883 IPP_TAG_INTEGER
)) != NULL
)
4884 attr
->values
[0].integer
+= kbytes
;
4893 * 'copy_file()' - Copy a PPD file or interface script...
4896 static int /* O - 0 = success, -1 = error */
4897 copy_file(const char *from
, /* I - Source file */
4898 const char *to
) /* I - Destination file */
4900 cups_file_t
*src
, /* Source file */
4901 *dst
; /* Destination file */
4902 int bytes
; /* Bytes to read/write */
4903 char buffer
[2048]; /* Copy buffer */
4906 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4909 * Open the source and destination file for a copy...
4912 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4915 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4922 * Copy the source file to the destination...
4925 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4926 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
4934 * Close both files and return...
4939 return (cupsFileClose(dst
));
4944 * 'copy_model()' - Copy a PPD model file, substituting default values
4948 static int /* O - 0 = success, -1 = error */
4949 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4950 const char *from
, /* I - Source file */
4951 const char *to
) /* I - Destination file */
4953 fd_set input
; /* select() input set */
4954 struct timeval timeout
; /* select() timeout */
4955 int maxfd
; /* Max file descriptor for select() */
4956 char tempfile
[1024]; /* Temporary PPD file */
4957 int tempfd
; /* Temporary PPD file descriptor */
4958 int temppid
; /* Process ID of cups-driverd */
4959 int temppipe
[2]; /* Temporary pipes */
4960 char *argv
[4], /* Command-line arguments */
4961 *envp
[MAX_ENV
]; /* Environment */
4962 cups_file_t
*src
, /* Source file */
4963 *dst
; /* Destination file */
4964 ppd_file_t
*ppd
; /* PPD file */
4965 int bytes
, /* Bytes from pipe */
4966 total
; /* Total bytes from pipe */
4967 char buffer
[2048]; /* Copy buffer */
4968 int i
; /* Looping var */
4969 char option
[PPD_MAX_NAME
], /* Option name */
4970 choice
[PPD_MAX_NAME
]; /* Choice name */
4971 int num_defaults
; /* Number of default options */
4972 cups_option_t
*defaults
; /* Default options */
4973 char cups_protocol
[PPD_MAX_LINE
];
4974 /* cupsProtocol attribute */
4975 int have_letter
, /* Have Letter size */
4976 have_a4
; /* Have A4 size */
4977 #ifdef HAVE_LIBPAPER
4978 char *paper_result
; /* Paper size name from libpaper */
4979 char system_paper
[64]; /* Paper size name buffer */
4980 #endif /* HAVE_LIBPAPER */
4983 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4984 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4988 * Run cups-driverd to get the PPD file...
4991 argv
[0] = "cups-driverd";
4993 argv
[2] = (char *)from
;
4996 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4998 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4999 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
5000 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5004 cupsdOpenPipe(temppipe
);
5006 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5007 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5009 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5010 -1, -1, 0, DefaultProfile
, &temppid
))
5021 * Wait up to 30 seconds for the PPD file to be copied...
5026 if (temppipe
[0] > CGIPipes
[0])
5027 maxfd
= temppipe
[0] + 1;
5029 maxfd
= CGIPipes
[0] + 1;
5034 * See if we have data ready...
5038 FD_SET(temppipe
[0], &input
);
5039 FD_SET(CGIPipes
[0], &input
);
5041 timeout
.tv_sec
= 30;
5042 timeout
.tv_usec
= 0;
5044 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5054 * We have timed out...
5060 if (FD_ISSET(temppipe
[0], &input
))
5063 * Read the PPD file from the pipe, and write it to the PPD file.
5066 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5068 if (write(tempfd
, buffer
, bytes
) < bytes
)
5077 if (FD_ISSET(CGIPipes
[0], &input
))
5087 * No data from cups-deviced...
5090 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5096 * Read the source file and see what page sizes are supported...
5099 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5105 have_letter
= ppdPageSize(ppd
, "Letter") != NULL
;
5106 have_a4
= ppdPageSize(ppd
, "A4") != NULL
;
5109 * Open the destination (if possible) and set the default options...
5114 cups_protocol
[0] = '\0';
5116 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5119 * Read all of the default lines from the old PPD...
5122 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5123 if (!strncmp(buffer
, "*Default", 8))
5126 * Add the default option...
5129 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5130 choice
, sizeof(choice
)))
5132 ppd_option_t
*ppdo
; /* PPD option */
5136 * Only add the default if the default hasn't already been
5137 * set and the choice exists in the new PPD...
5140 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5141 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5142 ppdFindChoice(ppdo
, choice
))
5143 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5147 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5148 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5152 #ifdef HAVE_LIBPAPER
5153 else if ((paper_result
= systempapername()) != NULL
)
5156 * Set the default media sizes from the systemwide default...
5159 strlcpy(system_paper
, paper_result
, sizeof(system_paper
));
5160 system_paper
[0] = toupper(system_paper
[0] & 255);
5162 if ((!strcmp(system_paper
, "Letter") && have_letter
) ||
5163 (!strcmp(system_paper
, "A4") && have_a4
))
5165 num_defaults
= cupsAddOption("PageSize", system_paper
,
5166 num_defaults
, &defaults
);
5167 num_defaults
= cupsAddOption("PageRegion", system_paper
,
5168 num_defaults
, &defaults
);
5169 num_defaults
= cupsAddOption("PaperDimension", system_paper
,
5170 num_defaults
, &defaults
);
5171 num_defaults
= cupsAddOption("ImageableArea", system_paper
,
5172 num_defaults
, &defaults
);
5175 #endif /* HAVE_LIBPAPER */
5179 * Add the default media sizes...
5181 * Note: These values are generally not valid for large-format devices
5182 * like plotters, however it is probably safe to say that those
5183 * users will configure the media size after initially adding
5184 * the device anyways...
5187 if (!DefaultLanguage
||
5188 !strcasecmp(DefaultLanguage
, "C") ||
5189 !strcasecmp(DefaultLanguage
, "POSIX") ||
5190 !strcasecmp(DefaultLanguage
, "en") ||
5191 !strncasecmp(DefaultLanguage
, "en.", 3) ||
5192 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
5193 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
5194 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
5197 * These are the only locales that will default to "letter" size...
5202 num_defaults
= cupsAddOption("PageSize", "Letter", num_defaults
,
5204 num_defaults
= cupsAddOption("PageRegion", "Letter", num_defaults
,
5206 num_defaults
= cupsAddOption("PaperDimension", "Letter", num_defaults
,
5208 num_defaults
= cupsAddOption("ImageableArea", "Letter", num_defaults
,
5215 * The rest default to "a4" size...
5218 num_defaults
= cupsAddOption("PageSize", "A4", num_defaults
,
5220 num_defaults
= cupsAddOption("PageRegion", "A4", num_defaults
,
5222 num_defaults
= cupsAddOption("PaperDimension", "A4", num_defaults
,
5224 num_defaults
= cupsAddOption("ImageableArea", "A4", num_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-more-info"))
5328 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5329 "job-more-info", NULL
, job_uri
);
5331 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5332 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5333 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5334 job
->num_files
> 0);
5336 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5337 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5338 "job-printer-up-time", time(NULL
));
5340 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5341 add_job_state_reasons(con
, job
);
5343 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5344 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5345 "job-uri", NULL
, job_uri
);
5347 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5352 * 'copy_printer_attrs()' - Copy printer attributes.
5357 cupsd_client_t
*con
, /* I - Client connection */
5358 cupsd_printer_t
*printer
, /* I - Printer */
5359 cups_array_t
*ra
) /* I - Requested attributes array */
5361 char printer_uri
[HTTP_MAX_URI
];
5363 time_t curtime
; /* Current time */
5364 int i
; /* Looping var */
5365 ipp_attribute_t
*history
; /* History collection */
5369 * Copy the printer attributes to the response using requested-attributes
5370 * and document-format attributes that may be provided by the client.
5373 curtime
= time(NULL
);
5376 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5377 printer
->recoverable
)
5378 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5379 "com.apple.print.recoverable-message", NULL
,
5380 printer
->recoverable
);
5381 #endif /* __APPLE__ */
5383 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5384 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5385 "marker-change-time", printer
->marker_time
);
5387 if (printer
->num_printers
> 0 &&
5388 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5390 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5391 cupsd_printer_t
*p2
; /* Printer in class */
5392 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5395 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5396 IPP_TAG_URI
, "member-uris",
5397 printer
->num_printers
, NULL
,
5400 for (i
= 0; i
< printer
->num_printers
; i
++)
5402 p2
= printer
->printers
[i
];
5404 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5405 IPP_TAG_URI
)) != NULL
)
5406 member_uris
->values
[i
].string
.text
=
5407 _cupsStrAlloc(p2_uri
->values
[0].string
.text
);
5410 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5411 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5413 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5414 "/classes/%s" : "/printers/%s", p2
->name
);
5415 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5421 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5422 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5423 "printer-alert", NULL
, printer
->alert
);
5425 if (printer
->alert_description
&&
5426 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5427 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5428 "printer-alert-description", NULL
,
5429 printer
->alert_description
);
5431 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5432 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5433 ippTimeToDate(curtime
));
5436 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5438 if (printer
->reg_name
)
5439 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5440 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5442 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5443 "printer-dns-sd-name", 0);
5445 #endif /* HAVE_DNSSD */
5447 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5448 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5449 "printer-error-policy", NULL
, printer
->error_policy
);
5451 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5452 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5453 printer
->accepting
);
5455 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5456 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5459 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5460 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5461 "printer-op-policy", NULL
, printer
->op_policy
);
5463 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5464 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5467 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5468 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5469 "printer-state-change-time", printer
->state_time
);
5471 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5472 cupsArrayFind(ra
, "printer-state-history"))
5475 * Printer history is only sent if specifically requested, so that
5476 * older CUPS/IPP clients won't barf on the collection attributes.
5479 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5480 "printer-state-history",
5481 printer
->num_history
, NULL
);
5483 for (i
= 0; i
< printer
->num_history
; i
++)
5484 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5485 NULL
, IPP_TAG_ZERO
, 0);
5488 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5489 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5490 "printer-state-message", NULL
, printer
->state_message
);
5492 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5493 add_printer_state_reasons(con
, printer
);
5495 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5497 int type
; /* printer-type value */
5501 * Add the CUPS-specific printer-type attribute...
5504 type
= printer
->type
;
5506 if (printer
== DefaultPrinter
)
5507 type
|= CUPS_PRINTER_DEFAULT
;
5509 if (!printer
->accepting
)
5510 type
|= CUPS_PRINTER_REJECTING
;
5512 if (!printer
->shared
)
5513 type
|= CUPS_PRINTER_NOT_SHARED
;
5515 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5519 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5520 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5521 "printer-up-time", curtime
);
5523 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5524 !ippFindAttribute(printer
->attrs
, "printer-uri-supported",
5527 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5528 "ipp", NULL
, con
->servername
, con
->serverport
,
5529 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5530 "/classes/%s" : "/printers/%s", printer
->name
);
5531 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5532 "printer-uri-supported", NULL
, printer_uri
);
5533 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5537 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5538 add_queued_job_count(con
, printer
);
5540 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5541 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5546 * 'copy_subscription_attrs()' - Copy subscription attributes.
5550 copy_subscription_attrs(
5551 cupsd_client_t
*con
, /* I - Client connection */
5552 cupsd_subscription_t
*sub
, /* I - Subscription */
5553 cups_array_t
*ra
) /* I - Requested attributes array */
5555 ipp_attribute_t
*attr
; /* Current attribute */
5556 char printer_uri
[HTTP_MAX_URI
];
5558 int count
; /* Number of events */
5559 unsigned mask
; /* Current event mask */
5560 const char *name
; /* Current event name */
5564 * Copy the subscription attributes to the response using the
5565 * requested-attributes attribute that may be provided by the client.
5568 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5570 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5573 * Simple event list...
5576 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5577 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5578 "notify-events", NULL
, name
);
5583 * Complex event list...
5586 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5587 if (sub
->mask
& mask
)
5590 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5591 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5592 "notify-events", count
, NULL
, NULL
);
5594 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5595 if (sub
->mask
& mask
)
5597 attr
->values
[count
].string
.text
=
5598 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5605 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5606 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5607 "notify-job-id", sub
->job
->id
);
5609 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5610 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5611 "notify-lease-duration", sub
->lease
);
5613 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5615 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5616 "ipp", NULL
, con
->servername
, con
->serverport
,
5617 "/printers/%s", sub
->dest
->name
);
5618 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5619 "notify-printer-uri", NULL
, printer_uri
);
5622 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5623 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5624 "notify-recipient-uri", NULL
, sub
->recipient
);
5625 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5626 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5627 "notify-pull-method", NULL
, "ippget");
5629 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5630 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5631 "notify-subscriber-user-name", NULL
, sub
->owner
);
5633 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5634 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5635 "notify-subscription-id", sub
->id
);
5637 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5638 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5639 "notify-time-interval", sub
->interval
);
5641 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5642 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5643 sub
->user_data
, sub
->user_data_len
);
5648 * 'create_job()' - Print a file to a printer or class.
5652 create_job(cupsd_client_t
*con
, /* I - Client connection */
5653 ipp_attribute_t
*uri
) /* I - Printer URI */
5655 cupsd_printer_t
*printer
; /* Printer */
5656 cupsd_job_t
*job
; /* New job */
5659 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5660 con
->http
.fd
, uri
->values
[0].string
.text
);
5663 * Is the destination valid?
5666 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5672 send_ipp_status(con
, IPP_NOT_FOUND
,
5673 _("The printer or class was not found."));
5678 * Create the job object...
5681 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5684 job
->pending_timeout
= 1;
5687 * Save and log the job...
5690 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5691 job
->dest
, job
->username
);
5696 * 'create_requested_array()' - Create an array for the requested-attributes.
5699 static cups_array_t
* /* O - Array of attributes or NULL */
5700 create_requested_array(ipp_t
*request
) /* I - IPP request */
5702 int i
; /* Looping var */
5703 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5704 cups_array_t
*ra
; /* Requested attributes array */
5705 char *value
; /* Current value */
5709 * Get the requested-attributes attribute, and return NULL if we don't
5713 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5714 IPP_TAG_KEYWORD
)) == NULL
)
5718 * If the attribute contains a single "all" keyword, return NULL...
5721 if (requested
->num_values
== 1 &&
5722 !strcmp(requested
->values
[0].string
.text
, "all"))
5726 * Create an array using "strcmp" as the comparison function...
5729 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5731 for (i
= 0; i
< requested
->num_values
; i
++)
5733 value
= requested
->values
[i
].string
.text
;
5735 if (!strcmp(value
, "job-template"))
5737 cupsArrayAdd(ra
, "copies");
5738 cupsArrayAdd(ra
, "copies-default");
5739 cupsArrayAdd(ra
, "copies-supported");
5740 cupsArrayAdd(ra
, "finishings");
5741 cupsArrayAdd(ra
, "finishings-default");
5742 cupsArrayAdd(ra
, "finishings-supported");
5743 cupsArrayAdd(ra
, "job-hold-until");
5744 cupsArrayAdd(ra
, "job-hold-until-default");
5745 cupsArrayAdd(ra
, "job-hold-until-supported");
5746 cupsArrayAdd(ra
, "job-priority");
5747 cupsArrayAdd(ra
, "job-priority-default");
5748 cupsArrayAdd(ra
, "job-priority-supported");
5749 cupsArrayAdd(ra
, "job-sheets");
5750 cupsArrayAdd(ra
, "job-sheets-default");
5751 cupsArrayAdd(ra
, "job-sheets-supported");
5752 cupsArrayAdd(ra
, "media");
5753 cupsArrayAdd(ra
, "media-default");
5754 cupsArrayAdd(ra
, "media-supported");
5755 cupsArrayAdd(ra
, "multiple-document-handling");
5756 cupsArrayAdd(ra
, "multiple-document-handling-default");
5757 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5758 cupsArrayAdd(ra
, "number-up");
5759 cupsArrayAdd(ra
, "number-up-default");
5760 cupsArrayAdd(ra
, "number-up-supported");
5761 cupsArrayAdd(ra
, "orientation-requested");
5762 cupsArrayAdd(ra
, "orientation-requested-default");
5763 cupsArrayAdd(ra
, "orientation-requested-supported");
5764 cupsArrayAdd(ra
, "page-ranges");
5765 cupsArrayAdd(ra
, "page-ranges-supported");
5766 cupsArrayAdd(ra
, "printer-resolution");
5767 cupsArrayAdd(ra
, "printer-resolution-default");
5768 cupsArrayAdd(ra
, "printer-resolution-supported");
5769 cupsArrayAdd(ra
, "print-quality");
5770 cupsArrayAdd(ra
, "print-quality-default");
5771 cupsArrayAdd(ra
, "print-quality-supported");
5772 cupsArrayAdd(ra
, "sides");
5773 cupsArrayAdd(ra
, "sides-default");
5774 cupsArrayAdd(ra
, "sides-supported");
5776 else if (!strcmp(value
, "job-description"))
5778 cupsArrayAdd(ra
, "date-time-at-completed");
5779 cupsArrayAdd(ra
, "date-time-at-creation");
5780 cupsArrayAdd(ra
, "date-time-at-processing");
5781 cupsArrayAdd(ra
, "job-detailed-status-message");
5782 cupsArrayAdd(ra
, "job-document-access-errors");
5783 cupsArrayAdd(ra
, "job-id");
5784 cupsArrayAdd(ra
, "job-impressions");
5785 cupsArrayAdd(ra
, "job-impressions-completed");
5786 cupsArrayAdd(ra
, "job-k-octets");
5787 cupsArrayAdd(ra
, "job-k-octets-processed");
5788 cupsArrayAdd(ra
, "job-media-sheets");
5789 cupsArrayAdd(ra
, "job-media-sheets-completed");
5790 cupsArrayAdd(ra
, "job-message-from-operator");
5791 cupsArrayAdd(ra
, "job-more-info");
5792 cupsArrayAdd(ra
, "job-name");
5793 cupsArrayAdd(ra
, "job-originating-user-name");
5794 cupsArrayAdd(ra
, "job-printer-up-time");
5795 cupsArrayAdd(ra
, "job-printer-uri");
5796 cupsArrayAdd(ra
, "job-state");
5797 cupsArrayAdd(ra
, "job-state-message");
5798 cupsArrayAdd(ra
, "job-state-reasons");
5799 cupsArrayAdd(ra
, "job-uri");
5800 cupsArrayAdd(ra
, "number-of-documents");
5801 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5802 cupsArrayAdd(ra
, "output-device-assigned");
5803 cupsArrayAdd(ra
, "time-at-completed");
5804 cupsArrayAdd(ra
, "time-at-creation");
5805 cupsArrayAdd(ra
, "time-at-processing");
5807 else if (!strcmp(value
, "printer-description"))
5809 cupsArrayAdd(ra
, "charset-configured");
5810 cupsArrayAdd(ra
, "charset-supported");
5811 cupsArrayAdd(ra
, "color-supported");
5812 cupsArrayAdd(ra
, "compression-supported");
5813 cupsArrayAdd(ra
, "document-format-default");
5814 cupsArrayAdd(ra
, "document-format-supported");
5815 cupsArrayAdd(ra
, "generated-natural-language-supported");
5816 cupsArrayAdd(ra
, "ipp-versions-supported");
5817 cupsArrayAdd(ra
, "job-impressions-supported");
5818 cupsArrayAdd(ra
, "job-k-octets-supported");
5819 cupsArrayAdd(ra
, "job-media-sheets-supported");
5820 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5821 cupsArrayAdd(ra
, "multiple-operation-time-out");
5822 cupsArrayAdd(ra
, "natural-language-configured");
5823 cupsArrayAdd(ra
, "notify-attributes-supported");
5824 cupsArrayAdd(ra
, "notify-lease-duration-default");
5825 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5826 cupsArrayAdd(ra
, "notify-max-events-supported");
5827 cupsArrayAdd(ra
, "notify-events-default");
5828 cupsArrayAdd(ra
, "notify-events-supported");
5829 cupsArrayAdd(ra
, "notify-pull-method-supported");
5830 cupsArrayAdd(ra
, "notify-schemes-supported");
5831 cupsArrayAdd(ra
, "operations-supported");
5832 cupsArrayAdd(ra
, "pages-per-minute");
5833 cupsArrayAdd(ra
, "pages-per-minute-color");
5834 cupsArrayAdd(ra
, "pdl-override-supported");
5835 cupsArrayAdd(ra
, "printer-alert");
5836 cupsArrayAdd(ra
, "printer-alert-description");
5837 cupsArrayAdd(ra
, "printer-commands");
5838 cupsArrayAdd(ra
, "printer-current-time");
5839 cupsArrayAdd(ra
, "printer-driver-installer");
5840 cupsArrayAdd(ra
, "printer-dns-sd-name");
5841 cupsArrayAdd(ra
, "printer-info");
5842 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5843 cupsArrayAdd(ra
, "printer-location");
5844 cupsArrayAdd(ra
, "printer-make-and-model");
5845 cupsArrayAdd(ra
, "printer-message-from-operator");
5846 cupsArrayAdd(ra
, "printer-more-info");
5847 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5848 cupsArrayAdd(ra
, "printer-name");
5849 cupsArrayAdd(ra
, "printer-state");
5850 cupsArrayAdd(ra
, "printer-state-message");
5851 cupsArrayAdd(ra
, "printer-state-reasons");
5852 cupsArrayAdd(ra
, "printer-type");
5853 cupsArrayAdd(ra
, "printer-up-time");
5854 cupsArrayAdd(ra
, "printer-uri-supported");
5855 cupsArrayAdd(ra
, "queued-job-count");
5856 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5857 cupsArrayAdd(ra
, "uri-authentication-supported");
5858 cupsArrayAdd(ra
, "uri-security-supported");
5860 else if (!strcmp(value
, "printer-defaults"))
5862 char *name
; /* Option name */
5865 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5867 name
= (char *)cupsArrayNext(CommonDefaults
))
5868 cupsArrayAdd(ra
, name
);
5870 else if (!strcmp(value
, "subscription-template"))
5872 cupsArrayAdd(ra
, "notify-attributes");
5873 cupsArrayAdd(ra
, "notify-charset");
5874 cupsArrayAdd(ra
, "notify-events");
5875 cupsArrayAdd(ra
, "notify-lease-duration");
5876 cupsArrayAdd(ra
, "notify-natural-language");
5877 cupsArrayAdd(ra
, "notify-pull-method");
5878 cupsArrayAdd(ra
, "notify-recipient-uri");
5879 cupsArrayAdd(ra
, "notify-time-interval");
5880 cupsArrayAdd(ra
, "notify-user-data");
5883 cupsArrayAdd(ra
, value
);
5891 * 'create_subscription()' - Create a notification subscription.
5895 create_subscription(
5896 cupsd_client_t
*con
, /* I - Client connection */
5897 ipp_attribute_t
*uri
) /* I - Printer URI */
5899 http_status_t status
; /* Policy status */
5900 int i
; /* Looping var */
5901 ipp_attribute_t
*attr
; /* Current attribute */
5902 cups_ptype_t dtype
; /* Destination type (printer/class) */
5903 char scheme
[HTTP_MAX_URI
],
5904 /* Scheme portion of URI */
5905 userpass
[HTTP_MAX_URI
],
5906 /* Username portion of URI */
5908 /* Host portion of URI */
5909 resource
[HTTP_MAX_URI
];
5910 /* Resource portion of URI */
5911 int port
; /* Port portion of URI */
5912 cupsd_printer_t
*printer
; /* Printer/class */
5913 cupsd_job_t
*job
; /* Job */
5914 int jobid
; /* Job ID */
5915 cupsd_subscription_t
*sub
; /* Subscription object */
5916 const char *username
, /* requesting-user-name or
5917 authenticated username */
5918 *recipient
, /* notify-recipient-uri */
5919 *pullmethod
; /* notify-pull-method */
5920 ipp_attribute_t
*user_data
; /* notify-user-data */
5921 int interval
, /* notify-time-interval */
5922 lease
; /* notify-lease-duration */
5923 unsigned mask
; /* notify-events */
5924 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5925 *notify_lease
; /* notify-lease-duration(-default) */
5929 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5931 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5932 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5933 attr
->value_tag
, attr
->name
);
5935 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5940 * Is the destination valid?
5943 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5944 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5945 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5947 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5948 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5949 sizeof(host
), &port
, resource
, sizeof(resource
));
5951 if (!strcmp(resource
, "/"))
5953 dtype
= (cups_ptype_t
)0;
5956 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5958 dtype
= (cups_ptype_t
)0;
5961 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5963 dtype
= CUPS_PRINTER_CLASS
;
5966 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5972 send_ipp_status(con
, IPP_NOT_FOUND
,
5973 _("The printer or class was not found."));
5983 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5986 send_http_error(con
, status
, printer
);
5990 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5992 send_http_error(con
, status
, NULL
);
5997 * Get the user that is requesting the subscription...
6000 username
= get_username(con
);
6003 * Find the first subscription group attribute; return if we have
6007 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6008 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6013 send_ipp_status(con
, IPP_BAD_REQUEST
,
6014 _("No subscription attributes in request!"));
6019 * Process the subscription attributes in the request...
6022 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6030 lease
= DefaultLeaseDuration
;
6032 mask
= CUPSD_EVENT_NONE
;
6036 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6038 notify_lease
= ippFindAttribute(printer
->attrs
,
6039 "notify-lease-duration-default",
6043 lease
= notify_lease
->values
[0].integer
;
6047 notify_events
= NULL
;
6048 notify_lease
= NULL
;
6051 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6053 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6054 attr
->value_tag
== IPP_TAG_URI
)
6057 * Validate the recipient scheme against the ServerBin/notifier
6061 char notifier
[1024]; /* Notifier filename */
6064 recipient
= attr
->values
[0].string
.text
;
6066 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6067 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6068 host
, sizeof(host
), &port
,
6069 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6071 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6072 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6073 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6074 "notify-status-code", IPP_URI_SCHEME
);
6078 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6080 if (access(notifier
, X_OK
))
6082 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6083 _("notify-recipient-uri URI \"%s\" uses unknown "
6084 "scheme!"), recipient
);
6085 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6086 "notify-status-code", IPP_URI_SCHEME
);
6090 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6092 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6093 _("notify-recipient-uri URI \"%s\" is already used!"),
6095 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6096 "notify-status-code", IPP_ATTRIBUTES
);
6100 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6101 attr
->value_tag
== IPP_TAG_KEYWORD
)
6103 pullmethod
= attr
->values
[0].string
.text
;
6105 if (strcmp(pullmethod
, "ippget"))
6107 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6108 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6109 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6110 "notify-status-code", IPP_ATTRIBUTES
);
6114 else if (!strcmp(attr
->name
, "notify-charset") &&
6115 attr
->value_tag
== IPP_TAG_CHARSET
&&
6116 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6117 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6119 send_ipp_status(con
, IPP_CHARSET
,
6120 _("Character set \"%s\" not supported!"),
6121 attr
->values
[0].string
.text
);
6124 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6125 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6126 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6128 send_ipp_status(con
, IPP_CHARSET
,
6129 _("Language \"%s\" not supported!"),
6130 attr
->values
[0].string
.text
);
6133 else if (!strcmp(attr
->name
, "notify-user-data") &&
6134 attr
->value_tag
== IPP_TAG_STRING
)
6136 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6138 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6139 _("The notify-user-data value is too large "
6140 "(%d > 63 octets)!"),
6141 attr
->values
[0].unknown
.length
);
6147 else if (!strcmp(attr
->name
, "notify-events") &&
6148 attr
->value_tag
== IPP_TAG_KEYWORD
)
6149 notify_events
= attr
;
6150 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6151 attr
->value_tag
== IPP_TAG_INTEGER
)
6152 lease
= attr
->values
[0].integer
;
6153 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6154 attr
->value_tag
== IPP_TAG_INTEGER
)
6155 interval
= attr
->values
[0].integer
;
6156 else if (!strcmp(attr
->name
, "notify-job-id") &&
6157 attr
->value_tag
== IPP_TAG_INTEGER
)
6158 jobid
= attr
->values
[0].integer
;
6165 for (i
= 0; i
< notify_events
->num_values
; i
++)
6166 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6170 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6172 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6173 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6174 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6176 if (!recipient
&& !pullmethod
)
6179 if (mask
== CUPSD_EVENT_NONE
)
6182 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6184 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6187 send_ipp_status(con
, IPP_BAD_REQUEST
,
6188 _("notify-events not specified!"));
6193 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6195 cupsdLogMessage(CUPSD_LOG_INFO
,
6196 "create_subscription: Limiting notify-lease-duration to "
6199 lease
= MaxLeaseDuration
;
6204 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6206 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6213 sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0);
6216 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6219 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6220 "Added subscription %d for printer \"%s\"",
6221 sub
->id
, printer
->name
);
6223 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6226 sub
->interval
= interval
;
6228 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6230 cupsdSetString(&sub
->owner
, username
);
6234 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6235 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6236 sub
->user_data_len
);
6239 ippAddSeparator(con
->response
);
6240 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6241 "notify-subscription-id", sub
->id
);
6243 con
->response
->request
.status
.status_code
= IPP_OK
;
6249 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6254 * 'delete_printer()' - Remove a printer or class from the system.
6258 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6259 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6261 http_status_t status
; /* Policy status */
6262 cups_ptype_t dtype
; /* Destination type (printer/class) */
6263 cupsd_printer_t
*printer
; /* Printer/class */
6264 char filename
[1024]; /* Script/PPD filename */
6267 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6268 con
->http
.fd
, uri
->values
[0].string
.text
);
6271 * Do we have a valid URI?
6274 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6280 send_ipp_status(con
, IPP_NOT_FOUND
,
6281 _("The printer or class was not found."));
6289 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6291 send_http_error(con
, status
, NULL
);
6296 * Remove old jobs...
6299 cupsdCancelJobs(printer
->name
, NULL
, 1);
6302 * Remove old subscriptions and send a "deleted printer" event...
6305 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6306 "%s \"%s\" deleted by \"%s\".",
6307 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6308 printer
->name
, get_username(con
));
6310 cupsdExpireSubscriptions(printer
, NULL
);
6313 * Remove any old PPD or script files...
6316 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6320 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6326 * Unregister color profiles...
6329 apple_unregister_profiles(printer
);
6330 #endif /* __APPLE__ */
6332 if (dtype
& CUPS_PRINTER_CLASS
)
6334 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6335 printer
->name
, get_username(con
));
6337 cupsdDeletePrinter(printer
, 0);
6338 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6342 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6343 printer
->name
, get_username(con
));
6345 cupsdDeletePrinter(printer
, 0);
6346 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6349 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6352 * Return with no errors...
6355 con
->response
->request
.status
.status_code
= IPP_OK
;
6360 * 'get_default()' - Get the default destination.
6364 get_default(cupsd_client_t
*con
) /* I - Client connection */
6366 http_status_t status
; /* Policy status */
6367 cups_array_t
*ra
; /* Requested attributes array */
6370 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6376 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6378 send_http_error(con
, status
, NULL
);
6384 ra
= create_requested_array(con
->request
);
6386 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6388 cupsArrayDelete(ra
);
6390 con
->response
->request
.status
.status_code
= IPP_OK
;
6393 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6398 * 'get_devices()' - Get the list of available devices on the local system.
6402 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6404 http_status_t status
; /* Policy status */
6405 ipp_attribute_t
*limit
, /* limit attribute */
6406 *timeout
, /* timeout attribute */
6407 *requested
, /* requested-attributes attribute */
6408 *exclude
; /* exclude-schemes attribute */
6409 char command
[1024], /* cups-deviced command */
6410 options
[1024], /* Options to pass to command */
6412 /* String for requested attributes */
6414 /* String for excluded attributes */
6417 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6423 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6425 send_http_error(con
, status
, NULL
);
6430 * Run cups-deviced command with the given options...
6433 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6434 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6435 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6437 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6440 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6442 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6445 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6447 exclude_str
[0] = '\0';
6449 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6450 snprintf(options
, sizeof(options
),
6451 "%d+%d+%d+%d+%s%s%s",
6452 con
->request
->request
.op
.request_id
,
6453 limit
? limit
->values
[0].integer
: 0,
6454 timeout
? timeout
->values
[0].integer
: 10,
6457 exclude_str
[0] ? "%20" : "", exclude_str
);
6459 if (cupsdSendCommand(con
, command
, options
, 1))
6462 * Command started successfully, don't send an IPP response here...
6465 ippDelete(con
->response
);
6466 con
->response
= NULL
;
6471 * Command failed, return "internal error" so the user knows something
6475 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6476 _("cups-deviced failed to execute."));
6482 * 'get_document()' - Get a copy of a job file.
6486 get_document(cupsd_client_t
*con
, /* I - Client connection */
6487 ipp_attribute_t
*uri
) /* I - Job URI */
6489 http_status_t status
; /* Policy status */
6490 ipp_attribute_t
*attr
; /* Current attribute */
6491 int jobid
; /* Job ID */
6492 int docnum
; /* Document number */
6493 cupsd_job_t
*job
; /* Current job */
6494 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6495 username
[HTTP_MAX_URI
], /* Username portion of URI */
6496 host
[HTTP_MAX_URI
], /* Host portion of URI */
6497 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6498 int port
; /* Port portion of URI */
6499 char filename
[1024], /* Filename for document */
6500 format
[1024]; /* Format for document */
6503 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6504 con
->http
.fd
, uri
->values
[0].string
.text
);
6507 * See if we have a job URI or a printer URI...
6510 if (!strcmp(uri
->name
, "printer-uri"))
6513 * Got a printer URI; see if we also have a job-id attribute...
6516 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6517 IPP_TAG_INTEGER
)) == NULL
)
6519 send_ipp_status(con
, IPP_BAD_REQUEST
,
6520 _("Got a printer-uri attribute but no job-id!"));
6524 jobid
= attr
->values
[0].integer
;
6529 * Got a job URI; parse it to get the job ID...
6532 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6533 sizeof(method
), username
, sizeof(username
), host
,
6534 sizeof(host
), &port
, resource
, sizeof(resource
));
6536 if (strncmp(resource
, "/jobs/", 6))
6542 send_ipp_status(con
, IPP_BAD_REQUEST
,
6543 _("Bad job-uri attribute \"%s\"!"),
6544 uri
->values
[0].string
.text
);
6548 jobid
= atoi(resource
+ 6);
6552 * See if the job exists...
6555 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6558 * Nope - return a "not found" error...
6561 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6569 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6571 send_http_error(con
, status
, NULL
);
6576 * Get the document number...
6579 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6580 IPP_TAG_INTEGER
)) == NULL
)
6582 send_ipp_status(con
, IPP_BAD_REQUEST
,
6583 _("Missing document-number attribute!"));
6587 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6588 attr
->num_values
> 1)
6590 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6595 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6597 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6599 cupsdLogMessage(CUPSD_LOG_ERROR
,
6600 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6602 send_ipp_status(con
, IPP_NOT_FOUND
,
6603 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6607 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6611 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6612 job
->filetypes
[docnum
- 1]->type
);
6614 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6616 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6618 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6619 IPP_TAG_NAME
)) != NULL
)
6620 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6621 NULL
, attr
->values
[0].string
.text
);
6626 * 'get_job_attrs()' - Get job attributes.
6630 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6631 ipp_attribute_t
*uri
) /* I - Job URI */
6633 http_status_t status
; /* Policy status */
6634 ipp_attribute_t
*attr
; /* Current attribute */
6635 int jobid
; /* Job ID */
6636 cupsd_job_t
*job
; /* Current job */
6637 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6638 username
[HTTP_MAX_URI
], /* Username portion of URI */
6639 host
[HTTP_MAX_URI
], /* Host portion of URI */
6640 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6641 int port
; /* Port portion of URI */
6642 cups_array_t
*ra
; /* Requested attributes array */
6645 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6646 con
->http
.fd
, uri
->values
[0].string
.text
);
6649 * See if we have a job URI or a printer URI...
6652 if (!strcmp(uri
->name
, "printer-uri"))
6655 * Got a printer URI; see if we also have a job-id attribute...
6658 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6659 IPP_TAG_INTEGER
)) == NULL
)
6661 send_ipp_status(con
, IPP_BAD_REQUEST
,
6662 _("Got a printer-uri attribute but no job-id!"));
6666 jobid
= attr
->values
[0].integer
;
6671 * Got a job URI; parse it to get the job ID...
6674 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6675 sizeof(method
), username
, sizeof(username
), host
,
6676 sizeof(host
), &port
, resource
, sizeof(resource
));
6678 if (strncmp(resource
, "/jobs/", 6))
6684 send_ipp_status(con
, IPP_BAD_REQUEST
,
6685 _("Bad job-uri attribute \"%s\"!"),
6686 uri
->values
[0].string
.text
);
6690 jobid
= atoi(resource
+ 6);
6694 * See if the job exists...
6697 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6700 * Nope - return a "not found" error...
6703 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6711 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6713 send_http_error(con
, status
, NULL
);
6718 * Copy attributes...
6723 ra
= create_requested_array(con
->request
);
6724 copy_job_attrs(con
, job
, ra
);
6725 cupsArrayDelete(ra
);
6727 con
->response
->request
.status
.status_code
= IPP_OK
;
6732 * 'get_jobs()' - Get a list of jobs for the specified printer.
6736 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6737 ipp_attribute_t
*uri
) /* I - Printer URI */
6739 http_status_t status
; /* Policy status */
6740 ipp_attribute_t
*attr
; /* Current attribute */
6741 const char *dest
; /* Destination */
6742 cups_ptype_t dtype
; /* Destination type (printer/class) */
6743 cups_ptype_t dmask
; /* Destination type mask */
6744 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6745 username
[HTTP_MAX_URI
], /* Username portion of URI */
6746 host
[HTTP_MAX_URI
], /* Host portion of URI */
6747 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6748 int port
; /* Port portion of URI */
6749 int completed
; /* Completed jobs? */
6750 int first_job_id
; /* First job ID */
6751 int limit
; /* Maximum number of jobs to return */
6752 int count
; /* Number of jobs that match */
6753 cupsd_job_t
*job
; /* Current job pointer */
6754 cupsd_printer_t
*printer
; /* Printer */
6755 cups_array_t
*list
; /* Which job list... */
6756 cups_array_t
*ra
; /* Requested attributes array */
6759 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6760 uri
->values
[0].string
.text
);
6763 * Is the destination valid?
6766 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6767 sizeof(scheme
), username
, sizeof(username
), host
,
6768 sizeof(host
), &port
, resource
, sizeof(resource
));
6770 if (!strcmp(resource
, "/") ||
6771 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
6774 dtype
= (cups_ptype_t
)0;
6775 dmask
= (cups_ptype_t
)0;
6778 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6781 dtype
= (cups_ptype_t
)0;
6782 dmask
= CUPS_PRINTER_CLASS
;
6785 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6788 dtype
= CUPS_PRINTER_CLASS
;
6789 dmask
= CUPS_PRINTER_CLASS
;
6792 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6799 send_ipp_status(con
, IPP_NOT_FOUND
,
6800 _("The printer or class was not found."));
6805 dtype
&= CUPS_PRINTER_CLASS
;
6806 dmask
= CUPS_PRINTER_CLASS
;
6815 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6818 send_http_error(con
, status
, printer
);
6822 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6824 send_http_error(con
, status
, NULL
);
6829 * See if the "which-jobs" attribute have been specified...
6832 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6833 IPP_TAG_KEYWORD
)) != NULL
&&
6834 !strcmp(attr
->values
[0].string
.text
, "completed"))
6839 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6844 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "printing"))
6847 list
= PrintingJobs
;
6856 * See if they want to limit the number of jobs reported...
6859 if ((attr
= ippFindAttribute(con
->request
, "limit",
6860 IPP_TAG_INTEGER
)) != NULL
)
6861 limit
= attr
->values
[0].integer
;
6865 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6866 IPP_TAG_INTEGER
)) != NULL
)
6867 first_job_id
= attr
->values
[0].integer
;
6872 * See if we only want to see jobs for a specific user...
6875 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6876 IPP_TAG_BOOLEAN
)) != NULL
&&
6877 attr
->values
[0].boolean
)
6878 strlcpy(username
, get_username(con
), sizeof(username
));
6882 ra
= create_requested_array(con
->request
);
6885 * OK, build a list of jobs for this printer...
6888 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6889 (limit
<= 0 || count
< limit
) && job
;
6890 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6893 * Filter out jobs that don't match...
6896 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
6898 if (!job
->dest
|| !job
->username
)
6901 if (!job
->dest
|| !job
->username
)
6904 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6905 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6907 if ((job
->dtype
& dmask
) != dtype
&&
6908 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6910 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
6913 if (job
->id
< first_job_id
)
6921 if (username
[0] && strcasecmp(username
, job
->username
))
6925 ippAddSeparator(con
->response
);
6929 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
6931 copy_job_attrs(con
, job
, ra
);
6934 cupsArrayDelete(ra
);
6936 con
->response
->request
.status
.status_code
= IPP_OK
;
6941 * 'get_notifications()' - Get events for a subscription.
6945 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6947 int i
, j
; /* Looping vars */
6948 http_status_t status
; /* Policy status */
6949 cupsd_subscription_t
*sub
; /* Subscription */
6950 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6951 *sequences
; /* notify-sequence-numbers */
6952 int min_seq
; /* Minimum sequence number */
6953 int interval
; /* Poll interval */
6956 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6960 * Get subscription attributes...
6963 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6965 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6970 send_ipp_status(con
, IPP_BAD_REQUEST
,
6971 _("Missing notify-subscription-ids attribute!"));
6976 * Are the subscription IDs valid?
6979 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6981 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6984 * Bad subscription ID...
6987 send_ipp_status(con
, IPP_NOT_FOUND
,
6988 _("notify-subscription-id %d no good!"),
6989 ids
->values
[i
].integer
);
6997 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6999 con
, sub
->owner
)) != HTTP_OK
)
7001 send_http_error(con
, status
, sub
->dest
);
7006 * Check the subscription type and update the interval accordingly.
7009 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7012 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7014 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7020 * Tell the client to poll again in N seconds...
7024 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7025 "notify-get-interval", interval
);
7027 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7028 "printer-up-time", time(NULL
));
7031 * Copy the subscription event attributes to the response.
7034 con
->response
->request
.status
.status_code
=
7035 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7037 for (i
= 0; i
< ids
->num_values
; i
++)
7040 * Get the subscription and sequence number...
7043 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7045 if (sequences
&& i
< sequences
->num_values
)
7046 min_seq
= sequences
->values
[i
].integer
;
7051 * If we don't have any new events, nothing to do here...
7054 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7058 * Otherwise copy all of the new events...
7061 if (sub
->first_event_id
> min_seq
)
7064 j
= min_seq
- sub
->first_event_id
;
7066 for (; j
< sub
->num_events
; j
++)
7068 ippAddSeparator(con
->response
);
7070 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7071 IPP_TAG_EVENT_NOTIFICATION
, 0);
7078 * 'get_ppd()' - Get a named PPD from the local system.
7082 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7083 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7085 http_status_t status
; /* Policy status */
7086 cupsd_printer_t
*dest
; /* Destination */
7087 cups_ptype_t dtype
; /* Destination type */
7090 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7091 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7093 if (!strcmp(uri
->name
, "ppd-name"))
7096 * Return a PPD file from cups-driverd...
7099 char command
[1024], /* cups-driverd command */
7100 options
[1024], /* Options to pass to command */
7101 ppd_name
[1024]; /* ppd-name */
7108 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7110 send_http_error(con
, status
, NULL
);
7115 * Run cups-driverd command with the given options...
7118 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7119 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7120 snprintf(options
, sizeof(options
), "get+%d+%s",
7121 con
->request
->request
.op
.request_id
, ppd_name
);
7123 if (cupsdSendCommand(con
, command
, options
, 0))
7126 * Command started successfully, don't send an IPP response here...
7129 ippDelete(con
->response
);
7130 con
->response
= NULL
;
7135 * Command failed, return "internal error" so the user knows something
7139 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7140 _("cups-driverd failed to execute."));
7143 else if (!strcmp(uri
->name
, "printer-uri") &&
7144 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7146 int i
; /* Looping var */
7147 char filename
[1024]; /* PPD filename */
7154 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7156 send_http_error(con
, status
, dest
);
7161 * See if we need the PPD for a class or remote printer...
7164 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7167 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7169 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7170 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7171 "printer-uri", NULL
, dest
->uri
);
7174 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7176 for (i
= 0; i
< dest
->num_printers
; i
++)
7177 if (!(dest
->printers
[i
]->type
&
7178 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7180 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7181 dest
->printers
[i
]->name
);
7183 if (!access(filename
, 0))
7187 if (i
< dest
->num_printers
)
7188 dest
= dest
->printers
[i
];
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
->printers
[0]->uri
);
7199 * Found the printer with the PPD file, now see if there is one...
7202 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7204 send_ipp_status(con
, IPP_NOT_FOUND
,
7205 _("The PPD file \"%s\" could not be opened: %s"),
7206 uri
->values
[0].string
.text
, strerror(errno
));
7210 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7214 con
->response
->request
.status
.status_code
= IPP_OK
;
7217 send_ipp_status(con
, IPP_NOT_FOUND
,
7218 _("The PPD file \"%s\" could not be found."),
7219 uri
->values
[0].string
.text
);
7224 * 'get_ppds()' - Get the list of PPD files on the local system.
7228 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7230 http_status_t status
; /* Policy status */
7231 ipp_attribute_t
*limit
, /* Limit attribute */
7232 *device
, /* ppd-device-id attribute */
7233 *language
, /* ppd-natural-language attribute */
7234 *make
, /* ppd-make attribute */
7235 *model
, /* ppd-make-and-model attribute */
7236 *model_number
, /* ppd-model-number attribute */
7237 *product
, /* ppd-product attribute */
7238 *psversion
, /* ppd-psverion attribute */
7239 *type
, /* ppd-type attribute */
7240 *requested
; /* requested-attributes attribute */
7241 char command
[1024], /* cups-driverd command */
7242 options
[1024], /* Options to pass to command */
7243 device_str
[256],/* Escaped ppd-device-id string */
7245 /* Escaped ppd-natural-language */
7246 make_str
[256], /* Escaped ppd-make string */
7247 model_str
[256], /* Escaped ppd-make-and-model string */
7248 model_number_str
[256],
7249 /* ppd-model-number string */
7251 /* Escaped ppd-product string */
7253 /* Escaped ppd-psversion string */
7254 type_str
[256], /* Escaped ppd-type string */
7256 /* String for requested attributes */
7259 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7265 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7267 send_http_error(con
, status
, NULL
);
7272 * Run cups-driverd command with the given options...
7275 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7276 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7277 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7279 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7280 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7282 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7284 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7285 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7286 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7287 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7291 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7293 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7296 url_encode_attr(device
, device_str
, sizeof(device_str
));
7298 device_str
[0] = '\0';
7301 url_encode_attr(language
, language_str
, sizeof(language_str
));
7303 language_str
[0] = '\0';
7306 url_encode_attr(make
, make_str
, sizeof(make_str
));
7311 url_encode_attr(model
, model_str
, sizeof(model_str
));
7313 model_str
[0] = '\0';
7316 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7317 model_number
->values
[0].integer
);
7319 model_number_str
[0] = '\0';
7322 url_encode_attr(product
, product_str
, sizeof(product_str
));
7324 product_str
[0] = '\0';
7327 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7329 psversion_str
[0] = '\0';
7332 url_encode_attr(type
, type_str
, sizeof(type_str
));
7336 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7337 snprintf(options
, sizeof(options
),
7338 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7339 con
->request
->request
.op
.request_id
,
7340 limit
? limit
->values
[0].integer
: 0,
7342 device
? "%20" : "", device_str
,
7343 language
? "%20" : "", language_str
,
7344 make
? "%20" : "", make_str
,
7345 model
? "%20" : "", model_str
,
7346 model_number
? "%20" : "", model_number_str
,
7347 product
? "%20" : "", product_str
,
7348 psversion
? "%20" : "", psversion_str
,
7349 type
? "%20" : "", type_str
);
7351 if (cupsdSendCommand(con
, command
, options
, 0))
7354 * Command started successfully, don't send an IPP response here...
7357 ippDelete(con
->response
);
7358 con
->response
= NULL
;
7363 * Command failed, return "internal error" so the user knows something
7367 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7368 _("cups-driverd failed to execute."));
7374 * 'get_printer_attrs()' - Get printer attributes.
7378 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7379 ipp_attribute_t
*uri
) /* I - Printer URI */
7381 http_status_t status
; /* Policy status */
7382 cups_ptype_t dtype
; /* Destination type (printer/class) */
7383 cupsd_printer_t
*printer
; /* Printer/class */
7384 cups_array_t
*ra
; /* Requested attributes array */
7387 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7388 con
->http
.fd
, uri
->values
[0].string
.text
);
7391 * Is the destination valid?
7394 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7400 send_ipp_status(con
, IPP_NOT_FOUND
,
7401 _("The printer or class was not found."));
7409 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7411 send_http_error(con
, status
, printer
);
7416 * Send the attributes...
7419 ra
= create_requested_array(con
->request
);
7421 copy_printer_attrs(con
, printer
, ra
);
7423 cupsArrayDelete(ra
);
7425 con
->response
->request
.status
.status_code
= IPP_OK
;
7430 * 'get_printers()' - Get a list of printers or classes.
7434 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7435 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7437 http_status_t status
; /* Policy status */
7438 ipp_attribute_t
*attr
; /* Current attribute */
7439 int limit
; /* Max number of printers to return */
7440 int count
; /* Number of printers that match */
7441 cupsd_printer_t
*printer
; /* Current printer pointer */
7442 int printer_type
, /* printer-type attribute */
7443 printer_mask
; /* printer-type-mask attribute */
7444 char *location
; /* Location string */
7445 const char *username
; /* Current user */
7446 char *first_printer_name
; /* first-printer-name attribute */
7447 cups_array_t
*ra
; /* Requested attributes array */
7450 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7451 con
->http
.fd
, type
);
7457 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7459 send_http_error(con
, status
, NULL
);
7464 * Check for printers...
7467 if (!Printers
|| !cupsArrayCount(Printers
))
7469 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7474 * See if they want to limit the number of printers reported...
7477 if ((attr
= ippFindAttribute(con
->request
, "limit",
7478 IPP_TAG_INTEGER
)) != NULL
)
7479 limit
= attr
->values
[0].integer
;
7483 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7484 IPP_TAG_NAME
)) != NULL
)
7485 first_printer_name
= attr
->values
[0].string
.text
;
7487 first_printer_name
= NULL
;
7490 * Support filtering...
7493 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7494 IPP_TAG_ENUM
)) != NULL
)
7495 printer_type
= attr
->values
[0].integer
;
7499 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7500 IPP_TAG_ENUM
)) != NULL
)
7501 printer_mask
= attr
->values
[0].integer
;
7505 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7506 IPP_TAG_TEXT
)) != NULL
)
7507 location
= attr
->values
[0].string
.text
;
7511 if (con
->username
[0])
7512 username
= con
->username
;
7513 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7514 IPP_TAG_NAME
)) != NULL
)
7515 username
= attr
->values
[0].string
.text
;
7519 ra
= create_requested_array(con
->request
);
7522 * OK, build a list of printers for this printer...
7525 if (first_printer_name
)
7527 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7528 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7531 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7534 count
< limit
&& printer
;
7535 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7537 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7538 (printer
->type
& printer_mask
) == printer_type
&&
7539 (!location
|| !printer
->location
||
7540 !strcasecmp(printer
->location
, location
)))
7543 * If HideImplicitMembers is enabled, see if this printer or class
7544 * is a member of an implicit class...
7547 if (ImplicitClasses
&& HideImplicitMembers
&&
7548 printer
->in_implicit_class
)
7552 * If a username is specified, see if it is allowed or denied
7556 if (!(printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
7557 printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7561 * Add the group separator as needed...
7565 ippAddSeparator(con
->response
);
7570 * Send the attributes...
7573 copy_printer_attrs(con
, printer
, ra
);
7577 cupsArrayDelete(ra
);
7579 con
->response
->request
.status
.status_code
= IPP_OK
;
7584 * 'get_subscription_attrs()' - Get subscription attributes.
7588 get_subscription_attrs(
7589 cupsd_client_t
*con
, /* I - Client connection */
7590 int sub_id
) /* I - Subscription ID */
7592 http_status_t status
; /* Policy status */
7593 cupsd_subscription_t
*sub
; /* Subscription */
7594 cups_array_t
*ra
; /* Requested attributes array */
7597 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7598 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7599 con
, con
->http
.fd
, sub_id
);
7602 * Is the subscription ID valid?
7605 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7608 * Bad subscription ID...
7611 send_ipp_status(con
, IPP_NOT_FOUND
,
7612 _("notify-subscription-id %d no good!"), sub_id
);
7620 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7622 con
, sub
->owner
)) != HTTP_OK
)
7624 send_http_error(con
, status
, sub
->dest
);
7629 * Copy the subscription attributes to the response using the
7630 * requested-attributes attribute that may be provided by the client.
7633 ra
= create_requested_array(con
->request
);
7635 copy_subscription_attrs(con
, sub
, ra
);
7637 cupsArrayDelete(ra
);
7639 con
->response
->request
.status
.status_code
= IPP_OK
;
7644 * 'get_subscriptions()' - Get subscriptions.
7648 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7649 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7651 http_status_t status
; /* Policy status */
7652 int count
; /* Number of subscriptions */
7653 int limit
; /* Limit */
7654 cupsd_subscription_t
*sub
; /* Subscription */
7655 cups_array_t
*ra
; /* Requested attributes array */
7656 ipp_attribute_t
*attr
; /* Attribute */
7657 cups_ptype_t dtype
; /* Destination type (printer/class) */
7658 char scheme
[HTTP_MAX_URI
],
7659 /* Scheme portion of URI */
7660 username
[HTTP_MAX_URI
],
7661 /* Username portion of URI */
7663 /* Host portion of URI */
7664 resource
[HTTP_MAX_URI
];
7665 /* Resource portion of URI */
7666 int port
; /* Port portion of URI */
7667 cupsd_job_t
*job
; /* Job pointer */
7668 cupsd_printer_t
*printer
; /* Printer */
7671 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7672 "get_subscriptions(con=%p[%d], uri=%s)",
7673 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7676 * Is the destination valid?
7679 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7680 sizeof(scheme
), username
, sizeof(username
), host
,
7681 sizeof(host
), &port
, resource
, sizeof(resource
));
7683 if (!strcmp(resource
, "/") ||
7684 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7685 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7686 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7691 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7694 job
= cupsdFindJob(atoi(resource
+ 6));
7698 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7703 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7709 send_ipp_status(con
, IPP_NOT_FOUND
,
7710 _("The printer or class was not found."));
7713 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7714 IPP_TAG_INTEGER
)) != NULL
)
7716 job
= cupsdFindJob(attr
->values
[0].integer
);
7720 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7721 attr
->values
[0].integer
);
7732 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7734 con
, NULL
)) != HTTP_OK
)
7736 send_http_error(con
, status
, printer
);
7741 * Copy the subscription attributes to the response using the
7742 * requested-attributes attribute that may be provided by the client.
7745 ra
= create_requested_array(con
->request
);
7747 if ((attr
= ippFindAttribute(con
->request
, "limit",
7748 IPP_TAG_INTEGER
)) != NULL
)
7749 limit
= attr
->values
[0].integer
;
7754 * See if we only want to see subscriptions for a specific user...
7757 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7758 IPP_TAG_BOOLEAN
)) != NULL
&&
7759 attr
->values
[0].boolean
)
7760 strlcpy(username
, get_username(con
), sizeof(username
));
7764 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7766 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7767 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7768 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7770 ippAddSeparator(con
->response
);
7771 copy_subscription_attrs(con
, sub
, ra
);
7774 if (limit
&& count
>= limit
)
7778 cupsArrayDelete(ra
);
7781 con
->response
->request
.status
.status_code
= IPP_OK
;
7783 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7788 * 'get_username()' - Get the username associated with a request.
7791 static const char * /* O - Username */
7792 get_username(cupsd_client_t
*con
) /* I - Connection */
7794 ipp_attribute_t
*attr
; /* Attribute */
7797 if (con
->username
[0])
7798 return (con
->username
);
7799 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7800 IPP_TAG_NAME
)) != NULL
)
7801 return (attr
->values
[0].string
.text
);
7803 return ("anonymous");
7808 * 'hold_job()' - Hold a print job.
7812 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7813 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7815 ipp_attribute_t
*attr
, /* Current job-hold-until */
7816 *newattr
; /* New job-hold-until */
7817 int jobid
; /* Job ID */
7818 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7819 username
[HTTP_MAX_URI
], /* Username portion of URI */
7820 host
[HTTP_MAX_URI
], /* Host portion of URI */
7821 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7822 int port
; /* Port portion of URI */
7823 cupsd_job_t
*job
; /* Job information */
7826 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7827 uri
->values
[0].string
.text
);
7830 * See if we have a job URI or a printer URI...
7833 if (!strcmp(uri
->name
, "printer-uri"))
7836 * Got a printer URI; see if we also have a job-id attribute...
7839 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7840 IPP_TAG_INTEGER
)) == NULL
)
7842 send_ipp_status(con
, IPP_BAD_REQUEST
,
7843 _("Got a printer-uri attribute but no job-id!"));
7847 jobid
= attr
->values
[0].integer
;
7852 * Got a job URI; parse it to get the job ID...
7855 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7856 sizeof(method
), username
, sizeof(username
), host
,
7857 sizeof(host
), &port
, resource
, sizeof(resource
));
7859 if (strncmp(resource
, "/jobs/", 6))
7865 send_ipp_status(con
, IPP_BAD_REQUEST
,
7866 _("Bad job-uri attribute \"%s\"!"),
7867 uri
->values
[0].string
.text
);
7871 jobid
= atoi(resource
+ 6);
7875 * See if the job exists...
7878 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7881 * Nope - return a "not found" error...
7884 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7889 * See if the job is owned by the requesting user...
7892 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7894 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
7899 * Hold the job and return...
7904 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
7905 "Job held by user.");
7907 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
7908 IPP_TAG_KEYWORD
)) == NULL
)
7909 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7911 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7912 IPP_TAG_KEYWORD
)) == NULL
)
7913 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7918 * Free the old hold value and copy the new one over...
7921 _cupsStrFree(attr
->values
[0].string
.text
);
7925 attr
->value_tag
= newattr
->value_tag
;
7926 attr
->values
[0].string
.text
=
7927 _cupsStrAlloc(newattr
->values
[0].string
.text
);
7931 attr
->value_tag
= IPP_TAG_KEYWORD
;
7932 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
7936 * Hold job until specified time...
7939 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
7941 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7942 "Job job-hold-until value changed by user.");
7945 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Held by \"%s\".", username
);
7947 con
->response
->request
.status
.status_code
= IPP_OK
;
7952 * 'move_job()' - Move a job to a new destination.
7956 move_job(cupsd_client_t
*con
, /* I - Client connection */
7957 ipp_attribute_t
*uri
) /* I - Job URI */
7959 http_status_t status
; /* Policy status */
7960 ipp_attribute_t
*attr
; /* Current attribute */
7961 int jobid
; /* Job ID */
7962 cupsd_job_t
*job
; /* Current job */
7963 const char *src
; /* Source printer/class */
7964 cups_ptype_t stype
, /* Source type (printer or class) */
7965 dtype
; /* Destination type (printer/class) */
7966 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7967 username
[HTTP_MAX_URI
], /* Username portion of URI */
7968 host
[HTTP_MAX_URI
], /* Host portion of URI */
7969 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7970 int port
; /* Port portion of URI */
7971 cupsd_printer_t
*sprinter
, /* Source printer */
7972 *dprinter
; /* Destination printer */
7975 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7976 uri
->values
[0].string
.text
);
7979 * Get the new printer or class...
7982 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7983 IPP_TAG_URI
)) == NULL
)
7986 * Need job-printer-uri...
7989 send_ipp_status(con
, IPP_BAD_REQUEST
,
7990 _("job-printer-uri attribute missing!"));
7994 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8000 send_ipp_status(con
, IPP_NOT_FOUND
,
8001 _("The printer or class was not found."));
8006 * See if we have a job URI or a printer URI...
8009 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8010 sizeof(scheme
), username
, sizeof(username
), host
,
8011 sizeof(host
), &port
, resource
, sizeof(resource
));
8013 if (!strcmp(uri
->name
, "printer-uri"))
8016 * Got a printer URI; see if we also have a job-id attribute...
8019 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8020 IPP_TAG_INTEGER
)) == NULL
)
8026 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8027 &sprinter
)) == NULL
)
8033 send_ipp_status(con
, IPP_NOT_FOUND
,
8034 _("The printer or class was not found."));
8043 * Otherwise, just move a single job...
8046 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8049 * Nope - return a "not found" error...
8052 send_ipp_status(con
, IPP_NOT_FOUND
,
8053 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8059 * Job found, initialize source pointers...
8070 * Got a job URI; parse it to get the job ID...
8073 if (strncmp(resource
, "/jobs/", 6))
8079 send_ipp_status(con
, IPP_BAD_REQUEST
,
8080 _("Bad job-uri attribute \"%s\"!"),
8081 uri
->values
[0].string
.text
);
8086 * See if the job exists...
8089 jobid
= atoi(resource
+ 6);
8091 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8094 * Nope - return a "not found" error...
8097 send_ipp_status(con
, IPP_NOT_FOUND
,
8098 _("Job #%d does not exist!"), jobid
);
8104 * Job found, initialize source pointers...
8113 * Check the policy of the destination printer...
8116 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8117 job
? job
->username
: NULL
)) != HTTP_OK
)
8119 send_http_error(con
, status
, dprinter
);
8124 * Now move the job or jobs...
8130 * See if the job has been completed...
8133 if (job
->state_value
> IPP_JOB_STOPPED
)
8136 * Return a "not-possible" error...
8139 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8140 _("Job #%d is finished and cannot be altered!"),
8146 * See if the job is owned by the requesting user...
8149 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8151 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8156 * Move the job to a different printer or class...
8159 cupsdMoveJob(job
, dprinter
);
8164 * Got the source printer, now look through the jobs...
8167 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8169 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8172 * See if the job is pointing at the source printer or has not been
8176 if (strcasecmp(job
->dest
, src
) ||
8177 job
->state_value
> IPP_JOB_STOPPED
)
8181 * See if the job can be moved by the requesting user...
8184 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8188 * Move the job to a different printer or class...
8191 cupsdMoveJob(job
, dprinter
);
8196 * Start jobs if possible...
8202 * Return with "everything is OK" status...
8205 con
->response
->request
.status
.status_code
= IPP_OK
;
8210 * 'ppd_parse_line()' - Parse a PPD default line.
8213 static int /* O - 0 on success, -1 on failure */
8214 ppd_parse_line(const char *line
, /* I - Line */
8215 char *option
, /* O - Option name */
8216 int olen
, /* I - Size of option name */
8217 char *choice
, /* O - Choice name */
8218 int clen
) /* I - Size of choice name */
8221 * Verify this is a default option line...
8224 if (strncmp(line
, "*Default", 8))
8228 * Read the option name...
8231 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
8241 * Skip everything else up to the colon (:)...
8244 while (*line
&& *line
!= ':')
8253 * Now grab the option choice, skipping leading whitespace...
8256 while (isspace(*line
& 255))
8259 for (clen
--; isalnum(*line
& 255); line
++)
8269 * Return with no errors...
8277 * 'print_job()' - Print a file to a printer or class.
8281 print_job(cupsd_client_t
*con
, /* I - Client connection */
8282 ipp_attribute_t
*uri
) /* I - Printer URI */
8284 ipp_attribute_t
*attr
; /* Current attribute */
8285 ipp_attribute_t
*format
; /* Document-format attribute */
8286 const char *default_format
; /* document-format-default value */
8287 cupsd_job_t
*job
; /* New job */
8288 char filename
[1024]; /* Job filename */
8289 mime_type_t
*filetype
; /* Type of file */
8290 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8291 type
[MIME_MAX_TYPE
], /* Subtype of file */
8292 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8293 /* Textual name of mime type */
8294 cupsd_printer_t
*printer
; /* Printer data */
8295 struct stat fileinfo
; /* File information */
8296 int kbytes
; /* Size of file */
8297 int compression
; /* Document compression */
8300 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8301 uri
->values
[0].string
.text
);
8304 * Validate print file attributes, for now just document-format and
8305 * compression (CUPS only supports "none" and "gzip")...
8308 compression
= CUPS_FILE_NONE
;
8310 if ((attr
= ippFindAttribute(con
->request
, "compression",
8311 IPP_TAG_KEYWORD
)) != NULL
)
8313 if (strcmp(attr
->values
[0].string
.text
, "none")
8315 && strcmp(attr
->values
[0].string
.text
, "gzip")
8316 #endif /* HAVE_LIBZ */
8319 send_ipp_status(con
, IPP_ATTRIBUTES
,
8320 _("Unsupported compression \"%s\"!"),
8321 attr
->values
[0].string
.text
);
8322 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8323 "compression", NULL
, attr
->values
[0].string
.text
);
8328 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8329 compression
= CUPS_FILE_GZIP
;
8330 #endif /* HAVE_LIBZ */
8334 * Do we have a file to print?
8339 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8344 * Is the destination valid?
8347 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8353 send_ipp_status(con
, IPP_NOT_FOUND
,
8354 _("The printer or class was not found."));
8359 * Is it a format we support?
8362 if ((format
= ippFindAttribute(con
->request
, "document-format",
8363 IPP_TAG_MIMETYPE
)) != NULL
)
8366 * Grab format from client...
8369 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8372 send_ipp_status(con
, IPP_BAD_REQUEST
,
8373 _("Could not scan type \"%s\"!"),
8374 format
->values
[0].string
.text
);
8378 else if ((default_format
= cupsGetOption("document-format",
8379 printer
->num_options
,
8380 printer
->options
)) != NULL
)
8383 * Use default document format...
8386 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8388 send_ipp_status(con
, IPP_BAD_REQUEST
,
8389 _("Could not scan type \"%s\"!"),
8400 strcpy(super
, "application");
8401 strcpy(type
, "octet-stream");
8404 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8407 * Auto-type the file...
8410 ipp_attribute_t
*doc_name
; /* document-name attribute */
8413 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8415 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8416 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8417 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8421 filetype
= mimeType(MimeDatabase
, super
, type
);
8423 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8424 filetype
->super
, filetype
->type
);
8427 filetype
= mimeType(MimeDatabase
, super
, type
);
8431 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8434 * Replace the document-format attribute value with the auto-typed or
8438 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8443 _cupsStrFree(format
->values
[0].string
.text
);
8445 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8448 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8449 "document-format", NULL
, mimetype
);
8453 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8454 _("Unsupported format \'%s/%s\'!"), super
, type
);
8455 cupsdLogMessage(CUPSD_LOG_INFO
,
8456 "Hint: Do you have the raw file printing rules enabled?");
8459 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8460 "document-format", NULL
, format
->values
[0].string
.text
);
8466 * Read any embedded job ticket info from PS files...
8469 if (!strcasecmp(filetype
->super
, "application") &&
8470 !strcasecmp(filetype
->type
, "postscript"))
8471 read_ps_job_ticket(con
);
8474 * Create the job object...
8477 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8481 * Update quota data...
8484 if (stat(con
->filename
, &fileinfo
))
8487 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8489 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8491 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8492 IPP_TAG_INTEGER
)) != NULL
)
8493 attr
->values
[0].integer
+= kbytes
;
8496 * Add the job file...
8499 if (add_file(con
, job
, filetype
, compression
))
8502 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8504 rename(con
->filename
, filename
);
8505 cupsdClearString(&con
->filename
);
8508 * See if we need to add the ending sheet...
8511 if (cupsdTimeoutJob(job
))
8515 * Log and save the job...
8518 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8519 "File of type %s/%s queued by \"%s\".",
8520 filetype
->super
, filetype
->type
, job
->username
);
8521 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8524 * Start the job if possible...
8532 * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
8534 * This function only gets called when printing a single PostScript
8535 * file using the Print-Job operation. It doesn't work for Create-Job +
8536 * Send-File, since the job attributes need to be set at job creation
8537 * time for banners to work. The embedded PS job ticket stuff is here
8538 * only to allow the Windows printer driver for CUPS to pass in JCL
8539 * options and IPP attributes which otherwise would be lost.
8541 * The format of a PS job ticket is simple:
8543 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8545 * %cupsJobTicket: attr1=value1
8546 * %cupsJobTicket: attr2=value2
8548 * %cupsJobTicket: attrN=valueN
8550 * Job ticket lines must appear immediately after the first line that
8551 * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
8552 * looking for job ticket info when it finds a line that does not begin
8553 * with "%cupsJobTicket:".
8555 * The maximum length of a job ticket line, including the prefix, is
8556 * 255 characters to conform with the Adobe DSC.
8558 * Read-only attributes are rejected with a notice to the error log in
8559 * case a malicious user tries anything. Since the job ticket is read
8560 * prior to attribute validation in print_job(), job ticket attributes
8561 * will go through the same validation as IPP attributes...
8565 read_ps_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8567 cups_file_t
*fp
; /* File to read from */
8568 char line
[256]; /* Line data */
8569 int num_options
; /* Number of options */
8570 cups_option_t
*options
; /* Options */
8571 ipp_t
*ticket
; /* New attributes */
8572 ipp_attribute_t
*attr
, /* Current attribute */
8573 *attr2
, /* Job attribute */
8574 *prev2
; /* Previous job attribute */
8578 * First open the print file...
8581 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8583 cupsdLogMessage(CUPSD_LOG_ERROR
,
8584 "read_ps_job_ticket: Unable to open PostScript print file "
8591 * Skip the first line...
8594 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8596 cupsdLogMessage(CUPSD_LOG_ERROR
,
8597 "read_ps_job_ticket: Unable to read from PostScript print "
8604 if (strncmp(line
, "%!PS-Adobe-", 11))
8607 * Not a DSC-compliant file, so no job ticket info will be available...
8615 * Read job ticket info from the file...
8621 while (cupsFileGets(fp
, line
, sizeof(line
)))
8624 * Stop at the first non-ticket line...
8627 if (strncmp(line
, "%cupsJobTicket:", 15))
8631 * Add the options to the option array...
8634 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8638 * Done with the file; see if we have any options...
8643 if (num_options
== 0)
8647 * OK, convert the options to an attribute list, and apply them to
8652 cupsEncodeOptions(ticket
, num_options
, options
);
8655 * See what the user wants to change.
8658 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8660 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8663 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8664 !strcmp(attr
->name
, "job-originating-user-name") ||
8665 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8666 !strcmp(attr
->name
, "job-k-octets") ||
8667 !strcmp(attr
->name
, "job-id") ||
8668 !strncmp(attr
->name
, "job-state", 9) ||
8669 !strncmp(attr
->name
, "time-at-", 8))
8670 continue; /* Read-only attrs */
8672 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8673 IPP_TAG_ZERO
)) != NULL
)
8676 * Some other value; first free the old value...
8679 if (con
->request
->attrs
== attr2
)
8681 con
->request
->attrs
= attr2
->next
;
8686 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8687 if (prev2
->next
== attr2
)
8689 prev2
->next
= attr2
->next
;
8694 if (con
->request
->last
== attr2
)
8695 con
->request
->last
= prev2
;
8697 _ippFreeAttr(attr2
);
8701 * Add new option by copying it...
8704 copy_attribute(con
->request
, attr
, 0);
8708 * Then free the attribute list and option array...
8712 cupsFreeOptions(num_options
, options
);
8717 * 'reject_jobs()' - Reject print jobs to a printer.
8721 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8722 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8724 http_status_t status
; /* Policy status */
8725 cups_ptype_t dtype
; /* Destination type (printer/class) */
8726 cupsd_printer_t
*printer
; /* Printer data */
8727 ipp_attribute_t
*attr
; /* printer-state-message text */
8730 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8731 con
->http
.fd
, uri
->values
[0].string
.text
);
8734 * Is the destination valid?
8737 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8743 send_ipp_status(con
, IPP_NOT_FOUND
,
8744 _("The printer or class was not found."));
8752 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8754 send_http_error(con
, status
, printer
);
8759 * Reject jobs sent to the printer...
8762 printer
->accepting
= 0;
8764 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8765 IPP_TAG_TEXT
)) == NULL
)
8766 strcpy(printer
->state_message
, "Rejecting Jobs");
8768 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8769 sizeof(printer
->state_message
));
8771 cupsdAddPrinterHistory(printer
);
8773 if (dtype
& CUPS_PRINTER_CLASS
)
8775 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8777 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8778 printer
->name
, get_username(con
));
8782 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8784 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8785 printer
->name
, get_username(con
));
8789 * Everything was ok, so return OK status...
8792 con
->response
->request
.status
.status_code
= IPP_OK
;
8797 * 'release_job()' - Release a held print job.
8801 release_job(cupsd_client_t
*con
, /* I - Client connection */
8802 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8804 ipp_attribute_t
*attr
; /* Current attribute */
8805 int jobid
; /* Job ID */
8806 char method
[HTTP_MAX_URI
], /* Method portion of URI */
8807 username
[HTTP_MAX_URI
], /* Username portion of URI */
8808 host
[HTTP_MAX_URI
], /* Host portion of URI */
8809 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8810 int port
; /* Port portion of URI */
8811 cupsd_job_t
*job
; /* Job information */
8814 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8815 con
->http
.fd
, uri
->values
[0].string
.text
);
8818 * See if we have a job URI or a printer URI...
8821 if (!strcmp(uri
->name
, "printer-uri"))
8824 * Got a printer URI; see if we also have a job-id attribute...
8827 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8828 IPP_TAG_INTEGER
)) == NULL
)
8830 send_ipp_status(con
, IPP_BAD_REQUEST
,
8831 _("Got a printer-uri attribute but no job-id!"));
8835 jobid
= attr
->values
[0].integer
;
8840 * Got a job URI; parse it to get the job ID...
8843 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8844 sizeof(method
), username
, sizeof(username
), host
,
8845 sizeof(host
), &port
, resource
, sizeof(resource
));
8847 if (strncmp(resource
, "/jobs/", 6))
8853 send_ipp_status(con
, IPP_BAD_REQUEST
,
8854 _("Bad job-uri attribute \"%s\"!"),
8855 uri
->values
[0].string
.text
);
8859 jobid
= atoi(resource
+ 6);
8863 * See if the job exists...
8866 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8869 * Nope - return a "not found" error...
8872 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8877 * See if job is "held"...
8880 if (job
->state_value
!= IPP_JOB_HELD
)
8883 * Nope - return a "not possible" error...
8886 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
8891 * See if the job is owned by the requesting user...
8894 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8896 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8901 * Reset the job-hold-until value to "no-hold"...
8904 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8905 IPP_TAG_KEYWORD
)) == NULL
)
8906 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8910 _cupsStrFree(attr
->values
[0].string
.text
);
8912 attr
->value_tag
= IPP_TAG_KEYWORD
;
8913 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8915 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8916 "Job job-hold-until value changed by user.");
8920 * Release the job and return...
8923 cupsdReleaseJob(job
);
8925 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8926 "Job released by user.");
8928 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8930 con
->response
->request
.status
.status_code
= IPP_OK
;
8935 * 'renew_subscription()' - Renew an existing subscription...
8940 cupsd_client_t
*con
, /* I - Client connection */
8941 int sub_id
) /* I - Subscription ID */
8943 http_status_t status
; /* Policy status */
8944 cupsd_subscription_t
*sub
; /* Subscription */
8945 ipp_attribute_t
*lease
; /* notify-lease-duration */
8948 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8949 "renew_subscription(con=%p[%d], sub_id=%d)",
8950 con
, con
->http
.fd
, sub_id
);
8953 * Is the subscription ID valid?
8956 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8959 * Bad subscription ID...
8962 send_ipp_status(con
, IPP_NOT_FOUND
,
8963 _("notify-subscription-id %d no good!"), sub_id
);
8970 * Job subscriptions cannot be renewed...
8973 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8974 _("Job subscriptions cannot be renewed!"));
8982 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8984 con
, sub
->owner
)) != HTTP_OK
)
8986 send_http_error(con
, status
, sub
->dest
);
8991 * Renew the subscription...
8994 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8997 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8999 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9001 cupsdLogMessage(CUPSD_LOG_INFO
,
9002 "renew_subscription: Limiting notify-lease-duration to "
9005 sub
->lease
= MaxLeaseDuration
;
9008 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9010 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9012 con
->response
->request
.status
.status_code
= IPP_OK
;
9014 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9015 "notify-lease-duration", sub
->lease
);
9020 * 'restart_job()' - Restart an old print job.
9024 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9025 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9027 ipp_attribute_t
*attr
; /* Current attribute */
9028 int jobid
; /* Job ID */
9029 char method
[HTTP_MAX_URI
], /* Method portion of URI */
9030 username
[HTTP_MAX_URI
], /* Username portion of URI */
9031 host
[HTTP_MAX_URI
], /* Host portion of URI */
9032 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9033 int port
; /* Port portion of URI */
9034 cupsd_job_t
*job
; /* Job information */
9037 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9038 con
->http
.fd
, uri
->values
[0].string
.text
);
9041 * See if we have a job URI or a printer URI...
9044 if (!strcmp(uri
->name
, "printer-uri"))
9047 * Got a printer URI; see if we also have a job-id attribute...
9050 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9051 IPP_TAG_INTEGER
)) == NULL
)
9053 send_ipp_status(con
, IPP_BAD_REQUEST
,
9054 _("Got a printer-uri attribute but no job-id!"));
9058 jobid
= attr
->values
[0].integer
;
9063 * Got a job URI; parse it to get the job ID...
9066 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9067 sizeof(method
), username
, sizeof(username
), host
,
9068 sizeof(host
), &port
, resource
, sizeof(resource
));
9070 if (strncmp(resource
, "/jobs/", 6))
9076 send_ipp_status(con
, IPP_BAD_REQUEST
,
9077 _("Bad job-uri attribute \"%s\"!"),
9078 uri
->values
[0].string
.text
);
9082 jobid
= atoi(resource
+ 6);
9086 * See if the job exists...
9089 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9092 * Nope - return a "not found" error...
9095 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9100 * See if job is in any of the "completed" states...
9103 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9106 * Nope - return a "not possible" error...
9109 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9115 * See if we have retained the job files...
9120 if (!job
->attrs
|| job
->num_files
== 0)
9123 * Nope - return a "not possible" error...
9126 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9127 _("Job #%d cannot be restarted - no files!"), jobid
);
9132 * See if the job is owned by the requesting user...
9135 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9137 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9142 * Restart the job and return...
9145 cupsdRestartJob(job
);
9147 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9149 con
->response
->request
.status
.status_code
= IPP_OK
;
9154 * 'save_auth_info()' - Save authentication information for a job.
9159 cupsd_client_t
*con
, /* I - Client connection */
9160 cupsd_job_t
*job
, /* I - Job */
9161 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9163 int i
; /* Looping var */
9164 char filename
[1024]; /* Job authentication filename */
9165 cups_file_t
*fp
; /* Job authentication file */
9166 char line
[2048]; /* Line for file */
9167 cupsd_printer_t
*dest
; /* Destination printer/class */
9171 * This function saves the in-memory authentication information for
9172 * a job so that it can be used to authenticate with a remote host.
9173 * The information is stored in a file that is readable only by the
9174 * root user. The fields are Base-64 encoded, each on a separate line,
9175 * followed by random number (up to 1024) of newlines to limit the
9176 * amount of information that is exposed.
9178 * Because of the potential for exposing of authentication information,
9179 * this functionality is only enabled when running cupsd as root.
9181 * This caching only works for the Basic and BasicDigest authentication
9182 * types. Digest authentication cannot be cached this way, and in
9183 * the future Kerberos authentication may make all of this obsolete.
9185 * Authentication information is saved whenever an authenticated
9186 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9189 * This information is deleted after a job is completed or canceled,
9190 * so reprints may require subsequent re-authentication.
9196 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9200 * Create the authentication file and change permissions...
9203 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9204 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9206 cupsdLogMessage(CUPSD_LOG_ERROR
,
9207 "Unable to save authentication info to \"%s\" - %s",
9208 filename
, strerror(errno
));
9212 fchown(cupsFileNumber(fp
), 0, 0);
9213 fchmod(cupsFileNumber(fp
), 0400);
9215 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9218 * Write 1 to 3 auth values...
9221 cupsdClearString(&job
->auth_username
);
9222 cupsdClearString(&job
->auth_domain
);
9223 cupsdClearString(&job
->auth_password
);
9225 for (i
= 0; i
< auth_info
->num_values
; i
++)
9227 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9228 strlen(auth_info
->values
[i
].string
.text
));
9229 cupsFilePrintf(fp
, "%s\n", line
);
9231 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9232 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9233 auth_info
->values
[i
].string
.text
);
9234 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9235 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9236 auth_info
->values
[i
].string
.text
);
9237 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9238 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9239 auth_info
->values
[i
].string
.text
);
9242 else if (con
->username
[0])
9245 * Write the authenticated username...
9248 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9249 cupsFilePrintf(fp
, "%s\n", line
);
9251 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9252 cupsdClearString(&job
->auth_domain
);
9255 * Write the authenticated password...
9258 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9259 cupsFilePrintf(fp
, "%s\n", line
);
9261 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9265 * Write a random number of newlines to the end of the file...
9268 for (i
= (rand() % 1024); i
>= 0; i
--)
9269 cupsFilePutChar(fp
, '\n');
9272 * Close the file and return...
9277 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9278 if (con
->gss_have_creds
)
9279 save_krb5_creds(con
, job
);
9280 else if (job
->ccname
)
9281 cupsdClearString(&(job
->ccname
));
9282 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9286 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9288 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9292 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9293 cupsd_job_t
*job
) /* I - Job */
9295 # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
9296 cupsdLogMessage(CUPSD_LOG_INFO
,
9297 "Sorry, your version of Kerberos does not support delegated "
9302 krb5_error_code error
; /* Kerberos error code */
9303 OM_uint32 major_status
, /* Major status code */
9304 minor_status
; /* Minor status code */
9305 krb5_principal principal
; /* Kerberos principal */
9310 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
9314 if (krb5_init_context
== NULL
)
9316 # endif /* __APPLE__ */
9319 * We MUST create a file-based cache because memory-based caches are
9320 * only valid for the current process/address space.
9322 * Due to various bugs/features in different versions of Kerberos, we
9323 * need either the krb5_cc_new_unique() function or Heimdal's version
9324 * of krb5_cc_gen_new() to create a new FILE: credential cache that
9325 * can be passed to the backend. These functions create a temporary
9326 * file (typically in /tmp) containing the cached credentials, which
9327 * are removed when we have successfully printed a job.
9330 # ifdef HAVE_KRB5_CC_NEW_UNIQUE
9331 if ((error
= krb5_cc_new_unique(KerberosContext
, "FILE", NULL
,
9332 &(job
->ccache
))) != 0)
9333 # else /* HAVE_HEIMDAL */
9334 if ((error
= krb5_cc_gen_new(KerberosContext
, &krb5_fcc_ops
,
9335 &(job
->ccache
))) != 0)
9336 # endif /* HAVE_KRB5_CC_NEW_UNIQUE */
9338 cupsdLogMessage(CUPSD_LOG_ERROR
,
9339 "Unable to create new credentials cache (%d/%s)",
9340 error
, strerror(errno
));
9345 if ((error
= krb5_parse_name(KerberosContext
, con
->username
, &principal
)) != 0)
9347 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to parse kerberos username (%d/%s)",
9348 error
, strerror(errno
));
9349 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9354 if ((error
= krb5_cc_initialize(KerberosContext
, job
->ccache
, principal
)))
9356 cupsdLogMessage(CUPSD_LOG_ERROR
,
9357 "Unable to initialize credentials cache (%d/%s)", error
,
9359 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9360 krb5_free_principal(KerberosContext
, principal
);
9365 krb5_free_principal(KerberosContext
, principal
);
9368 * Copy the user's credentials to the new cache file...
9371 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
9374 if (GSS_ERROR(major_status
))
9376 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
9377 "Unable to import client credentials cache");
9378 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9384 * Add the KRB5CCNAME environment variable to the job so that the
9385 * backend can use the credentials when printing.
9388 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9389 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9391 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9392 # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
9394 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9398 * 'send_document()' - Send a file to a printer or class.
9402 send_document(cupsd_client_t
*con
, /* I - Client connection */
9403 ipp_attribute_t
*uri
) /* I - Printer URI */
9405 ipp_attribute_t
*attr
; /* Current attribute */
9406 ipp_attribute_t
*format
; /* Request's document-format attribute */
9407 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9408 const char *default_format
;/* document-format-default value */
9409 int jobid
; /* Job ID number */
9410 cupsd_job_t
*job
; /* Current job */
9411 char job_uri
[HTTP_MAX_URI
],
9413 method
[HTTP_MAX_URI
],
9414 /* Method portion of URI */
9415 username
[HTTP_MAX_URI
],
9416 /* Username portion of URI */
9418 /* Host portion of URI */
9419 resource
[HTTP_MAX_URI
];
9420 /* Resource portion of URI */
9421 int port
; /* Port portion of URI */
9422 mime_type_t
*filetype
; /* Type of file */
9423 char super
[MIME_MAX_SUPER
],
9424 /* Supertype of file */
9425 type
[MIME_MAX_TYPE
],
9426 /* Subtype of file */
9427 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9428 /* Textual name of mime type */
9429 char filename
[1024]; /* Job filename */
9430 cupsd_printer_t
*printer
; /* Current printer */
9431 struct stat fileinfo
; /* File information */
9432 int kbytes
; /* Size of file */
9433 int compression
; /* Type of compression */
9434 int start_job
; /* Start the job? */
9437 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9438 con
->http
.fd
, uri
->values
[0].string
.text
);
9441 * See if we have a job URI or a printer URI...
9444 if (!strcmp(uri
->name
, "printer-uri"))
9447 * Got a printer URI; see if we also have a job-id attribute...
9450 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9451 IPP_TAG_INTEGER
)) == NULL
)
9453 send_ipp_status(con
, IPP_BAD_REQUEST
,
9454 _("Got a printer-uri attribute but no job-id!"));
9458 jobid
= attr
->values
[0].integer
;
9463 * Got a job URI; parse it to get the job ID...
9466 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9467 sizeof(method
), username
, sizeof(username
), host
,
9468 sizeof(host
), &port
, resource
, sizeof(resource
));
9470 if (strncmp(resource
, "/jobs/", 6))
9476 send_ipp_status(con
, IPP_BAD_REQUEST
,
9477 _("Bad job-uri attribute \"%s\"!"),
9478 uri
->values
[0].string
.text
);
9482 jobid
= atoi(resource
+ 6);
9486 * See if the job exists...
9489 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9492 * Nope - return a "not found" error...
9495 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9499 printer
= cupsdFindDest(job
->dest
);
9502 * See if the job is owned by the requesting user...
9505 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9507 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9512 * OK, see if the client is sending the document compressed - CUPS
9513 * only supports "none" and "gzip".
9516 compression
= CUPS_FILE_NONE
;
9518 if ((attr
= ippFindAttribute(con
->request
, "compression",
9519 IPP_TAG_KEYWORD
)) != NULL
)
9521 if (strcmp(attr
->values
[0].string
.text
, "none")
9523 && strcmp(attr
->values
[0].string
.text
, "gzip")
9524 #endif /* HAVE_LIBZ */
9527 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9528 attr
->values
[0].string
.text
);
9529 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9530 "compression", NULL
, attr
->values
[0].string
.text
);
9535 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9536 compression
= CUPS_FILE_GZIP
;
9537 #endif /* HAVE_LIBZ */
9541 * Do we have a file to print?
9546 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9551 * Is it a format we support?
9554 if ((format
= ippFindAttribute(con
->request
, "document-format",
9555 IPP_TAG_MIMETYPE
)) != NULL
)
9558 * Grab format from client...
9561 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9564 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9565 format
->values
[0].string
.text
);
9569 else if ((default_format
= cupsGetOption("document-format",
9570 printer
->num_options
,
9571 printer
->options
)) != NULL
)
9574 * Use default document format...
9577 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9579 send_ipp_status(con
, IPP_BAD_REQUEST
,
9580 _("Could not scan type \"%s\"!"),
9588 * No document format attribute? Auto-type it!
9591 strcpy(super
, "application");
9592 strcpy(type
, "octet-stream");
9595 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9598 * Auto-type the file...
9601 ipp_attribute_t
*doc_name
; /* document-name attribute */
9604 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9606 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9607 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9608 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9612 filetype
= mimeType(MimeDatabase
, super
, type
);
9614 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9615 filetype
->super
, filetype
->type
);
9618 filetype
= mimeType(MimeDatabase
, super
, type
);
9620 jformat
= ippFindAttribute(job
->attrs
, "document-format", IPP_TAG_MIMETYPE
);
9624 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9627 * Replace the document-format attribute value with the auto-typed or
9631 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9636 _cupsStrFree(jformat
->values
[0].string
.text
);
9638 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9641 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9642 "document-format", NULL
, mimetype
);
9646 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9647 _("Unsupported format \'%s/%s\'!"), super
, type
);
9648 cupsdLogMessage(CUPSD_LOG_INFO
,
9649 "Hint: Do you have the raw file printing rules enabled?");
9652 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9653 "document-format", NULL
, format
->values
[0].string
.text
);
9658 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9660 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9663 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9664 _("Unsupported format \'%s\'!"), mimetype
);
9666 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9667 "document-format", NULL
, mimetype
);
9673 * Add the file to the job...
9678 if (add_file(con
, job
, filetype
, compression
))
9681 if (stat(con
->filename
, &fileinfo
))
9684 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9686 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9688 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9689 IPP_TAG_INTEGER
)) != NULL
)
9690 attr
->values
[0].integer
+= kbytes
;
9692 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9694 rename(con
->filename
, filename
);
9696 cupsdClearString(&con
->filename
);
9698 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9699 filetype
->super
, filetype
->type
, job
->username
);
9702 * Start the job if this is the last document...
9705 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9706 IPP_TAG_BOOLEAN
)) != NULL
&&
9707 attr
->values
[0].boolean
)
9710 * See if we need to add the ending sheet...
9713 if (cupsdTimeoutJob(job
))
9716 if (job
->state_value
== IPP_JOB_STOPPED
)
9718 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9719 job
->state_value
= IPP_JOB_PENDING
;
9721 else if (job
->state_value
== IPP_JOB_HELD
)
9723 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9724 IPP_TAG_KEYWORD
)) == NULL
)
9725 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9727 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9729 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9730 job
->state_value
= IPP_JOB_PENDING
;
9735 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9741 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9742 IPP_TAG_KEYWORD
)) == NULL
)
9743 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9745 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9747 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9748 job
->state_value
= IPP_JOB_HELD
;
9749 job
->hold_until
= time(NULL
) + 60;
9752 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9759 * Fill in the response info...
9762 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
9765 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9768 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9770 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9772 add_job_state_reasons(con
, job
);
9774 con
->response
->request
.status
.status_code
= IPP_OK
;
9777 * Start the job if necessary...
9786 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9791 cupsd_client_t
*con
, /* I - Client connection */
9792 http_status_t status
, /* I - HTTP status code */
9793 cupsd_printer_t
*printer
) /* I - Printer, if any */
9795 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s",
9796 ippOpString(con
->request
->request
.op
.operation_id
),
9797 httpStatus(status
));
9799 if (status
== HTTP_UNAUTHORIZED
&&
9800 printer
&& printer
->num_auth_info_required
> 0 &&
9801 !strcmp(printer
->auth_info_required
[0], "negotiate"))
9802 cupsdSendError(con
, status
, CUPSD_AUTH_NEGOTIATE
);
9805 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9806 cupsd_location_t
*auth
; /* Pointer to authentication element */
9807 int auth_type
; /* Type of authentication required */
9810 if (printer
->type
& CUPS_PRINTER_CLASS
)
9811 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9813 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9815 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9816 auth
->type
== CUPSD_AUTH_NONE
)
9817 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9819 con
->request
->request
.op
.operation_id
:
9823 auth_type
= CUPSD_AUTH_NONE
;
9824 else if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9825 auth_type
= DefaultAuthType
;
9827 auth_type
= auth
->type
;
9829 cupsdSendError(con
, status
, auth_type
);
9832 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9834 ippDelete(con
->response
);
9835 con
->response
= NULL
;
9842 * 'send_ipp_status()' - Send a status back to the IPP client.
9846 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9847 ipp_status_t status
, /* I - IPP status code */
9848 const char *message
,/* I - Status message */
9849 ...) /* I - Additional args as needed */
9851 va_list ap
; /* Pointer to additional args */
9852 char formatted
[1024]; /* Formatted errror message */
9855 va_start(ap
, message
);
9856 vsnprintf(formatted
, sizeof(formatted
),
9857 _cupsLangString(con
->language
, message
), ap
);
9860 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9861 ippOpString(con
->request
->request
.op
.operation_id
),
9862 ippErrorString(status
), formatted
);
9864 con
->response
->request
.status
.status_code
= status
;
9866 if (ippFindAttribute(con
->response
, "attributes-charset",
9867 IPP_TAG_ZERO
) == NULL
)
9868 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9869 "attributes-charset", NULL
, DefaultCharset
);
9871 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9872 IPP_TAG_ZERO
) == NULL
)
9873 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9874 "attributes-natural-language", NULL
, DefaultLanguage
);
9876 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9877 "status-message", NULL
, formatted
);
9882 * 'set_default()' - Set the default destination...
9886 set_default(cupsd_client_t
*con
, /* I - Client connection */
9887 ipp_attribute_t
*uri
) /* I - Printer URI */
9889 http_status_t status
; /* Policy status */
9890 cups_ptype_t dtype
; /* Destination type (printer/class) */
9891 cupsd_printer_t
*printer
, /* Printer */
9892 *oldprinter
; /* Old default printer */
9895 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9896 con
->http
.fd
, uri
->values
[0].string
.text
);
9899 * Is the destination valid?
9902 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9908 send_ipp_status(con
, IPP_NOT_FOUND
,
9909 _("The printer or class was not found."));
9917 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9919 send_http_error(con
, status
, NULL
);
9924 * Set it as the default...
9927 oldprinter
= DefaultPrinter
;
9928 DefaultPrinter
= printer
;
9931 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9932 "%s is no longer the default printer.", oldprinter
->name
);
9934 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9935 "%s is now the default printer.", printer
->name
);
9937 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9938 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
9940 cupsdLogMessage(CUPSD_LOG_INFO
,
9941 "Default destination set to \"%s\" by \"%s\".",
9942 printer
->name
, get_username(con
));
9945 * Everything was ok, so return OK status...
9948 con
->response
->request
.status
.status_code
= IPP_OK
;
9953 * 'set_job_attrs()' - Set job attributes.
9957 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9958 ipp_attribute_t
*uri
) /* I - Job URI */
9960 ipp_attribute_t
*attr
, /* Current attribute */
9961 *attr2
; /* Job attribute */
9962 int jobid
; /* Job ID */
9963 cupsd_job_t
*job
; /* Current job */
9964 char method
[HTTP_MAX_URI
],
9965 /* Method portion of URI */
9966 username
[HTTP_MAX_URI
],
9967 /* Username portion of URI */
9969 /* Host portion of URI */
9970 resource
[HTTP_MAX_URI
];
9971 /* Resource portion of URI */
9972 int port
; /* Port portion of URI */
9973 int event
; /* Events? */
9976 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9977 con
->http
.fd
, uri
->values
[0].string
.text
);
9980 * Start with "everything is OK" status...
9983 con
->response
->request
.status
.status_code
= IPP_OK
;
9986 * See if we have a job URI or a printer URI...
9989 if (!strcmp(uri
->name
, "printer-uri"))
9992 * Got a printer URI; see if we also have a job-id attribute...
9995 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9996 IPP_TAG_INTEGER
)) == NULL
)
9998 send_ipp_status(con
, IPP_BAD_REQUEST
,
9999 _("Got a printer-uri attribute but no job-id!"));
10003 jobid
= attr
->values
[0].integer
;
10008 * Got a job URI; parse it to get the job ID...
10011 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
10012 sizeof(method
), username
, sizeof(username
), host
,
10013 sizeof(host
), &port
, resource
, sizeof(resource
));
10015 if (strncmp(resource
, "/jobs/", 6))
10021 send_ipp_status(con
, IPP_BAD_REQUEST
,
10022 _("Bad job-uri attribute \"%s\"!"),
10023 uri
->values
[0].string
.text
);
10027 jobid
= atoi(resource
+ 6);
10031 * See if the job exists...
10034 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10037 * Nope - return a "not found" error...
10040 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10045 * See if the job has been completed...
10048 if (job
->state_value
> IPP_JOB_STOPPED
)
10051 * Return a "not-possible" error...
10054 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10055 _("Job #%d is finished and cannot be altered!"), jobid
);
10060 * See if the job is owned by the requesting user...
10063 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10065 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
10070 * See what the user wants to change.
10077 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10079 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10082 if (!strcmp(attr
->name
, "attributes-charset") ||
10083 !strcmp(attr
->name
, "attributes-natural-language") ||
10084 !strcmp(attr
->name
, "document-compression") ||
10085 !strcmp(attr
->name
, "document-format") ||
10086 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10087 !strcmp(attr
->name
, "job-document-access-errors") ||
10088 !strcmp(attr
->name
, "job-id") ||
10089 !strcmp(attr
->name
, "job-impressions-completed") ||
10090 !strcmp(attr
->name
, "job-k-octets") ||
10091 !strcmp(attr
->name
, "job-originating-host-name") ||
10092 !strcmp(attr
->name
, "job-originating-user-name") ||
10093 !strcmp(attr
->name
, "job-printer-up-time") ||
10094 !strcmp(attr
->name
, "job-printer-uri") ||
10095 !strcmp(attr
->name
, "job-sheets") ||
10096 !strcmp(attr
->name
, "job-state-message") ||
10097 !strcmp(attr
->name
, "job-state-reasons") ||
10098 !strcmp(attr
->name
, "job-uri") ||
10099 !strcmp(attr
->name
, "number-of-documents") ||
10100 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10101 !strcmp(attr
->name
, "output-device-assigned") ||
10102 !strncmp(attr
->name
, "date-time-at-", 13) ||
10103 !strncmp(attr
->name
, "job-k-octets", 12) ||
10104 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10105 !strncmp(attr
->name
, "time-at-", 8))
10111 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10112 _("%s cannot be changed."), attr
->name
);
10114 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10115 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10120 if (!strcmp(attr
->name
, "job-priority"))
10123 * Change the job priority...
10126 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10128 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10130 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10131 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10133 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10135 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10136 _("Job is completed and cannot be changed."));
10139 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10141 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10142 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10143 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10146 else if (!strcmp(attr
->name
, "job-state"))
10149 * Change the job state...
10152 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10154 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10156 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10157 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10161 switch (attr
->values
[0].integer
)
10163 case IPP_JOB_PENDING
:
10164 case IPP_JOB_HELD
:
10165 if (job
->state_value
> IPP_JOB_HELD
)
10167 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10168 _("Job state cannot be changed."));
10171 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10173 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
10174 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
10176 event
|= CUPSD_EVENT_JOB_STATE
;
10180 case IPP_JOB_PROCESSING
:
10181 case IPP_JOB_STOPPED
:
10182 if (job
->state_value
!= attr
->values
[0].integer
)
10184 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10185 _("Job state cannot be changed."));
10190 case IPP_JOB_CANCELED
:
10191 case IPP_JOB_ABORTED
:
10192 case IPP_JOB_COMPLETED
:
10193 if (job
->state_value
> IPP_JOB_PROCESSING
)
10195 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10196 _("Job state cannot be changed."));
10199 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10200 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
10205 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10207 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10208 IPP_TAG_ZERO
)) != NULL
)
10211 * Some other value; first free the old value...
10214 if (job
->attrs
->prev
)
10215 job
->attrs
->prev
->next
= attr2
->next
;
10217 job
->attrs
->attrs
= attr2
->next
;
10219 if (job
->attrs
->last
== attr2
)
10220 job
->attrs
->last
= job
->attrs
->prev
;
10222 _ippFreeAttr(attr2
);
10225 * Then copy the attribute...
10228 copy_attribute(job
->attrs
, attr
, 0);
10231 * See if the job-name or job-hold-until is being changed.
10234 if (!strcmp(attr
->name
, "job-hold-until"))
10236 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
10238 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10239 cupsdReleaseJob(job
);
10243 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10246 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10249 * Delete the attribute...
10252 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10253 IPP_TAG_ZERO
)) != NULL
)
10255 if (job
->attrs
->prev
)
10256 job
->attrs
->prev
->next
= attr2
->next
;
10258 job
->attrs
->attrs
= attr2
->next
;
10260 if (attr2
== job
->attrs
->last
)
10261 job
->attrs
->last
= job
->attrs
->prev
;
10263 _ippFreeAttr(attr2
);
10265 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10271 * Add new option by copying it...
10274 copy_attribute(job
->attrs
, attr
, 0);
10276 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10285 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10288 * Send events as needed...
10291 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10292 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10293 cupsdFindDest(job
->dest
), job
,
10294 "Job priority changed by user.");
10296 if (event
& CUPSD_EVENT_JOB_STATE
)
10297 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10298 job
->state_value
== IPP_JOB_HELD
?
10299 "Job held by user." : "Job restarted by user.");
10301 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10302 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10303 "Job options changed by user.");
10306 * Start jobs if possible...
10314 * 'set_printer_defaults()' - Set printer default options from a request.
10318 set_printer_defaults(
10319 cupsd_client_t
*con
, /* I - Client connection */
10320 cupsd_printer_t
*printer
) /* I - Printer */
10322 int i
; /* Looping var */
10323 ipp_attribute_t
*attr
; /* Current attribute */
10324 int namelen
; /* Length of attribute name */
10325 char name
[256], /* New attribute name */
10326 value
[256]; /* String version of integer attrs */
10329 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10332 * Skip non-printer attributes...
10335 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10338 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10340 if (!strcmp(attr
->name
, "job-sheets-default"))
10343 * Only allow keywords and names...
10346 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10350 * Only allow job-sheets-default to be set when running without a
10351 * system high classification level...
10354 if (Classification
)
10357 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10359 if (attr
->num_values
> 1)
10360 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10362 cupsdSetString(&printer
->job_sheets
[1], "none");
10364 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10366 cupsdFreePrinterUsers(printer
);
10368 printer
->deny_users
= 0;
10370 if (attr
->value_tag
== IPP_TAG_NAME
&&
10371 (attr
->num_values
> 1 ||
10372 strcmp(attr
->values
[0].string
.text
, "all")))
10374 for (i
= 0; i
< attr
->num_values
; i
++)
10375 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10378 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10380 cupsdFreePrinterUsers(printer
);
10382 printer
->deny_users
= 1;
10384 if (attr
->value_tag
== IPP_TAG_NAME
&&
10385 (attr
->num_values
> 1 ||
10386 strcmp(attr
->values
[0].string
.text
, "none")))
10388 for (i
= 0; i
< attr
->num_values
; i
++)
10389 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10392 else if (!strcmp(attr
->name
, "job-quota-period"))
10394 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10397 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10398 attr
->values
[0].integer
);
10399 cupsdFreeQuotas(printer
);
10401 printer
->quota_period
= attr
->values
[0].integer
;
10403 else if (!strcmp(attr
->name
, "job-k-limit"))
10405 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10408 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10409 attr
->values
[0].integer
);
10410 cupsdFreeQuotas(printer
);
10412 printer
->k_limit
= attr
->values
[0].integer
;
10414 else if (!strcmp(attr
->name
, "job-page-limit"))
10416 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10419 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10420 attr
->values
[0].integer
);
10421 cupsdFreeQuotas(printer
);
10423 printer
->page_limit
= attr
->values
[0].integer
;
10425 else if (!strcmp(attr
->name
, "printer-op-policy"))
10427 cupsd_policy_t
*p
; /* Policy */
10430 if (attr
->value_tag
!= IPP_TAG_NAME
)
10433 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10435 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10436 "Setting printer-op-policy to \"%s\"...",
10437 attr
->values
[0].string
.text
);
10438 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10439 printer
->op_policy_ptr
= p
;
10443 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10444 _("Unknown printer-op-policy \"%s\"."),
10445 attr
->values
[0].string
.text
);
10449 else if (!strcmp(attr
->name
, "printer-error-policy"))
10451 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10454 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10455 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10456 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
10458 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10459 _("Unknown printer-error-policy \"%s\"."),
10460 attr
->values
[0].string
.text
);
10464 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10465 "Setting printer-error-policy to \"%s\"...",
10466 attr
->values
[0].string
.text
);
10467 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10471 * Skip any other non-default attributes...
10474 namelen
= strlen(attr
->name
);
10475 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10476 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10480 * OK, anything else must be a user-defined default...
10483 strlcpy(name
, attr
->name
, sizeof(name
));
10484 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10486 switch (attr
->value_tag
)
10488 case IPP_TAG_DELETEATTR
:
10489 printer
->num_options
= cupsRemoveOption(name
,
10490 printer
->num_options
,
10491 &(printer
->options
));
10492 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10493 "Deleting %s", attr
->name
);
10496 case IPP_TAG_NAME
:
10497 case IPP_TAG_KEYWORD
:
10499 printer
->num_options
= cupsAddOption(name
,
10500 attr
->values
[0].string
.text
,
10501 printer
->num_options
,
10502 &(printer
->options
));
10503 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10504 "Setting %s to \"%s\"...", attr
->name
,
10505 attr
->values
[0].string
.text
);
10508 case IPP_TAG_BOOLEAN
:
10509 printer
->num_options
= cupsAddOption(name
,
10510 attr
->values
[0].boolean
?
10512 printer
->num_options
,
10513 &(printer
->options
));
10514 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10515 "Setting %s to %s...", attr
->name
,
10516 attr
->values
[0].boolean
? "true" : "false");
10519 case IPP_TAG_INTEGER
:
10520 case IPP_TAG_ENUM
:
10521 sprintf(value
, "%d", attr
->values
[0].integer
);
10522 printer
->num_options
= cupsAddOption(name
, value
,
10523 printer
->num_options
,
10524 &(printer
->options
));
10525 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10526 "Setting %s to %s...", attr
->name
, value
);
10529 case IPP_TAG_RANGE
:
10530 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10531 attr
->values
[0].range
.upper
);
10532 printer
->num_options
= cupsAddOption(name
, value
,
10533 printer
->num_options
,
10534 &(printer
->options
));
10535 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10536 "Setting %s to %s...", attr
->name
, value
);
10539 case IPP_TAG_RESOLUTION
:
10540 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10541 attr
->values
[0].resolution
.yres
,
10542 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10544 printer
->num_options
= cupsAddOption(name
, value
,
10545 printer
->num_options
,
10546 &(printer
->options
));
10547 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10548 "Setting %s to %s...", attr
->name
, value
);
10552 /* Do nothing for other values */
10560 * 'start_printer()' - Start a printer.
10564 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10565 ipp_attribute_t
*uri
) /* I - Printer URI */
10567 http_status_t status
; /* Policy status */
10568 cups_ptype_t dtype
; /* Destination type (printer/class) */
10569 cupsd_printer_t
*printer
; /* Printer data */
10572 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10573 con
->http
.fd
, uri
->values
[0].string
.text
);
10576 * Is the destination valid?
10579 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10585 send_ipp_status(con
, IPP_NOT_FOUND
,
10586 _("The printer or class was not found."));
10594 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10596 send_http_error(con
, status
, printer
);
10601 * Start the printer...
10604 printer
->state_message
[0] = '\0';
10606 cupsdStartPrinter(printer
, 1);
10608 if (dtype
& CUPS_PRINTER_CLASS
)
10609 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10610 printer
->name
, get_username(con
));
10612 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10613 printer
->name
, get_username(con
));
10618 * Everything was ok, so return OK status...
10621 con
->response
->request
.status
.status_code
= IPP_OK
;
10626 * 'stop_printer()' - Stop a printer.
10630 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10631 ipp_attribute_t
*uri
) /* I - Printer URI */
10633 http_status_t status
; /* Policy status */
10634 cups_ptype_t dtype
; /* Destination type (printer/class) */
10635 cupsd_printer_t
*printer
; /* Printer data */
10636 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10639 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10640 con
->http
.fd
, uri
->values
[0].string
.text
);
10643 * Is the destination valid?
10646 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10652 send_ipp_status(con
, IPP_NOT_FOUND
,
10653 _("The printer or class was not found."));
10661 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10663 send_http_error(con
, status
, printer
);
10668 * Stop the printer...
10671 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10672 IPP_TAG_TEXT
)) == NULL
)
10673 strcpy(printer
->state_message
, "Paused");
10676 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10677 sizeof(printer
->state_message
));
10680 cupsdStopPrinter(printer
, 1);
10682 if (dtype
& CUPS_PRINTER_CLASS
)
10683 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10684 printer
->name
, get_username(con
));
10686 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10687 printer
->name
, get_username(con
));
10690 * Everything was ok, so return OK status...
10693 con
->response
->request
.status
.status_code
= IPP_OK
;
10698 * 'url_encode_attr()' - URL-encode a string attribute.
10702 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10703 char *buffer
,/* I - String buffer */
10704 int bufsize
)/* I - Size of buffer */
10706 int i
; /* Looping var */
10707 char *bufptr
, /* Pointer into buffer */
10708 *bufend
; /* End of buffer */
10711 strlcpy(buffer
, attr
->name
, bufsize
);
10712 bufptr
= buffer
+ strlen(buffer
);
10713 bufend
= buffer
+ bufsize
- 1;
10715 for (i
= 0; i
< attr
->num_values
; i
++)
10717 if (bufptr
>= bufend
)
10725 if (bufptr
>= bufend
)
10730 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10731 bufptr
, bufend
- bufptr
+ 1);
10733 if (bufptr
>= bufend
)
10744 * 'url_encode_string()' - URL-encode a string.
10747 static char * /* O - End of string */
10748 url_encode_string(const char *s
, /* I - String */
10749 char *buffer
, /* I - String buffer */
10750 int bufsize
) /* I - Size of buffer */
10752 char *bufptr
, /* Pointer into buffer */
10753 *bufend
; /* End of buffer */
10754 static const char *hex
= "0123456789ABCDEF";
10759 bufend
= buffer
+ bufsize
- 1;
10761 while (*s
&& bufptr
< bufend
)
10763 if (*s
== ' ' || *s
== '%')
10765 if (bufptr
>= (bufend
- 2))
10769 *bufptr
++ = hex
[(*s
>> 4) & 15];
10770 *bufptr
++ = hex
[*s
& 15];
10774 else if (*s
== '\'' || *s
== '\\')
10776 if (bufptr
>= (bufend
- 1))
10793 * 'user_allowed()' - See if a user is allowed to print to a queue.
10796 static int /* O - 0 if not allowed, 1 if allowed */
10797 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10798 const char *username
) /* I - Username */
10800 int i
; /* Looping var */
10801 struct passwd
*pw
; /* User password data */
10802 char baseuser
[256], /* Base username */
10803 *baseptr
; /* Pointer to "@" in base username */
10806 if (p
->num_users
== 0)
10809 if (!strcmp(username
, "root"))
10812 if (strchr(username
, '@'))
10815 * Strip @REALM for username check...
10818 strlcpy(baseuser
, username
, sizeof(baseuser
));
10820 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10823 username
= baseuser
;
10826 pw
= getpwnam(username
);
10829 for (i
= 0; i
< p
->num_users
; i
++)
10831 if (p
->users
[i
][0] == '@')
10834 * Check group membership...
10837 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
10840 else if (p
->users
[i
][0] == '#')
10846 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
10849 else if (!strcasecmp(username
, p
->users
[i
]))
10853 return ((i
< p
->num_users
) != p
->deny_users
);
10858 * 'validate_job()' - Validate printer options and destination.
10862 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10863 ipp_attribute_t
*uri
) /* I - Printer URI */
10865 http_status_t status
; /* Policy status */
10866 ipp_attribute_t
*attr
; /* Current attribute */
10867 ipp_attribute_t
*format
; /* Document-format attribute */
10868 cups_ptype_t dtype
; /* Destination type (printer/class) */
10869 char super
[MIME_MAX_SUPER
],
10870 /* Supertype of file */
10871 type
[MIME_MAX_TYPE
];
10872 /* Subtype of file */
10873 cupsd_printer_t
*printer
; /* Printer */
10876 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10877 con
->http
.fd
, uri
->values
[0].string
.text
);
10880 * OK, see if the client is sending the document compressed - CUPS
10881 * doesn't support compression yet...
10884 if ((attr
= ippFindAttribute(con
->request
, "compression",
10885 IPP_TAG_KEYWORD
)) != NULL
&&
10886 !strcmp(attr
->values
[0].string
.text
, "none"))
10888 send_ipp_status(con
, IPP_ATTRIBUTES
,
10889 _("Unsupported compression attribute %s!"),
10890 attr
->values
[0].string
.text
);
10891 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10892 "compression", NULL
, attr
->values
[0].string
.text
);
10897 * Is it a format we support?
10900 if ((format
= ippFindAttribute(con
->request
, "document-format",
10901 IPP_TAG_MIMETYPE
)) != NULL
)
10903 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10906 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
10907 format
->values
[0].string
.text
);
10911 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10912 !mimeType(MimeDatabase
, super
, type
))
10914 cupsdLogMessage(CUPSD_LOG_INFO
,
10915 "Hint: Do you have the raw file printing rules enabled?");
10916 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10917 _("Unsupported format \"%s\"!"),
10918 format
->values
[0].string
.text
);
10919 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10920 "document-format", NULL
, format
->values
[0].string
.text
);
10926 * Is the destination valid?
10929 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10935 send_ipp_status(con
, IPP_NOT_FOUND
,
10936 _("The printer or class was not found."));
10944 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10946 send_http_error(con
, status
, printer
);
10951 * Everything was ok, so return OK status...
10954 con
->response
->request
.status
.status_code
= IPP_OK
;
10959 * 'validate_name()' - Make sure the printer name only contains valid chars.
10962 static int /* O - 0 if name is no good, 1 if good */
10963 validate_name(const char *name
) /* I - Name to check */
10965 const char *ptr
; /* Pointer into name */
10969 * Scan the whole name...
10972 for (ptr
= name
; *ptr
; ptr
++)
10973 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
10977 * All the characters are good; validate the length, too...
10980 return ((ptr
- name
) < 128);
10985 * 'validate_user()' - Validate the user for the request.
10988 static int /* O - 1 if permitted, 0 otherwise */
10989 validate_user(cupsd_job_t
*job
, /* I - Job */
10990 cupsd_client_t
*con
, /* I - Client connection */
10991 const char *owner
, /* I - Owner of job/resource */
10992 char *username
, /* O - Authenticated username */
10993 int userlen
) /* I - Length of username */
10995 cupsd_printer_t
*printer
; /* Printer for job */
10998 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10999 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11001 job
->id
, con
? con
->http
.fd
: 0,
11002 owner
? owner
: "(null)", username
, userlen
);
11005 * Validate input...
11008 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11012 * Get the best authenticated username that is available.
11015 strlcpy(username
, get_username(con
), userlen
);
11018 * Check the username against the owner...
11021 printer
= cupsdFindDest(job
->dest
);
11023 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11024 con
, owner
) == HTTP_OK
);
11029 * End of "$Id: ipp.c 7682 2008-06-21 00:06:02Z mike $".