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 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1676 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1677 IPP_TAG_KEYWORD
)) == NULL
)
1678 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1681 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1682 printer
->options
)) == NULL
)
1685 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1686 "job-hold-until", NULL
, val
);
1688 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1689 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1692 * Hold job until specified time...
1695 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1697 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1698 job
->state_value
= IPP_JOB_HELD
;
1700 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1702 job
->hold_until
= time(NULL
) + 60;
1703 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1704 job
->state_value
= IPP_JOB_HELD
;
1708 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1709 job
->state_value
= IPP_JOB_PENDING
;
1712 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1716 * Add job sheets options...
1719 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1720 IPP_TAG_ZERO
)) == NULL
)
1722 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1723 "Adding default job-sheets values \"%s,%s\"...",
1724 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1726 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1728 attr
->values
[0].string
.text
= _cupsStrAlloc(printer
->job_sheets
[0]);
1729 attr
->values
[1].string
.text
= _cupsStrAlloc(printer
->job_sheets
[1]);
1732 job
->job_sheets
= attr
;
1735 * Enforce classification level if set...
1740 cupsdLogMessage(CUPSD_LOG_INFO
,
1741 "Classification=\"%s\", ClassifyOverride=%d",
1742 Classification
? Classification
: "(null)",
1745 if (ClassifyOverride
)
1747 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1748 (attr
->num_values
== 1 ||
1749 !strcmp(attr
->values
[1].string
.text
, "none")))
1752 * Force the leading banner to have the classification on it...
1755 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1757 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1758 "job-sheets=\"%s,none\", "
1759 "job-originating-user-name=\"%s\"",
1760 Classification
, job
->username
);
1762 else if (attr
->num_values
== 2 &&
1763 strcmp(attr
->values
[0].string
.text
,
1764 attr
->values
[1].string
.text
) &&
1765 strcmp(attr
->values
[0].string
.text
, "none") &&
1766 strcmp(attr
->values
[1].string
.text
, "none"))
1769 * Can't put two different security markings on the same document!
1772 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1774 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1775 "job-sheets=\"%s,%s\", "
1776 "job-originating-user-name=\"%s\"",
1777 attr
->values
[0].string
.text
,
1778 attr
->values
[1].string
.text
, job
->username
);
1780 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1781 strcmp(attr
->values
[0].string
.text
, "none") &&
1782 (attr
->num_values
== 1 ||
1783 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1784 strcmp(attr
->values
[1].string
.text
, "none"))))
1786 if (attr
->num_values
== 1)
1787 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1788 "CLASSIFICATION OVERRIDDEN "
1789 "job-sheets=\"%s\", "
1790 "job-originating-user-name=\"%s\"",
1791 attr
->values
[0].string
.text
, job
->username
);
1793 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1794 "CLASSIFICATION OVERRIDDEN "
1795 "job-sheets=\"%s,%s\",fffff "
1796 "job-originating-user-name=\"%s\"",
1797 attr
->values
[0].string
.text
,
1798 attr
->values
[1].string
.text
, job
->username
);
1801 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1802 (attr
->num_values
== 1 ||
1803 strcmp(attr
->values
[1].string
.text
, Classification
)))
1806 * Force the banner to have the classification on it...
1809 if (attr
->num_values
> 1 &&
1810 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1812 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1813 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1817 if (attr
->num_values
== 1 ||
1818 strcmp(attr
->values
[0].string
.text
, "none"))
1819 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1821 if (attr
->num_values
> 1 &&
1822 strcmp(attr
->values
[1].string
.text
, "none"))
1823 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1826 if (attr
->num_values
> 1)
1827 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1828 "CLASSIFICATION FORCED "
1829 "job-sheets=\"%s,%s\", "
1830 "job-originating-user-name=\"%s\"",
1831 attr
->values
[0].string
.text
,
1832 attr
->values
[1].string
.text
, job
->username
);
1834 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1835 "CLASSIFICATION FORCED "
1836 "job-sheets=\"%s\", "
1837 "job-originating-user-name=\"%s\"",
1838 Classification
, job
->username
);
1843 * See if we need to add the starting sheet...
1846 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1848 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1849 attr
->values
[0].string
.text
);
1851 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1853 cupsdDeleteJob(job
);
1857 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1860 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1861 IPP_TAG_ZERO
)) != NULL
)
1865 * Fill in the response info...
1868 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1869 LocalPort
, job
->id
);
1871 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1874 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1876 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1878 add_job_state_reasons(con
, job
);
1880 con
->response
->request
.status
.status_code
= IPP_OK
;
1883 * Add any job subscriptions...
1886 add_job_subscriptions(con
, job
);
1889 * Set all but the first two attributes to the job attributes group...
1892 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1893 attr
->group_tag
= IPP_TAG_JOB
;
1896 * Fire the "job created" event...
1899 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1902 * Return the new job...
1910 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1911 * upon the job and printer state...
1915 add_job_state_reasons(
1916 cupsd_client_t
*con
, /* I - Client connection */
1917 cupsd_job_t
*job
) /* I - Job info */
1919 cupsd_printer_t
*dest
; /* Destination printer */
1922 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1923 con
, con
->http
.fd
, job
? job
->id
: 0);
1925 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1927 case IPP_JOB_PENDING
:
1928 dest
= cupsdFindDest(job
->dest
);
1930 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1931 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1932 "job-state-reasons", NULL
, "printer-stopped");
1934 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1935 "job-state-reasons", NULL
, "none");
1939 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1940 IPP_TAG_KEYWORD
) != NULL
||
1941 ippFindAttribute(job
->attrs
, "job-hold-until",
1942 IPP_TAG_NAME
) != NULL
)
1943 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1944 "job-state-reasons", NULL
, "job-hold-until-specified");
1946 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1947 "job-state-reasons", NULL
, "job-incoming");
1950 case IPP_JOB_PROCESSING
:
1951 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1952 "job-state-reasons", NULL
, "job-printing");
1955 case IPP_JOB_STOPPED
:
1956 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1957 "job-state-reasons", NULL
, "job-stopped");
1960 case IPP_JOB_CANCELED
:
1961 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1962 "job-state-reasons", NULL
, "job-canceled-by-user");
1965 case IPP_JOB_ABORTED
:
1966 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1967 "job-state-reasons", NULL
, "aborted-by-system");
1970 case IPP_JOB_COMPLETED
:
1971 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1972 "job-state-reasons", NULL
, "job-completed-successfully");
1979 * 'add_job_subscriptions()' - Add any subcriptions for a job.
1983 add_job_subscriptions(
1984 cupsd_client_t
*con
, /* I - Client connection */
1985 cupsd_job_t
*job
) /* I - Newly created job */
1987 int i
; /* Looping var */
1988 ipp_attribute_t
*prev
, /* Previous attribute */
1989 *next
, /* Next attribute */
1990 *attr
; /* Current attribute */
1991 cupsd_subscription_t
*sub
; /* Subscription object */
1992 const char *recipient
, /* notify-recipient-uri */
1993 *pullmethod
; /* notify-pull-method */
1994 ipp_attribute_t
*user_data
; /* notify-user-data */
1995 int interval
; /* notify-time-interval */
1996 unsigned mask
; /* notify-events */
2000 * Find the first subscription group attribute; return if we have
2004 for (attr
= job
->attrs
->attrs
, prev
= NULL
;
2006 prev
= attr
, attr
= attr
->next
)
2007 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
2014 * Process the subscription attributes in the request...
2023 mask
= CUPSD_EVENT_NONE
;
2025 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2027 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2028 attr
->value_tag
== IPP_TAG_URI
)
2031 * Validate the recipient scheme against the ServerBin/notifier
2035 char notifier
[1024], /* Notifier filename */
2036 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2037 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2038 host
[HTTP_MAX_URI
], /* Host portion of URI */
2039 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2040 int port
; /* Port portion of URI */
2043 recipient
= attr
->values
[0].string
.text
;
2045 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2046 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2047 host
, sizeof(host
), &port
,
2048 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2050 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2051 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
2052 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2053 "notify-status-code", IPP_URI_SCHEME
);
2057 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2059 if (access(notifier
, X_OK
))
2061 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2062 _("notify-recipient-uri URI \"%s\" uses unknown "
2063 "scheme!"), recipient
);
2064 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2065 "notify-status-code", IPP_URI_SCHEME
);
2069 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2071 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2072 _("notify-recipient-uri URI \"%s\" is already used!"),
2074 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2075 "notify-status-code", IPP_ATTRIBUTES
);
2079 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2080 attr
->value_tag
== IPP_TAG_KEYWORD
)
2082 pullmethod
= attr
->values
[0].string
.text
;
2084 if (strcmp(pullmethod
, "ippget"))
2086 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2087 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
2088 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2089 "notify-status-code", IPP_ATTRIBUTES
);
2093 else if (!strcmp(attr
->name
, "notify-charset") &&
2094 attr
->value_tag
== IPP_TAG_CHARSET
&&
2095 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2096 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2098 send_ipp_status(con
, IPP_CHARSET
,
2099 _("Character set \"%s\" not supported!"),
2100 attr
->values
[0].string
.text
);
2103 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2104 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2105 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2107 send_ipp_status(con
, IPP_CHARSET
,
2108 _("Language \"%s\" not supported!"),
2109 attr
->values
[0].string
.text
);
2112 else if (!strcmp(attr
->name
, "notify-user-data") &&
2113 attr
->value_tag
== IPP_TAG_STRING
)
2115 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2117 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2118 _("The notify-user-data value is too large "
2119 "(%d > 63 octets)!"),
2120 attr
->values
[0].unknown
.length
);
2126 else if (!strcmp(attr
->name
, "notify-events") &&
2127 attr
->value_tag
== IPP_TAG_KEYWORD
)
2129 for (i
= 0; i
< attr
->num_values
; i
++)
2130 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2132 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2134 send_ipp_status(con
, IPP_BAD_REQUEST
,
2135 _("The notify-lease-duration attribute cannot be "
2136 "used with job subscriptions."));
2139 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2140 attr
->value_tag
== IPP_TAG_INTEGER
)
2141 interval
= attr
->values
[0].integer
;
2146 if (!recipient
&& !pullmethod
)
2149 if (mask
== CUPSD_EVENT_NONE
)
2150 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2152 sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
, recipient
,
2155 sub
->interval
= interval
;
2157 cupsdSetString(&sub
->owner
, job
->username
);
2161 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2162 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2163 sub
->user_data_len
);
2166 ippAddSeparator(con
->response
);
2167 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2168 "notify-subscription-id", sub
->id
);
2174 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2177 * Remove all of the subscription attributes from the job 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, option
= printer
->options
;
3486 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
3488 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
3493 * Encode these options as attributes in the job object...
3496 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
3497 cupsFreeOptions(num_options
, options
);
3502 * 'authenticate_job()' - Set job authentication info.
3506 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
3507 ipp_attribute_t
*uri
) /* I - Job URI */
3509 ipp_attribute_t
*attr
, /* job-id attribute */
3510 *auth_info
; /* auth-info attribute */
3511 int jobid
; /* Job ID */
3512 cupsd_job_t
*job
; /* Current job */
3513 char method
[HTTP_MAX_URI
],
3514 /* Method portion of URI */
3515 username
[HTTP_MAX_URI
],
3516 /* Username portion of URI */
3518 /* Host portion of URI */
3519 resource
[HTTP_MAX_URI
];
3520 /* Resource portion of URI */
3521 int port
; /* Port portion of URI */
3524 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
3525 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
3528 * Start with "everything is OK" status...
3531 con
->response
->request
.status
.status_code
= IPP_OK
;
3534 * See if we have a job URI or a printer URI...
3537 if (!strcmp(uri
->name
, "printer-uri"))
3540 * Got a printer URI; see if we also have a job-id attribute...
3543 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3544 IPP_TAG_INTEGER
)) == NULL
)
3546 send_ipp_status(con
, IPP_BAD_REQUEST
,
3547 _("Got a printer-uri attribute but no job-id!"));
3551 jobid
= attr
->values
[0].integer
;
3556 * Got a job URI; parse it to get the job ID...
3559 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
3560 sizeof(method
), username
, sizeof(username
), host
,
3561 sizeof(host
), &port
, resource
, sizeof(resource
));
3563 if (strncmp(resource
, "/jobs/", 6))
3569 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
3570 uri
->values
[0].string
.text
);
3574 jobid
= atoi(resource
+ 6);
3578 * See if the job exists...
3581 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3584 * Nope - return a "not found" error...
3587 send_ipp_status(con
, IPP_NOT_FOUND
,
3588 _("Job #%d does not exist!"), jobid
);
3593 * See if the job has been completed...
3596 if (job
->state_value
!= IPP_JOB_HELD
)
3599 * Return a "not-possible" error...
3602 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3603 _("Job #%d is not held for authentication!"),
3609 * See if we have already authenticated...
3612 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3614 if (!con
->username
[0] && !auth_info
)
3616 cupsd_printer_t
*printer
; /* Job destination */
3620 * No auth data. If we need to authenticate via Kerberos, send a
3621 * HTTP auth challenge, otherwise just return an IPP error...
3624 printer
= cupsdFindDest(job
->dest
);
3626 if (printer
&& printer
->num_auth_info_required
> 0 &&
3627 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3628 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3630 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3631 _("No authentication information provided!"));
3636 * See if the job is owned by the requesting user...
3639 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3641 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3646 * Save the authentication information for this job...
3649 save_auth_info(con
, job
, auth_info
);
3652 * Reset the job-hold-until value to "no-hold"...
3655 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3656 IPP_TAG_KEYWORD
)) == NULL
)
3657 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3661 attr
->value_tag
= IPP_TAG_KEYWORD
;
3662 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3666 * Release the job and return...
3669 cupsdReleaseJob(job
);
3671 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3676 * 'cancel_all_jobs()' - Cancel all print jobs.
3680 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3681 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3683 http_status_t status
; /* Policy status */
3684 cups_ptype_t dtype
; /* Destination type */
3685 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3686 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3687 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3688 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3689 int port
; /* Port portion of URI */
3690 ipp_attribute_t
*attr
; /* Attribute in request */
3691 const char *username
; /* Username */
3692 int purge
; /* Purge? */
3693 cupsd_printer_t
*printer
; /* Printer */
3696 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3697 con
->http
.fd
, uri
->values
[0].string
.text
);
3700 * See if we have a printer URI...
3703 if (strcmp(uri
->name
, "printer-uri"))
3705 send_ipp_status(con
, IPP_BAD_REQUEST
,
3706 _("The printer-uri attribute is required!"));
3711 * Get the username (if any) for the jobs we want to cancel (only if
3712 * "my-jobs" is specified...
3715 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3716 IPP_TAG_BOOLEAN
)) != NULL
&&
3717 attr
->values
[0].boolean
)
3719 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3720 IPP_TAG_NAME
)) != NULL
)
3721 username
= attr
->values
[0].string
.text
;
3724 send_ipp_status(con
, IPP_BAD_REQUEST
,
3725 _("Missing requesting-user-name attribute!"));
3733 * Look for the "purge-jobs" attribute...
3736 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3737 IPP_TAG_BOOLEAN
)) != NULL
)
3738 purge
= attr
->values
[0].boolean
;
3743 * And if the destination is valid...
3746 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3752 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3753 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3754 hostname
, sizeof(hostname
), &port
,
3755 resource
, sizeof(resource
));
3757 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3758 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3760 send_ipp_status(con
, IPP_NOT_FOUND
,
3761 _("The printer or class was not found."));
3769 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3771 send_http_error(con
, status
, NULL
);
3776 * Cancel all jobs on all printers...
3779 cupsdCancelJobs(NULL
, username
, purge
);
3781 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3782 purge
? "purged" : "canceled", get_username(con
));
3790 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3793 send_http_error(con
, status
, printer
);
3798 * Cancel all of the jobs on the named printer...
3801 cupsdCancelJobs(printer
->name
, username
, purge
);
3803 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3804 printer
->name
, purge
? "purged" : "canceled",
3808 con
->response
->request
.status
.status_code
= IPP_OK
;
3813 * 'cancel_job()' - Cancel a print job.
3817 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3818 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3820 ipp_attribute_t
*attr
; /* Current attribute */
3821 int jobid
; /* Job ID */
3822 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3823 username
[HTTP_MAX_URI
], /* Username portion of URI */
3824 host
[HTTP_MAX_URI
], /* Host portion of URI */
3825 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3826 int port
; /* Port portion of URI */
3827 cupsd_job_t
*job
; /* Job information */
3828 cups_ptype_t dtype
; /* Destination type (printer/class) */
3829 cupsd_printer_t
*printer
; /* Printer data */
3830 int purge
; /* Purge the job? */
3833 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3834 con
->http
.fd
, uri
->values
[0].string
.text
);
3837 * See if we have a job URI or a printer URI...
3840 if (!strcmp(uri
->name
, "printer-uri"))
3843 * Got a printer URI; see if we also have a job-id attribute...
3846 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3847 IPP_TAG_INTEGER
)) == NULL
)
3849 send_ipp_status(con
, IPP_BAD_REQUEST
,
3850 _("Got a printer-uri attribute but no job-id!"));
3854 if ((jobid
= attr
->values
[0].integer
) == 0)
3857 * Find the current job on the specified printer...
3860 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3866 send_ipp_status(con
, IPP_NOT_FOUND
,
3867 _("The printer or class was not found."));
3872 * See if the printer is currently printing a job...
3876 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
3880 * No, see if there are any pending jobs...
3883 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3885 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3886 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3887 !strcasecmp(job
->dest
, printer
->name
))
3894 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3896 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3897 if (job
->state_value
== IPP_JOB_STOPPED
&&
3898 !strcasecmp(job
->dest
, printer
->name
))
3905 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
3916 * Got a job URI; parse it to get the job ID...
3919 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3920 sizeof(scheme
), username
, sizeof(username
), host
,
3921 sizeof(host
), &port
, resource
, sizeof(resource
));
3923 if (strncmp(resource
, "/jobs/", 6))
3929 send_ipp_status(con
, IPP_BAD_REQUEST
,
3930 _("Bad job-uri attribute \"%s\"!"),
3931 uri
->values
[0].string
.text
);
3935 jobid
= atoi(resource
+ 6);
3939 * Look for the "purge-job" attribute...
3942 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3943 IPP_TAG_BOOLEAN
)) != NULL
)
3944 purge
= attr
->values
[0].boolean
;
3949 * See if the job exists...
3952 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3955 * Nope - return a "not found" error...
3958 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
3963 * See if the job is owned by the requesting user...
3966 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3968 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
3973 * See if the job is already completed, canceled, or aborted; if so,
3974 * we can't cancel...
3977 if (job
->state_value
>= IPP_JOB_CANCELED
&& !purge
)
3979 switch (job
->state_value
)
3981 case IPP_JOB_CANCELED
:
3982 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3983 _("Job #%d is already canceled - can\'t cancel."),
3987 case IPP_JOB_ABORTED
:
3988 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3989 _("Job #%d is already aborted - can\'t cancel."),
3994 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3995 _("Job #%d is already completed - can\'t cancel."),
4004 * Cancel the job and return...
4007 cupsdCancelJob(job
, purge
, IPP_JOB_CANCELED
);
4011 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
4014 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
4017 con
->response
->request
.status
.status_code
= IPP_OK
;
4022 * 'cancel_subscription()' - Cancel a subscription.
4026 cancel_subscription(
4027 cupsd_client_t
*con
, /* I - Client connection */
4028 int sub_id
) /* I - Subscription ID */
4030 http_status_t status
; /* Policy status */
4031 cupsd_subscription_t
*sub
; /* Subscription */
4034 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4035 "cancel_subscription(con=%p[%d], sub_id=%d)",
4036 con
, con
->http
.fd
, sub_id
);
4039 * Is the subscription ID valid?
4042 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
4045 * Bad subscription ID...
4048 send_ipp_status(con
, IPP_NOT_FOUND
,
4049 _("notify-subscription-id %d no good!"), sub_id
);
4057 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
4059 con
, sub
->owner
)) != HTTP_OK
)
4061 send_http_error(con
, status
, sub
->dest
);
4066 * Cancel the subscription...
4069 cupsdDeleteSubscription(sub
, 1);
4071 con
->response
->request
.status
.status_code
= IPP_OK
;
4076 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
4079 static int /* O - 1 if OK, 0 if not */
4080 check_rss_recipient(
4081 const char *recipient
) /* I - Recipient URI */
4083 cupsd_subscription_t
*sub
; /* Current subscription */
4086 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
4088 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
4092 * Compare the URIs up to the first ?...
4095 const char *r1
, *r2
;
4097 for (r1
= recipient
, r2
= sub
->recipient
;
4098 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
4110 * 'check_quotas()' - Check quotas for a printer and user.
4113 static int /* O - 1 if OK, 0 if not */
4114 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
4115 cupsd_printer_t
*p
) /* I - Printer or class */
4117 int i
; /* Looping var */
4118 char username
[33]; /* Username */
4119 cupsd_quota_t
*q
; /* Quota data */
4120 #ifdef HAVE_MBR_UID_TO_UUID
4122 * Use Apple membership APIs which require that all names represent
4123 * valid user account or group records accessible by the server.
4126 uuid_t usr_uuid
; /* UUID for job requesting user */
4127 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
4128 uuid_t grp_uuid
; /* UUID for ACL group name entry */
4129 int mbr_err
; /* Error from membership function */
4130 int is_member
; /* Is this user a member? */
4133 * Use standard POSIX APIs for checking users and groups...
4136 struct passwd
*pw
; /* User password data */
4137 #endif /* HAVE_MBR_UID_TO_UUID */
4140 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
4141 con
, con
->http
.fd
, p
, p
->name
);
4144 * Figure out who is printing...
4147 strlcpy(username
, get_username(con
), sizeof(username
));
4150 * Check global active job limits for printers and users...
4153 if (MaxJobsPerPrinter
)
4156 * Check if there are too many pending jobs on this printer...
4159 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
4161 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
4170 * Check if there are too many pending jobs for this user...
4173 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
4175 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
4182 * Check against users...
4185 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
4190 #ifdef HAVE_MBR_UID_TO_UUID
4192 * Get UUID for job requesting user...
4195 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
4201 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4202 "check_quotas: UUID lookup failed for user \"%s\"",
4204 cupsdLogMessage(CUPSD_LOG_INFO
,
4205 "Denying user \"%s\" access to printer \"%s\" "
4206 "(unknown user)...",
4212 * Get UID and GID of requesting user...
4215 pw
= getpwnam(username
);
4217 #endif /* HAVE_MBR_UID_TO_UUID */
4219 for (i
= 0; i
< p
->num_users
; i
++)
4220 if (p
->users
[i
][0] == '@')
4223 * Check group membership...
4226 #ifdef HAVE_MBR_UID_TO_UUID
4227 if (p
->users
[i
][1] == '#')
4229 if (uuid_parse((char *)p
->users
[i
] + 2, grp_uuid
))
4230 uuid_clear(grp_uuid
);
4232 else if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
4236 * Invalid ACL entries are ignored for matching; just record a
4237 * warning in the log...
4240 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4241 "check_quotas: UUID lookup failed for ACL entry "
4242 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4243 cupsdLogMessage(CUPSD_LOG_WARN
,
4244 "Access control entry \"%s\" not a valid group name; "
4245 "entry ignored", p
->users
[i
]);
4248 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
4252 * At this point, there should be no errors, but check anyways...
4255 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4256 "check_quotas: group \"%s\" membership check "
4257 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
4262 * Stop if we found a match...
4269 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
4271 #endif /* HAVE_MBR_UID_TO_UUID */
4273 #ifdef HAVE_MBR_UID_TO_UUID
4276 if (p
->users
[i
][0] == '#')
4278 if (uuid_parse((char *)p
->users
[i
] + 1, usr2_uuid
))
4279 uuid_clear(usr2_uuid
);
4281 else if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
4285 * Invalid ACL entries are ignored for matching; just record a
4286 * warning in the log...
4289 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4290 "check_quotas: UUID lookup failed for ACL entry "
4291 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
4292 cupsdLogMessage(CUPSD_LOG_WARN
,
4293 "Access control entry \"%s\" not a valid user name; "
4294 "entry ignored", p
->users
[i
]);
4297 if ((mbr_err
= mbr_check_membership(usr_uuid
, usr2_uuid
,
4300 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4301 "check_quotas: User \"%s\" identity check failed "
4302 "(err=%d)", p
->users
[i
], mbr_err
);
4310 else if (!strcasecmp(username
, p
->users
[i
]))
4312 #endif /* HAVE_MBR_UID_TO_UUID */
4314 if ((i
< p
->num_users
) == p
->deny_users
)
4316 cupsdLogMessage(CUPSD_LOG_INFO
,
4317 "Denying user \"%s\" access to printer \"%s\"...",
4328 if (AppleQuotas
&& (q
= cupsdFindQuota(p
, username
)) != NULL
)
4331 * TODO: Define these special page count values as constants!
4334 if (q
->page_count
== -4) /* special case: unlimited user */
4336 cupsdLogMessage(CUPSD_LOG_INFO
,
4337 "User \"%s\" request approved for printer %s (%s): "
4339 username
, p
->name
, p
->info
);
4340 q
->page_count
= 0; /* allow user to print */
4343 else if (q
->page_count
== -3) /* quota exceeded */
4345 cupsdLogMessage(CUPSD_LOG_INFO
,
4346 "User \"%s\" request denied for printer %s (%s): "
4347 "quota limit exceeded.",
4348 username
, p
->name
, p
->info
);
4349 q
->page_count
= 2; /* force quota exceeded failure */
4352 else if (q
->page_count
== -2) /* quota disabled for user */
4354 cupsdLogMessage(CUPSD_LOG_INFO
,
4355 "User \"%s\" request denied for printer %s (%s): "
4356 "printing disabled for user.",
4357 username
, p
->name
, p
->info
);
4358 q
->page_count
= 2; /* force quota exceeded failure */
4361 else if (q
->page_count
== -1) /* quota access error */
4363 cupsdLogMessage(CUPSD_LOG_INFO
,
4364 "User \"%s\" request denied for printer %s (%s): "
4365 "unable to determine quota limit.",
4366 username
, p
->name
, p
->info
);
4367 q
->page_count
= 2; /* force quota exceeded failure */
4370 else if (q
->page_count
< 0) /* user not found or other error */
4372 cupsdLogMessage(CUPSD_LOG_INFO
,
4373 "User \"%s\" request denied for printer %s (%s): "
4374 "user disabled / missing quota.",
4375 username
, p
->name
, p
->info
);
4376 q
->page_count
= 2; /* force quota exceeded failure */
4379 else /* page within user limits */
4381 q
->page_count
= 0; /* allow user to print */
4386 #endif /* __APPLE__ */
4387 if (p
->k_limit
|| p
->page_limit
)
4389 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
4391 cupsdLogMessage(CUPSD_LOG_ERROR
,
4392 "Unable to allocate quota data for user \"%s\"!",
4397 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
4398 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
4400 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
4407 * If we have gotten this far, we're done!
4415 * 'copy_attribute()' - Copy a single attribute.
4418 static ipp_attribute_t
* /* O - New attribute */
4420 ipp_t
*to
, /* O - Destination request/response */
4421 ipp_attribute_t
*attr
, /* I - Attribute to copy */
4422 int quickcopy
) /* I - Do a quick copy? */
4424 int i
; /* Looping var */
4425 ipp_attribute_t
*toattr
; /* Destination attribute */
4428 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4429 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
4430 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
4433 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
4436 toattr
= ippAddSeparator(to
);
4439 case IPP_TAG_INTEGER
:
4441 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4442 attr
->name
, attr
->num_values
, NULL
);
4444 for (i
= 0; i
< attr
->num_values
; i
++)
4445 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
4448 case IPP_TAG_BOOLEAN
:
4449 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
4450 attr
->num_values
, NULL
);
4452 for (i
= 0; i
< attr
->num_values
; i
++)
4453 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
4456 case IPP_TAG_STRING
:
4459 case IPP_TAG_KEYWORD
:
4461 case IPP_TAG_URISCHEME
:
4462 case IPP_TAG_CHARSET
:
4463 case IPP_TAG_LANGUAGE
:
4464 case IPP_TAG_MIMETYPE
:
4465 toattr
= ippAddStrings(to
, attr
->group_tag
,
4466 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4467 attr
->name
, attr
->num_values
, NULL
, NULL
);
4471 for (i
= 0; i
< attr
->num_values
; i
++)
4472 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4476 for (i
= 0; i
< attr
->num_values
; i
++)
4477 toattr
->values
[i
].string
.text
=
4478 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4483 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
4484 attr
->values
[0].date
);
4487 case IPP_TAG_RESOLUTION
:
4488 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
4489 attr
->num_values
, IPP_RES_PER_INCH
,
4492 for (i
= 0; i
< attr
->num_values
; i
++)
4494 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
4495 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
4496 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
4500 case IPP_TAG_RANGE
:
4501 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
4502 attr
->num_values
, NULL
, NULL
);
4504 for (i
= 0; i
< attr
->num_values
; i
++)
4506 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
4507 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
4511 case IPP_TAG_TEXTLANG
:
4512 case IPP_TAG_NAMELANG
:
4513 toattr
= ippAddStrings(to
, attr
->group_tag
,
4514 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
4515 attr
->name
, attr
->num_values
, NULL
, NULL
);
4519 for (i
= 0; i
< attr
->num_values
; i
++)
4521 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
4522 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
4527 for (i
= 0; i
< attr
->num_values
; i
++)
4530 toattr
->values
[i
].string
.charset
=
4531 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
4533 toattr
->values
[i
].string
.charset
=
4534 toattr
->values
[0].string
.charset
;
4536 toattr
->values
[i
].string
.text
=
4537 _cupsStrAlloc(attr
->values
[i
].string
.text
);
4542 case IPP_TAG_BEGIN_COLLECTION
:
4543 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
4544 attr
->num_values
, NULL
);
4546 for (i
= 0; i
< attr
->num_values
; i
++)
4548 toattr
->values
[i
].collection
= ippNew();
4549 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
4550 NULL
, IPP_TAG_ZERO
, 0);
4555 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
4556 attr
->name
, attr
->num_values
, NULL
);
4558 for (i
= 0; i
< attr
->num_values
; i
++)
4560 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
4562 if (toattr
->values
[i
].unknown
.length
> 0)
4564 if ((toattr
->values
[i
].unknown
.data
=
4565 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
4566 toattr
->values
[i
].unknown
.length
= 0;
4568 memcpy(toattr
->values
[i
].unknown
.data
,
4569 attr
->values
[i
].unknown
.data
,
4570 toattr
->values
[i
].unknown
.length
);
4573 break; /* anti-compiler-warning-code */
4581 * 'copy_attrs()' - Copy attributes from one request to another.
4585 copy_attrs(ipp_t
*to
, /* I - Destination request */
4586 ipp_t
*from
, /* I - Source request */
4587 cups_array_t
*ra
, /* I - Requested attributes */
4588 ipp_tag_t group
, /* I - Group to copy */
4589 int quickcopy
) /* I - Do a quick copy? */
4591 ipp_attribute_t
*fromattr
; /* Source attribute */
4594 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4595 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4596 to
, from
, ra
, group
, quickcopy
);
4601 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4604 * Filter attributes as needed...
4607 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4608 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4611 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4612 copy_attribute(to
, fromattr
, quickcopy
);
4618 * 'copy_banner()' - Copy a banner file to the requests directory for the
4622 static int /* O - Size of banner file in kbytes */
4623 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4624 cupsd_job_t
*job
, /* I - Job information */
4625 const char *name
) /* I - Name of banner */
4627 int i
; /* Looping var */
4628 int kbytes
; /* Size of banner file in kbytes */
4629 char filename
[1024]; /* Job filename */
4630 cupsd_banner_t
*banner
; /* Pointer to banner */
4631 cups_file_t
*in
; /* Input file */
4632 cups_file_t
*out
; /* Output file */
4633 int ch
; /* Character from file */
4634 char attrname
[255], /* Name of attribute */
4635 *s
; /* Pointer into name */
4636 ipp_attribute_t
*attr
; /* Attribute */
4639 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4640 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4641 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4642 name
? name
: "(null)");
4645 * Find the banner; return if not found or "none"...
4648 if (!name
|| !strcmp(name
, "none") ||
4649 (banner
= cupsdFindBanner(name
)) == NULL
)
4653 * Open the banner and job files...
4656 if (add_file(con
, job
, banner
->filetype
, 0))
4659 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4661 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4663 cupsdLogMessage(CUPSD_LOG_ERROR
,
4664 "Unable to create banner job file %s - %s",
4665 filename
, strerror(errno
));
4670 fchmod(cupsFileNumber(out
), 0640);
4671 fchown(cupsFileNumber(out
), RunUser
, Group
);
4674 * Try the localized banner file under the subdirectory...
4677 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4679 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4682 * Convert ll-cc to ll_CC...
4686 attrname
[3] = toupper(attrname
[3] & 255);
4687 attrname
[4] = toupper(attrname
[4] & 255);
4690 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4693 if (access(filename
, 0) && strlen(attrname
) > 2)
4696 * Wasn't able to find "ll_CC" locale file; try the non-national
4697 * localization banner directory.
4702 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4706 if (access(filename
, 0))
4709 * Use the non-localized banner file.
4712 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4715 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4719 cupsdLogMessage(CUPSD_LOG_ERROR
,
4720 "Unable to open banner template file %s - %s",
4721 filename
, strerror(errno
));
4727 * Parse the file to the end...
4730 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4734 * Get an attribute name...
4737 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4738 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4740 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4750 * Ignore { followed by stuff that is not an attribute name...
4753 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4758 * See if it is defined...
4761 if (attrname
[0] == '?')
4766 if (!strcmp(s
, "printer-name"))
4768 cupsFilePuts(out
, job
->dest
);
4771 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4774 * See if we have a leading question mark...
4777 if (attrname
[0] != '?')
4780 * Nope, write to file as-is; probably a PostScript procedure...
4783 cupsFilePrintf(out
, "{%s}", attrname
);
4790 * Output value(s)...
4793 for (i
= 0; i
< attr
->num_values
; i
++)
4796 cupsFilePutChar(out
, ',');
4798 switch (attr
->value_tag
)
4800 case IPP_TAG_INTEGER
:
4802 if (!strncmp(s
, "time-at-", 8))
4803 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
4805 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4808 case IPP_TAG_BOOLEAN
:
4809 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4812 case IPP_TAG_NOVALUE
:
4813 cupsFilePuts(out
, "novalue");
4816 case IPP_TAG_RANGE
:
4817 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4818 attr
->values
[i
].range
.upper
);
4821 case IPP_TAG_RESOLUTION
:
4822 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4823 attr
->values
[i
].resolution
.yres
,
4824 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4829 case IPP_TAG_STRING
:
4832 case IPP_TAG_KEYWORD
:
4833 case IPP_TAG_CHARSET
:
4834 case IPP_TAG_LANGUAGE
:
4835 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
4838 * Need to quote strings for PS banners...
4843 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4845 if (*p
== '(' || *p
== ')' || *p
== '\\')
4847 cupsFilePutChar(out
, '\\');
4848 cupsFilePutChar(out
, *p
);
4850 else if (*p
< 32 || *p
> 126)
4851 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4853 cupsFilePutChar(out
, *p
);
4857 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4861 break; /* anti-compiler-warning-code */
4865 else if (ch
== '\\') /* Quoted char */
4867 ch
= cupsFileGetChar(in
);
4869 if (ch
!= '{') /* Only do special handling for \{ */
4870 cupsFilePutChar(out
, '\\');
4872 cupsFilePutChar(out
, ch
);
4875 cupsFilePutChar(out
, ch
);
4879 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4881 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4882 IPP_TAG_INTEGER
)) != NULL
)
4883 attr
->values
[0].integer
+= kbytes
;
4892 * 'copy_file()' - Copy a PPD file or interface script...
4895 static int /* O - 0 = success, -1 = error */
4896 copy_file(const char *from
, /* I - Source file */
4897 const char *to
) /* I - Destination file */
4899 cups_file_t
*src
, /* Source file */
4900 *dst
; /* Destination file */
4901 int bytes
; /* Bytes to read/write */
4902 char buffer
[2048]; /* Copy buffer */
4905 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4908 * Open the source and destination file for a copy...
4911 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4914 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4921 * Copy the source file to the destination...
4924 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4925 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
4933 * Close both files and return...
4938 return (cupsFileClose(dst
));
4943 * 'copy_model()' - Copy a PPD model file, substituting default values
4947 static int /* O - 0 = success, -1 = error */
4948 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4949 const char *from
, /* I - Source file */
4950 const char *to
) /* I - Destination file */
4952 fd_set input
; /* select() input set */
4953 struct timeval timeout
; /* select() timeout */
4954 int maxfd
; /* Max file descriptor for select() */
4955 char tempfile
[1024]; /* Temporary PPD file */
4956 int tempfd
; /* Temporary PPD file descriptor */
4957 int temppid
; /* Process ID of cups-driverd */
4958 int temppipe
[2]; /* Temporary pipes */
4959 char *argv
[4], /* Command-line arguments */
4960 *envp
[MAX_ENV
]; /* Environment */
4961 cups_file_t
*src
, /* Source file */
4962 *dst
; /* Destination file */
4963 ppd_file_t
*ppd
; /* PPD file */
4964 int bytes
, /* Bytes from pipe */
4965 total
; /* Total bytes from pipe */
4966 char buffer
[2048]; /* Copy buffer */
4967 int i
; /* Looping var */
4968 char option
[PPD_MAX_NAME
], /* Option name */
4969 choice
[PPD_MAX_NAME
]; /* Choice name */
4970 int num_defaults
; /* Number of default options */
4971 cups_option_t
*defaults
; /* Default options */
4972 char cups_protocol
[PPD_MAX_LINE
];
4973 /* cupsProtocol attribute */
4974 int have_letter
, /* Have Letter size */
4975 have_a4
; /* Have A4 size */
4976 #ifdef HAVE_LIBPAPER
4977 char *paper_result
; /* Paper size name from libpaper */
4978 char system_paper
[64]; /* Paper size name buffer */
4979 #endif /* HAVE_LIBPAPER */
4982 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4983 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4987 * Run cups-driverd to get the PPD file...
4990 argv
[0] = "cups-driverd";
4992 argv
[2] = (char *)from
;
4995 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4997 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4998 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4999 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
5003 cupsdOpenPipe(temppipe
);
5005 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5006 "copy_model: Running \"cups-driverd cat %s\"...", from
);
5008 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
5009 -1, -1, 0, DefaultProfile
, &temppid
))
5020 * Wait up to 30 seconds for the PPD file to be copied...
5025 if (temppipe
[0] > CGIPipes
[0])
5026 maxfd
= temppipe
[0] + 1;
5028 maxfd
= CGIPipes
[0] + 1;
5033 * See if we have data ready...
5039 FD_SET(temppipe
[0], &input
);
5040 FD_SET(CGIPipes
[0], &input
);
5042 timeout
.tv_sec
= 30;
5043 timeout
.tv_usec
= 0;
5045 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
5055 * We have timed out...
5061 if (FD_ISSET(temppipe
[0], &input
))
5064 * Read the PPD file from the pipe, and write it to the PPD file.
5067 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
5069 if (write(tempfd
, buffer
, bytes
) < bytes
)
5078 if (FD_ISSET(CGIPipes
[0], &input
))
5088 * No data from cups-deviced...
5091 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
5097 * Read the source file and see what page sizes are supported...
5100 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
5106 have_letter
= ppdPageSize(ppd
, "Letter") != NULL
;
5107 have_a4
= ppdPageSize(ppd
, "A4") != NULL
;
5110 * Open the destination (if possible) and set the default options...
5115 cups_protocol
[0] = '\0';
5117 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
5120 * Read all of the default lines from the old PPD...
5123 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
5124 if (!strncmp(buffer
, "*Default", 8))
5127 * Add the default option...
5130 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5131 choice
, sizeof(choice
)))
5133 ppd_option_t
*ppdo
; /* PPD option */
5137 * Only add the default if the default hasn't already been
5138 * set and the choice exists in the new PPD...
5141 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
5142 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
5143 ppdFindChoice(ppdo
, choice
))
5144 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
5148 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
5149 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
5153 #ifdef HAVE_LIBPAPER
5154 else if ((paper_result
= systempapername()) != NULL
)
5157 * Set the default media sizes from the systemwide default...
5160 strlcpy(system_paper
, paper_result
, sizeof(system_paper
));
5161 system_paper
[0] = toupper(system_paper
[0] & 255);
5163 if ((!strcmp(system_paper
, "Letter") && have_letter
) ||
5164 (!strcmp(system_paper
, "A4") && have_a4
))
5166 num_defaults
= cupsAddOption("PageSize", system_paper
,
5167 num_defaults
, &defaults
);
5168 num_defaults
= cupsAddOption("PageRegion", system_paper
,
5169 num_defaults
, &defaults
);
5170 num_defaults
= cupsAddOption("PaperDimension", system_paper
,
5171 num_defaults
, &defaults
);
5172 num_defaults
= cupsAddOption("ImageableArea", system_paper
,
5173 num_defaults
, &defaults
);
5176 #endif /* HAVE_LIBPAPER */
5180 * Add the default media sizes...
5182 * Note: These values are generally not valid for large-format devices
5183 * like plotters, however it is probably safe to say that those
5184 * users will configure the media size after initially adding
5185 * the device anyways...
5188 if (!DefaultLanguage
||
5189 !strcasecmp(DefaultLanguage
, "C") ||
5190 !strcasecmp(DefaultLanguage
, "POSIX") ||
5191 !strcasecmp(DefaultLanguage
, "en") ||
5192 !strncasecmp(DefaultLanguage
, "en.", 3) ||
5193 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
5194 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
5195 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
5198 * These are the only locales that will default to "letter" size...
5203 num_defaults
= cupsAddOption("PageSize", "Letter", num_defaults
,
5205 num_defaults
= cupsAddOption("PageRegion", "Letter", num_defaults
,
5207 num_defaults
= cupsAddOption("PaperDimension", "Letter", num_defaults
,
5209 num_defaults
= cupsAddOption("ImageableArea", "Letter", num_defaults
,
5216 * The rest default to "a4" size...
5219 num_defaults
= cupsAddOption("PageSize", "A4", num_defaults
,
5221 num_defaults
= cupsAddOption("PageRegion", "A4", num_defaults
,
5223 num_defaults
= cupsAddOption("PaperDimension", "A4", num_defaults
,
5225 num_defaults
= cupsAddOption("ImageableArea", "A4", num_defaults
,
5233 * Open the source file for a copy...
5236 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
5238 cupsFreeOptions(num_defaults
, defaults
);
5244 * Open the destination file for a copy...
5247 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
5249 cupsFreeOptions(num_defaults
, defaults
);
5256 * Copy the source file to the destination...
5259 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
5261 if (!strncmp(buffer
, "*Default", 8))
5264 * Check for an previous default option choice...
5267 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
5268 choice
, sizeof(choice
)))
5270 const char *val
; /* Default option value */
5273 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
5276 * Substitute the previous choice...
5279 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
5284 cupsFilePrintf(dst
, "%s\n", buffer
);
5287 if (cups_protocol
[0])
5288 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
5290 cupsFreeOptions(num_defaults
, defaults
);
5293 * Close both files and return...
5300 return (cupsFileClose(dst
));
5305 * 'copy_job_attrs()' - Copy job attributes.
5309 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5310 cupsd_job_t
*job
, /* I - Job */
5311 cups_array_t
*ra
) /* I - Requested attributes array */
5313 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
5317 * Send the requested attributes for each job...
5320 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
5321 con
->servername
, con
->serverport
, "/jobs/%d",
5324 if (!ra
|| cupsArrayFind(ra
, "document-count"))
5325 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5326 "document-count", job
->num_files
);
5328 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
5329 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5330 "job-more-info", NULL
, job_uri
);
5332 if (job
->state_value
> IPP_JOB_PROCESSING
&&
5333 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
5334 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
5335 job
->num_files
> 0);
5337 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
5338 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
5339 "job-printer-up-time", time(NULL
));
5341 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
5342 add_job_state_reasons(con
, job
);
5344 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
5345 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
5346 "job-uri", NULL
, job_uri
);
5348 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
5353 * 'copy_printer_attrs()' - Copy printer attributes.
5358 cupsd_client_t
*con
, /* I - Client connection */
5359 cupsd_printer_t
*printer
, /* I - Printer */
5360 cups_array_t
*ra
) /* I - Requested attributes array */
5362 char printer_uri
[HTTP_MAX_URI
];
5364 time_t curtime
; /* Current time */
5365 int i
; /* Looping var */
5366 ipp_attribute_t
*history
; /* History collection */
5370 * Copy the printer attributes to the response using requested-attributes
5371 * and document-format attributes that may be provided by the client.
5374 curtime
= time(NULL
);
5377 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
5378 printer
->recoverable
)
5379 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5380 "com.apple.print.recoverable-message", NULL
,
5381 printer
->recoverable
);
5382 #endif /* __APPLE__ */
5384 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
5385 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5386 "marker-change-time", printer
->marker_time
);
5388 if (printer
->num_printers
> 0 &&
5389 (!ra
|| cupsArrayFind(ra
, "member-uris")))
5391 ipp_attribute_t
*member_uris
; /* member-uris attribute */
5392 cupsd_printer_t
*p2
; /* Printer in class */
5393 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
5396 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
5397 IPP_TAG_URI
, "member-uris",
5398 printer
->num_printers
, NULL
,
5401 for (i
= 0; i
< printer
->num_printers
; i
++)
5403 p2
= printer
->printers
[i
];
5405 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
5406 IPP_TAG_URI
)) != NULL
)
5407 member_uris
->values
[i
].string
.text
=
5408 _cupsStrAlloc(p2_uri
->values
[0].string
.text
);
5411 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
5412 sizeof(printer_uri
), "ipp", NULL
, con
->servername
,
5414 (p2
->type
& CUPS_PRINTER_CLASS
) ?
5415 "/classes/%s" : "/printers/%s", p2
->name
);
5416 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
5422 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
5423 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
5424 "printer-alert", NULL
, printer
->alert
);
5426 if (printer
->alert_description
&&
5427 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
5428 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5429 "printer-alert-description", NULL
,
5430 printer
->alert_description
);
5432 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
5433 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
5434 ippTimeToDate(curtime
));
5437 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
5439 if (printer
->reg_name
)
5440 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5441 "printer-dns-sd-name", NULL
, printer
->reg_name
);
5443 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
5444 "printer-dns-sd-name", 0);
5446 #endif /* HAVE_DNSSD */
5448 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
5449 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5450 "printer-error-policy", NULL
, printer
->error_policy
);
5452 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
5453 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
5454 printer
->accepting
);
5456 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
5457 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
5460 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
5461 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
5462 "printer-op-policy", NULL
, printer
->op_policy
);
5464 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
5465 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
5468 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
5469 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5470 "printer-state-change-time", printer
->state_time
);
5472 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
5473 cupsArrayFind(ra
, "printer-state-history"))
5476 * Printer history is only sent if specifically requested, so that
5477 * older CUPS/IPP clients won't barf on the collection attributes.
5480 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
5481 "printer-state-history",
5482 printer
->num_history
, NULL
);
5484 for (i
= 0; i
< printer
->num_history
; i
++)
5485 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
5486 NULL
, IPP_TAG_ZERO
, 0);
5489 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
5490 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5491 "printer-state-message", NULL
, printer
->state_message
);
5493 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
5494 add_printer_state_reasons(con
, printer
);
5496 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
5498 int type
; /* printer-type value */
5502 * Add the CUPS-specific printer-type attribute...
5505 type
= printer
->type
;
5507 if (printer
== DefaultPrinter
)
5508 type
|= CUPS_PRINTER_DEFAULT
;
5510 if (!printer
->accepting
)
5511 type
|= CUPS_PRINTER_REJECTING
;
5513 if (!printer
->shared
)
5514 type
|= CUPS_PRINTER_NOT_SHARED
;
5516 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
5520 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5521 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5522 "printer-up-time", curtime
);
5524 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
5525 !ippFindAttribute(printer
->attrs
, "printer-uri-supported",
5528 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5529 "ipp", NULL
, con
->servername
, con
->serverport
,
5530 (printer
->type
& CUPS_PRINTER_CLASS
) ?
5531 "/classes/%s" : "/printers/%s", printer
->name
);
5532 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5533 "printer-uri-supported", NULL
, printer_uri
);
5534 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5538 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5539 add_queued_job_count(con
, printer
);
5541 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
5542 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
5547 * 'copy_subscription_attrs()' - Copy subscription attributes.
5551 copy_subscription_attrs(
5552 cupsd_client_t
*con
, /* I - Client connection */
5553 cupsd_subscription_t
*sub
, /* I - Subscription */
5554 cups_array_t
*ra
) /* I - Requested attributes array */
5556 ipp_attribute_t
*attr
; /* Current attribute */
5557 char printer_uri
[HTTP_MAX_URI
];
5559 int count
; /* Number of events */
5560 unsigned mask
; /* Current event mask */
5561 const char *name
; /* Current event name */
5565 * Copy the subscription attributes to the response using the
5566 * requested-attributes attribute that may be provided by the client.
5569 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
5571 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5574 * Simple event list...
5577 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5578 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5579 "notify-events", NULL
, name
);
5584 * Complex event list...
5587 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5588 if (sub
->mask
& mask
)
5591 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5592 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5593 "notify-events", count
, NULL
, NULL
);
5595 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5596 if (sub
->mask
& mask
)
5598 attr
->values
[count
].string
.text
=
5599 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5606 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5607 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5608 "notify-job-id", sub
->job
->id
);
5610 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
5611 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5612 "notify-lease-duration", sub
->lease
);
5614 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5616 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5617 "ipp", NULL
, con
->servername
, con
->serverport
,
5618 "/printers/%s", sub
->dest
->name
);
5619 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5620 "notify-printer-uri", NULL
, printer_uri
);
5623 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
5624 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5625 "notify-recipient-uri", NULL
, sub
->recipient
);
5626 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
5627 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5628 "notify-pull-method", NULL
, "ippget");
5630 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
5631 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5632 "notify-subscriber-user-name", NULL
, sub
->owner
);
5634 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5635 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5636 "notify-subscription-id", sub
->id
);
5638 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
5639 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5640 "notify-time-interval", sub
->interval
);
5642 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5643 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5644 sub
->user_data
, sub
->user_data_len
);
5649 * 'create_job()' - Print a file to a printer or class.
5653 create_job(cupsd_client_t
*con
, /* I - Client connection */
5654 ipp_attribute_t
*uri
) /* I - Printer URI */
5656 cupsd_printer_t
*printer
; /* Printer */
5657 cupsd_job_t
*job
; /* New job */
5660 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5661 con
->http
.fd
, uri
->values
[0].string
.text
);
5664 * Is the destination valid?
5667 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5673 send_ipp_status(con
, IPP_NOT_FOUND
,
5674 _("The printer or class was not found."));
5679 * Create the job object...
5682 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5685 job
->pending_timeout
= 1;
5688 * Save and log the job...
5691 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5692 job
->dest
, job
->username
);
5697 * 'create_requested_array()' - Create an array for the requested-attributes.
5700 static cups_array_t
* /* O - Array of attributes or NULL */
5701 create_requested_array(ipp_t
*request
) /* I - IPP request */
5703 int i
; /* Looping var */
5704 ipp_attribute_t
*requested
; /* requested-attributes attribute */
5705 cups_array_t
*ra
; /* Requested attributes array */
5706 char *value
; /* Current value */
5710 * Get the requested-attributes attribute, and return NULL if we don't
5714 if ((requested
= ippFindAttribute(request
, "requested-attributes",
5715 IPP_TAG_KEYWORD
)) == NULL
)
5719 * If the attribute contains a single "all" keyword, return NULL...
5722 if (requested
->num_values
== 1 &&
5723 !strcmp(requested
->values
[0].string
.text
, "all"))
5727 * Create an array using "strcmp" as the comparison function...
5730 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
5732 for (i
= 0; i
< requested
->num_values
; i
++)
5734 value
= requested
->values
[i
].string
.text
;
5736 if (!strcmp(value
, "job-template"))
5738 cupsArrayAdd(ra
, "copies");
5739 cupsArrayAdd(ra
, "copies-default");
5740 cupsArrayAdd(ra
, "copies-supported");
5741 cupsArrayAdd(ra
, "finishings");
5742 cupsArrayAdd(ra
, "finishings-default");
5743 cupsArrayAdd(ra
, "finishings-supported");
5744 cupsArrayAdd(ra
, "job-hold-until");
5745 cupsArrayAdd(ra
, "job-hold-until-default");
5746 cupsArrayAdd(ra
, "job-hold-until-supported");
5747 cupsArrayAdd(ra
, "job-priority");
5748 cupsArrayAdd(ra
, "job-priority-default");
5749 cupsArrayAdd(ra
, "job-priority-supported");
5750 cupsArrayAdd(ra
, "job-sheets");
5751 cupsArrayAdd(ra
, "job-sheets-default");
5752 cupsArrayAdd(ra
, "job-sheets-supported");
5753 cupsArrayAdd(ra
, "media");
5754 cupsArrayAdd(ra
, "media-default");
5755 cupsArrayAdd(ra
, "media-supported");
5756 cupsArrayAdd(ra
, "multiple-document-handling");
5757 cupsArrayAdd(ra
, "multiple-document-handling-default");
5758 cupsArrayAdd(ra
, "multiple-document-handling-supported");
5759 cupsArrayAdd(ra
, "number-up");
5760 cupsArrayAdd(ra
, "number-up-default");
5761 cupsArrayAdd(ra
, "number-up-supported");
5762 cupsArrayAdd(ra
, "orientation-requested");
5763 cupsArrayAdd(ra
, "orientation-requested-default");
5764 cupsArrayAdd(ra
, "orientation-requested-supported");
5765 cupsArrayAdd(ra
, "page-ranges");
5766 cupsArrayAdd(ra
, "page-ranges-supported");
5767 cupsArrayAdd(ra
, "printer-resolution");
5768 cupsArrayAdd(ra
, "printer-resolution-default");
5769 cupsArrayAdd(ra
, "printer-resolution-supported");
5770 cupsArrayAdd(ra
, "print-quality");
5771 cupsArrayAdd(ra
, "print-quality-default");
5772 cupsArrayAdd(ra
, "print-quality-supported");
5773 cupsArrayAdd(ra
, "sides");
5774 cupsArrayAdd(ra
, "sides-default");
5775 cupsArrayAdd(ra
, "sides-supported");
5777 else if (!strcmp(value
, "job-description"))
5779 cupsArrayAdd(ra
, "date-time-at-completed");
5780 cupsArrayAdd(ra
, "date-time-at-creation");
5781 cupsArrayAdd(ra
, "date-time-at-processing");
5782 cupsArrayAdd(ra
, "job-detailed-status-message");
5783 cupsArrayAdd(ra
, "job-document-access-errors");
5784 cupsArrayAdd(ra
, "job-id");
5785 cupsArrayAdd(ra
, "job-impressions");
5786 cupsArrayAdd(ra
, "job-impressions-completed");
5787 cupsArrayAdd(ra
, "job-k-octets");
5788 cupsArrayAdd(ra
, "job-k-octets-processed");
5789 cupsArrayAdd(ra
, "job-media-sheets");
5790 cupsArrayAdd(ra
, "job-media-sheets-completed");
5791 cupsArrayAdd(ra
, "job-message-from-operator");
5792 cupsArrayAdd(ra
, "job-more-info");
5793 cupsArrayAdd(ra
, "job-name");
5794 cupsArrayAdd(ra
, "job-originating-user-name");
5795 cupsArrayAdd(ra
, "job-printer-up-time");
5796 cupsArrayAdd(ra
, "job-printer-uri");
5797 cupsArrayAdd(ra
, "job-state");
5798 cupsArrayAdd(ra
, "job-state-message");
5799 cupsArrayAdd(ra
, "job-state-reasons");
5800 cupsArrayAdd(ra
, "job-uri");
5801 cupsArrayAdd(ra
, "number-of-documents");
5802 cupsArrayAdd(ra
, "number-of-intervening-jobs");
5803 cupsArrayAdd(ra
, "output-device-assigned");
5804 cupsArrayAdd(ra
, "time-at-completed");
5805 cupsArrayAdd(ra
, "time-at-creation");
5806 cupsArrayAdd(ra
, "time-at-processing");
5808 else if (!strcmp(value
, "printer-description"))
5810 cupsArrayAdd(ra
, "charset-configured");
5811 cupsArrayAdd(ra
, "charset-supported");
5812 cupsArrayAdd(ra
, "color-supported");
5813 cupsArrayAdd(ra
, "compression-supported");
5814 cupsArrayAdd(ra
, "document-format-default");
5815 cupsArrayAdd(ra
, "document-format-supported");
5816 cupsArrayAdd(ra
, "generated-natural-language-supported");
5817 cupsArrayAdd(ra
, "ipp-versions-supported");
5818 cupsArrayAdd(ra
, "job-impressions-supported");
5819 cupsArrayAdd(ra
, "job-k-octets-supported");
5820 cupsArrayAdd(ra
, "job-media-sheets-supported");
5821 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
5822 cupsArrayAdd(ra
, "multiple-operation-time-out");
5823 cupsArrayAdd(ra
, "natural-language-configured");
5824 cupsArrayAdd(ra
, "notify-attributes-supported");
5825 cupsArrayAdd(ra
, "notify-lease-duration-default");
5826 cupsArrayAdd(ra
, "notify-lease-duration-supported");
5827 cupsArrayAdd(ra
, "notify-max-events-supported");
5828 cupsArrayAdd(ra
, "notify-events-default");
5829 cupsArrayAdd(ra
, "notify-events-supported");
5830 cupsArrayAdd(ra
, "notify-pull-method-supported");
5831 cupsArrayAdd(ra
, "notify-schemes-supported");
5832 cupsArrayAdd(ra
, "operations-supported");
5833 cupsArrayAdd(ra
, "pages-per-minute");
5834 cupsArrayAdd(ra
, "pages-per-minute-color");
5835 cupsArrayAdd(ra
, "pdl-override-supported");
5836 cupsArrayAdd(ra
, "printer-alert");
5837 cupsArrayAdd(ra
, "printer-alert-description");
5838 cupsArrayAdd(ra
, "printer-commands");
5839 cupsArrayAdd(ra
, "printer-current-time");
5840 cupsArrayAdd(ra
, "printer-driver-installer");
5841 cupsArrayAdd(ra
, "printer-dns-sd-name");
5842 cupsArrayAdd(ra
, "printer-info");
5843 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
5844 cupsArrayAdd(ra
, "printer-location");
5845 cupsArrayAdd(ra
, "printer-make-and-model");
5846 cupsArrayAdd(ra
, "printer-message-from-operator");
5847 cupsArrayAdd(ra
, "printer-more-info");
5848 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
5849 cupsArrayAdd(ra
, "printer-name");
5850 cupsArrayAdd(ra
, "printer-state");
5851 cupsArrayAdd(ra
, "printer-state-message");
5852 cupsArrayAdd(ra
, "printer-state-reasons");
5853 cupsArrayAdd(ra
, "printer-type");
5854 cupsArrayAdd(ra
, "printer-up-time");
5855 cupsArrayAdd(ra
, "printer-uri-supported");
5856 cupsArrayAdd(ra
, "queued-job-count");
5857 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
5858 cupsArrayAdd(ra
, "uri-authentication-supported");
5859 cupsArrayAdd(ra
, "uri-security-supported");
5861 else if (!strcmp(value
, "printer-defaults"))
5863 char *name
; /* Option name */
5866 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5868 name
= (char *)cupsArrayNext(CommonDefaults
))
5869 cupsArrayAdd(ra
, name
);
5871 else if (!strcmp(value
, "subscription-template"))
5873 cupsArrayAdd(ra
, "notify-attributes");
5874 cupsArrayAdd(ra
, "notify-charset");
5875 cupsArrayAdd(ra
, "notify-events");
5876 cupsArrayAdd(ra
, "notify-lease-duration");
5877 cupsArrayAdd(ra
, "notify-natural-language");
5878 cupsArrayAdd(ra
, "notify-pull-method");
5879 cupsArrayAdd(ra
, "notify-recipient-uri");
5880 cupsArrayAdd(ra
, "notify-time-interval");
5881 cupsArrayAdd(ra
, "notify-user-data");
5884 cupsArrayAdd(ra
, value
);
5892 * 'create_subscription()' - Create a notification subscription.
5896 create_subscription(
5897 cupsd_client_t
*con
, /* I - Client connection */
5898 ipp_attribute_t
*uri
) /* I - Printer URI */
5900 http_status_t status
; /* Policy status */
5901 int i
; /* Looping var */
5902 ipp_attribute_t
*attr
; /* Current attribute */
5903 cups_ptype_t dtype
; /* Destination type (printer/class) */
5904 char scheme
[HTTP_MAX_URI
],
5905 /* Scheme portion of URI */
5906 userpass
[HTTP_MAX_URI
],
5907 /* Username portion of URI */
5909 /* Host portion of URI */
5910 resource
[HTTP_MAX_URI
];
5911 /* Resource portion of URI */
5912 int port
; /* Port portion of URI */
5913 cupsd_printer_t
*printer
; /* Printer/class */
5914 cupsd_job_t
*job
; /* Job */
5915 int jobid
; /* Job ID */
5916 cupsd_subscription_t
*sub
; /* Subscription object */
5917 const char *username
, /* requesting-user-name or
5918 authenticated username */
5919 *recipient
, /* notify-recipient-uri */
5920 *pullmethod
; /* notify-pull-method */
5921 ipp_attribute_t
*user_data
; /* notify-user-data */
5922 int interval
, /* notify-time-interval */
5923 lease
; /* notify-lease-duration */
5924 unsigned mask
; /* notify-events */
5925 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5926 *notify_lease
; /* notify-lease-duration(-default) */
5930 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5932 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5933 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5934 attr
->value_tag
, attr
->name
);
5936 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5941 * Is the destination valid?
5944 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5945 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
5946 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5948 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5949 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5950 sizeof(host
), &port
, resource
, sizeof(resource
));
5952 if (!strcmp(resource
, "/"))
5954 dtype
= (cups_ptype_t
)0;
5957 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5959 dtype
= (cups_ptype_t
)0;
5962 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5964 dtype
= CUPS_PRINTER_CLASS
;
5967 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5973 send_ipp_status(con
, IPP_NOT_FOUND
,
5974 _("The printer or class was not found."));
5984 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5987 send_http_error(con
, status
, printer
);
5991 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5993 send_http_error(con
, status
, NULL
);
5998 * Get the user that is requesting the subscription...
6001 username
= get_username(con
);
6004 * Find the first subscription group attribute; return if we have
6008 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
6009 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
6014 send_ipp_status(con
, IPP_BAD_REQUEST
,
6015 _("No subscription attributes in request!"));
6020 * Process the subscription attributes in the request...
6023 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
6031 lease
= DefaultLeaseDuration
;
6033 mask
= CUPSD_EVENT_NONE
;
6037 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
6039 notify_lease
= ippFindAttribute(printer
->attrs
,
6040 "notify-lease-duration-default",
6044 lease
= notify_lease
->values
[0].integer
;
6048 notify_events
= NULL
;
6049 notify_lease
= NULL
;
6052 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
6054 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
6055 attr
->value_tag
== IPP_TAG_URI
)
6058 * Validate the recipient scheme against the ServerBin/notifier
6062 char notifier
[1024]; /* Notifier filename */
6065 recipient
= attr
->values
[0].string
.text
;
6067 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
6068 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
6069 host
, sizeof(host
), &port
,
6070 resource
, sizeof(resource
)) < HTTP_URI_OK
)
6072 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6073 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
6074 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6075 "notify-status-code", IPP_URI_SCHEME
);
6079 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
6081 if (access(notifier
, X_OK
))
6083 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6084 _("notify-recipient-uri URI \"%s\" uses unknown "
6085 "scheme!"), recipient
);
6086 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6087 "notify-status-code", IPP_URI_SCHEME
);
6091 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
6093 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6094 _("notify-recipient-uri URI \"%s\" is already used!"),
6096 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6097 "notify-status-code", IPP_ATTRIBUTES
);
6101 else if (!strcmp(attr
->name
, "notify-pull-method") &&
6102 attr
->value_tag
== IPP_TAG_KEYWORD
)
6104 pullmethod
= attr
->values
[0].string
.text
;
6106 if (strcmp(pullmethod
, "ippget"))
6108 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6109 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
6110 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
6111 "notify-status-code", IPP_ATTRIBUTES
);
6115 else if (!strcmp(attr
->name
, "notify-charset") &&
6116 attr
->value_tag
== IPP_TAG_CHARSET
&&
6117 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
6118 strcmp(attr
->values
[0].string
.text
, "utf-8"))
6120 send_ipp_status(con
, IPP_CHARSET
,
6121 _("Character set \"%s\" not supported!"),
6122 attr
->values
[0].string
.text
);
6125 else if (!strcmp(attr
->name
, "notify-natural-language") &&
6126 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
6127 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
6129 send_ipp_status(con
, IPP_CHARSET
,
6130 _("Language \"%s\" not supported!"),
6131 attr
->values
[0].string
.text
);
6134 else if (!strcmp(attr
->name
, "notify-user-data") &&
6135 attr
->value_tag
== IPP_TAG_STRING
)
6137 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
6139 send_ipp_status(con
, IPP_REQUEST_VALUE
,
6140 _("The notify-user-data value is too large "
6141 "(%d > 63 octets)!"),
6142 attr
->values
[0].unknown
.length
);
6148 else if (!strcmp(attr
->name
, "notify-events") &&
6149 attr
->value_tag
== IPP_TAG_KEYWORD
)
6150 notify_events
= attr
;
6151 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
6152 attr
->value_tag
== IPP_TAG_INTEGER
)
6153 lease
= attr
->values
[0].integer
;
6154 else if (!strcmp(attr
->name
, "notify-time-interval") &&
6155 attr
->value_tag
== IPP_TAG_INTEGER
)
6156 interval
= attr
->values
[0].integer
;
6157 else if (!strcmp(attr
->name
, "notify-job-id") &&
6158 attr
->value_tag
== IPP_TAG_INTEGER
)
6159 jobid
= attr
->values
[0].integer
;
6166 for (i
= 0; i
< notify_events
->num_values
; i
++)
6167 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
6171 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
6173 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
6174 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
6175 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
6177 if (!recipient
&& !pullmethod
)
6180 if (mask
== CUPSD_EVENT_NONE
)
6183 mask
= CUPSD_EVENT_JOB_COMPLETED
;
6185 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
6188 send_ipp_status(con
, IPP_BAD_REQUEST
,
6189 _("notify-events not specified!"));
6194 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
6196 cupsdLogMessage(CUPSD_LOG_INFO
,
6197 "create_subscription: Limiting notify-lease-duration to "
6200 lease
= MaxLeaseDuration
;
6205 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6207 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
6214 sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0);
6217 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
6220 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6221 "Added subscription %d for printer \"%s\"",
6222 sub
->id
, printer
->name
);
6224 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
6227 sub
->interval
= interval
;
6229 sub
->expire
= lease
? time(NULL
) + lease
: 0;
6231 cupsdSetString(&sub
->owner
, username
);
6235 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
6236 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
6237 sub
->user_data_len
);
6240 ippAddSeparator(con
->response
);
6241 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
6242 "notify-subscription-id", sub
->id
);
6244 con
->response
->request
.status
.status_code
= IPP_OK
;
6250 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
6255 * 'delete_printer()' - Remove a printer or class from the system.
6259 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
6260 ipp_attribute_t
*uri
) /* I - URI of printer or class */
6262 http_status_t status
; /* Policy status */
6263 cups_ptype_t dtype
; /* Destination type (printer/class) */
6264 cupsd_printer_t
*printer
; /* Printer/class */
6265 char filename
[1024]; /* Script/PPD filename */
6268 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
6269 con
->http
.fd
, uri
->values
[0].string
.text
);
6272 * Do we have a valid URI?
6275 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6281 send_ipp_status(con
, IPP_NOT_FOUND
,
6282 _("The printer or class was not found."));
6290 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6292 send_http_error(con
, status
, NULL
);
6297 * Remove old jobs...
6300 cupsdCancelJobs(printer
->name
, NULL
, 1);
6303 * Remove old subscriptions and send a "deleted printer" event...
6306 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6307 "%s \"%s\" deleted by \"%s\".",
6308 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6309 printer
->name
, get_username(con
));
6311 cupsdExpireSubscriptions(printer
, NULL
);
6314 * Remove any old PPD or script files...
6317 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
6321 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6327 * Unregister color profiles...
6330 apple_unregister_profiles(printer
);
6331 #endif /* __APPLE__ */
6333 if (dtype
& CUPS_PRINTER_CLASS
)
6335 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6336 printer
->name
, get_username(con
));
6338 cupsdDeletePrinter(printer
, 0);
6339 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6343 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6344 printer
->name
, get_username(con
));
6346 cupsdDeletePrinter(printer
, 0);
6347 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6350 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6353 * Return with no errors...
6356 con
->response
->request
.status
.status_code
= IPP_OK
;
6361 * 'get_default()' - Get the default destination.
6365 get_default(cupsd_client_t
*con
) /* I - Client connection */
6367 http_status_t status
; /* Policy status */
6368 cups_array_t
*ra
; /* Requested attributes array */
6371 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
6377 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6379 send_http_error(con
, status
, NULL
);
6385 ra
= create_requested_array(con
->request
);
6387 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6389 cupsArrayDelete(ra
);
6391 con
->response
->request
.status
.status_code
= IPP_OK
;
6394 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
6399 * 'get_devices()' - Get the list of available devices on the local system.
6403 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6405 http_status_t status
; /* Policy status */
6406 ipp_attribute_t
*limit
, /* limit attribute */
6407 *timeout
, /* timeout attribute */
6408 *requested
, /* requested-attributes attribute */
6409 *exclude
; /* exclude-schemes attribute */
6410 char command
[1024], /* cups-deviced command */
6411 options
[1024], /* Options to pass to command */
6413 /* String for requested attributes */
6415 /* String for excluded attributes */
6418 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
6424 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6426 send_http_error(con
, status
, NULL
);
6431 * Run cups-deviced command with the given options...
6434 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6435 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6436 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6438 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6441 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6443 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6446 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6448 exclude_str
[0] = '\0';
6450 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6451 snprintf(options
, sizeof(options
),
6452 "%d+%d+%d+%d+%s%s%s",
6453 con
->request
->request
.op
.request_id
,
6454 limit
? limit
->values
[0].integer
: 0,
6455 timeout
? timeout
->values
[0].integer
: 10,
6458 exclude_str
[0] ? "%20" : "", exclude_str
);
6460 if (cupsdSendCommand(con
, command
, options
, 1))
6463 * Command started successfully, don't send an IPP response here...
6466 ippDelete(con
->response
);
6467 con
->response
= NULL
;
6472 * Command failed, return "internal error" so the user knows something
6476 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6477 _("cups-deviced failed to execute."));
6483 * 'get_document()' - Get a copy of a job file.
6487 get_document(cupsd_client_t
*con
, /* I - Client connection */
6488 ipp_attribute_t
*uri
) /* I - Job URI */
6490 http_status_t status
; /* Policy status */
6491 ipp_attribute_t
*attr
; /* Current attribute */
6492 int jobid
; /* Job ID */
6493 int docnum
; /* Document number */
6494 cupsd_job_t
*job
; /* Current job */
6495 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6496 username
[HTTP_MAX_URI
], /* Username portion of URI */
6497 host
[HTTP_MAX_URI
], /* Host portion of URI */
6498 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6499 int port
; /* Port portion of URI */
6500 char filename
[1024], /* Filename for document */
6501 format
[1024]; /* Format for document */
6504 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6505 con
->http
.fd
, uri
->values
[0].string
.text
);
6508 * See if we have a job URI or a printer URI...
6511 if (!strcmp(uri
->name
, "printer-uri"))
6514 * Got a printer URI; see if we also have a job-id attribute...
6517 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6518 IPP_TAG_INTEGER
)) == NULL
)
6520 send_ipp_status(con
, IPP_BAD_REQUEST
,
6521 _("Got a printer-uri attribute but no job-id!"));
6525 jobid
= attr
->values
[0].integer
;
6530 * Got a job URI; parse it to get the job ID...
6533 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6534 sizeof(method
), username
, sizeof(username
), host
,
6535 sizeof(host
), &port
, resource
, sizeof(resource
));
6537 if (strncmp(resource
, "/jobs/", 6))
6543 send_ipp_status(con
, IPP_BAD_REQUEST
,
6544 _("Bad job-uri attribute \"%s\"!"),
6545 uri
->values
[0].string
.text
);
6549 jobid
= atoi(resource
+ 6);
6553 * See if the job exists...
6556 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6559 * Nope - return a "not found" error...
6562 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6570 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6572 send_http_error(con
, status
, NULL
);
6577 * Get the document number...
6580 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6581 IPP_TAG_INTEGER
)) == NULL
)
6583 send_ipp_status(con
, IPP_BAD_REQUEST
,
6584 _("Missing document-number attribute!"));
6588 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6589 attr
->num_values
> 1)
6591 send_ipp_status(con
, IPP_NOT_FOUND
, _("Document %d not found in job %d."),
6596 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6598 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6600 cupsdLogMessage(CUPSD_LOG_ERROR
,
6601 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6603 send_ipp_status(con
, IPP_NOT_FOUND
,
6604 _("Unable to open document %d in job %d!"), docnum
, jobid
);
6608 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6612 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6613 job
->filetypes
[docnum
- 1]->type
);
6615 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6617 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6619 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6620 IPP_TAG_NAME
)) != NULL
)
6621 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6622 NULL
, attr
->values
[0].string
.text
);
6627 * 'get_job_attrs()' - Get job attributes.
6631 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6632 ipp_attribute_t
*uri
) /* I - Job URI */
6634 http_status_t status
; /* Policy status */
6635 ipp_attribute_t
*attr
; /* Current attribute */
6636 int jobid
; /* Job ID */
6637 cupsd_job_t
*job
; /* Current job */
6638 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6639 username
[HTTP_MAX_URI
], /* Username portion of URI */
6640 host
[HTTP_MAX_URI
], /* Host portion of URI */
6641 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6642 int port
; /* Port portion of URI */
6643 cups_array_t
*ra
; /* Requested attributes array */
6646 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6647 con
->http
.fd
, uri
->values
[0].string
.text
);
6650 * See if we have a job URI or a printer URI...
6653 if (!strcmp(uri
->name
, "printer-uri"))
6656 * Got a printer URI; see if we also have a job-id attribute...
6659 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6660 IPP_TAG_INTEGER
)) == NULL
)
6662 send_ipp_status(con
, IPP_BAD_REQUEST
,
6663 _("Got a printer-uri attribute but no job-id!"));
6667 jobid
= attr
->values
[0].integer
;
6672 * Got a job URI; parse it to get the job ID...
6675 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6676 sizeof(method
), username
, sizeof(username
), host
,
6677 sizeof(host
), &port
, resource
, sizeof(resource
));
6679 if (strncmp(resource
, "/jobs/", 6))
6685 send_ipp_status(con
, IPP_BAD_REQUEST
,
6686 _("Bad job-uri attribute \"%s\"!"),
6687 uri
->values
[0].string
.text
);
6691 jobid
= atoi(resource
+ 6);
6695 * See if the job exists...
6698 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6701 * Nope - return a "not found" error...
6704 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6712 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6714 send_http_error(con
, status
, NULL
);
6719 * Copy attributes...
6724 ra
= create_requested_array(con
->request
);
6725 copy_job_attrs(con
, job
, ra
);
6726 cupsArrayDelete(ra
);
6728 con
->response
->request
.status
.status_code
= IPP_OK
;
6733 * 'get_jobs()' - Get a list of jobs for the specified printer.
6737 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6738 ipp_attribute_t
*uri
) /* I - Printer URI */
6740 http_status_t status
; /* Policy status */
6741 ipp_attribute_t
*attr
; /* Current attribute */
6742 const char *dest
; /* Destination */
6743 cups_ptype_t dtype
; /* Destination type (printer/class) */
6744 cups_ptype_t dmask
; /* Destination type mask */
6745 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6746 username
[HTTP_MAX_URI
], /* Username portion of URI */
6747 host
[HTTP_MAX_URI
], /* Host portion of URI */
6748 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6749 int port
; /* Port portion of URI */
6750 int completed
; /* Completed jobs? */
6751 int first_job_id
; /* First job ID */
6752 int limit
; /* Maximum number of jobs to return */
6753 int count
; /* Number of jobs that match */
6754 cupsd_job_t
*job
; /* Current job pointer */
6755 cupsd_printer_t
*printer
; /* Printer */
6756 cups_array_t
*list
; /* Which job list... */
6757 cups_array_t
*ra
; /* Requested attributes array */
6760 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6761 uri
->values
[0].string
.text
);
6764 * Is the destination valid?
6767 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6768 sizeof(scheme
), username
, sizeof(username
), host
,
6769 sizeof(host
), &port
, resource
, sizeof(resource
));
6771 if (!strcmp(resource
, "/") ||
6772 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
6775 dtype
= (cups_ptype_t
)0;
6776 dmask
= (cups_ptype_t
)0;
6779 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6782 dtype
= (cups_ptype_t
)0;
6783 dmask
= CUPS_PRINTER_CLASS
;
6786 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6789 dtype
= CUPS_PRINTER_CLASS
;
6790 dmask
= CUPS_PRINTER_CLASS
;
6793 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6800 send_ipp_status(con
, IPP_NOT_FOUND
,
6801 _("The printer or class was not found."));
6806 dtype
&= CUPS_PRINTER_CLASS
;
6807 dmask
= CUPS_PRINTER_CLASS
;
6816 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
6819 send_http_error(con
, status
, printer
);
6823 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6825 send_http_error(con
, status
, NULL
);
6830 * See if the "which-jobs" attribute have been specified...
6833 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6834 IPP_TAG_KEYWORD
)) != NULL
&&
6835 !strcmp(attr
->values
[0].string
.text
, "completed"))
6840 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
6845 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "printing"))
6848 list
= PrintingJobs
;
6857 * See if they want to limit the number of jobs reported...
6860 if ((attr
= ippFindAttribute(con
->request
, "limit",
6861 IPP_TAG_INTEGER
)) != NULL
)
6862 limit
= attr
->values
[0].integer
;
6866 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6867 IPP_TAG_INTEGER
)) != NULL
)
6868 first_job_id
= attr
->values
[0].integer
;
6873 * See if we only want to see jobs for a specific user...
6876 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6877 IPP_TAG_BOOLEAN
)) != NULL
&&
6878 attr
->values
[0].boolean
)
6879 strlcpy(username
, get_username(con
), sizeof(username
));
6883 ra
= create_requested_array(con
->request
);
6886 * OK, build a list of jobs for this printer...
6889 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6890 (limit
<= 0 || count
< limit
) && job
;
6891 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6894 * Filter out jobs that don't match...
6897 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
6899 if (!job
->dest
|| !job
->username
)
6902 if (!job
->dest
|| !job
->username
)
6905 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6906 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6908 if ((job
->dtype
& dmask
) != dtype
&&
6909 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6911 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
6914 if (job
->id
< first_job_id
)
6922 if (username
[0] && strcasecmp(username
, job
->username
))
6926 ippAddSeparator(con
->response
);
6930 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
6932 copy_job_attrs(con
, job
, ra
);
6935 cupsArrayDelete(ra
);
6937 con
->response
->request
.status
.status_code
= IPP_OK
;
6942 * 'get_notifications()' - Get events for a subscription.
6946 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6948 int i
, j
; /* Looping vars */
6949 http_status_t status
; /* Policy status */
6950 cupsd_subscription_t
*sub
; /* Subscription */
6951 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6952 *sequences
; /* notify-sequence-numbers */
6953 int min_seq
; /* Minimum sequence number */
6954 int interval
; /* Poll interval */
6957 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6961 * Get subscription attributes...
6964 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6966 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6971 send_ipp_status(con
, IPP_BAD_REQUEST
,
6972 _("Missing notify-subscription-ids attribute!"));
6977 * Are the subscription IDs valid?
6980 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6982 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6985 * Bad subscription ID...
6988 send_ipp_status(con
, IPP_NOT_FOUND
,
6989 _("notify-subscription-id %d no good!"),
6990 ids
->values
[i
].integer
);
6998 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7000 con
, sub
->owner
)) != HTTP_OK
)
7002 send_http_error(con
, status
, sub
->dest
);
7007 * Check the subscription type and update the interval accordingly.
7010 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
7013 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
7015 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
7021 * Tell the client to poll again in N seconds...
7025 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7026 "notify-get-interval", interval
);
7028 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
7029 "printer-up-time", time(NULL
));
7032 * Copy the subscription event attributes to the response.
7035 con
->response
->request
.status
.status_code
=
7036 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
7038 for (i
= 0; i
< ids
->num_values
; i
++)
7041 * Get the subscription and sequence number...
7044 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
7046 if (sequences
&& i
< sequences
->num_values
)
7047 min_seq
= sequences
->values
[i
].integer
;
7052 * If we don't have any new events, nothing to do here...
7055 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
7059 * Otherwise copy all of the new events...
7062 if (sub
->first_event_id
> min_seq
)
7065 j
= min_seq
- sub
->first_event_id
;
7067 for (; j
< sub
->num_events
; j
++)
7069 ippAddSeparator(con
->response
);
7071 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
7072 IPP_TAG_EVENT_NOTIFICATION
, 0);
7079 * 'get_ppd()' - Get a named PPD from the local system.
7083 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7084 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7086 http_status_t status
; /* Policy status */
7087 cupsd_printer_t
*dest
; /* Destination */
7088 cups_ptype_t dtype
; /* Destination type */
7091 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7092 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7094 if (!strcmp(uri
->name
, "ppd-name"))
7097 * Return a PPD file from cups-driverd...
7100 char command
[1024], /* cups-driverd command */
7101 options
[1024], /* Options to pass to command */
7102 ppd_name
[1024]; /* ppd-name */
7109 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7111 send_http_error(con
, status
, NULL
);
7116 * Run cups-driverd command with the given options...
7119 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7120 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
7121 snprintf(options
, sizeof(options
), "get+%d+%s",
7122 con
->request
->request
.op
.request_id
, ppd_name
);
7124 if (cupsdSendCommand(con
, command
, options
, 0))
7127 * Command started successfully, don't send an IPP response here...
7130 ippDelete(con
->response
);
7131 con
->response
= NULL
;
7136 * Command failed, return "internal error" so the user knows something
7140 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7141 _("cups-driverd failed to execute."));
7144 else if (!strcmp(uri
->name
, "printer-uri") &&
7145 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
7147 int i
; /* Looping var */
7148 char filename
[1024]; /* PPD filename */
7155 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7157 send_http_error(con
, status
, dest
);
7162 * See if we need the PPD for a class or remote printer...
7165 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7168 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7170 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7171 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7172 "printer-uri", NULL
, dest
->uri
);
7175 else if (dtype
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
7177 for (i
= 0; i
< dest
->num_printers
; i
++)
7178 if (!(dest
->printers
[i
]->type
&
7179 (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
)))
7181 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
7182 dest
->printers
[i
]->name
);
7184 if (!access(filename
, 0))
7188 if (i
< dest
->num_printers
)
7189 dest
= dest
->printers
[i
];
7192 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
7193 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
7194 "printer-uri", NULL
, dest
->printers
[0]->uri
);
7200 * Found the printer with the PPD file, now see if there is one...
7203 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7205 send_ipp_status(con
, IPP_NOT_FOUND
,
7206 _("The PPD file \"%s\" could not be opened: %s"),
7207 uri
->values
[0].string
.text
, strerror(errno
));
7211 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7215 con
->response
->request
.status
.status_code
= IPP_OK
;
7218 send_ipp_status(con
, IPP_NOT_FOUND
,
7219 _("The PPD file \"%s\" could not be found."),
7220 uri
->values
[0].string
.text
);
7225 * 'get_ppds()' - Get the list of PPD files on the local system.
7229 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7231 http_status_t status
; /* Policy status */
7232 ipp_attribute_t
*limit
, /* Limit attribute */
7233 *device
, /* ppd-device-id attribute */
7234 *language
, /* ppd-natural-language attribute */
7235 *make
, /* ppd-make attribute */
7236 *model
, /* ppd-make-and-model attribute */
7237 *model_number
, /* ppd-model-number attribute */
7238 *product
, /* ppd-product attribute */
7239 *psversion
, /* ppd-psverion attribute */
7240 *type
, /* ppd-type attribute */
7241 *requested
; /* requested-attributes attribute */
7242 char command
[1024], /* cups-driverd command */
7243 options
[1024], /* Options to pass to command */
7244 device_str
[256],/* Escaped ppd-device-id string */
7246 /* Escaped ppd-natural-language */
7247 make_str
[256], /* Escaped ppd-make string */
7248 model_str
[256], /* Escaped ppd-make-and-model string */
7249 model_number_str
[256],
7250 /* ppd-model-number string */
7252 /* Escaped ppd-product string */
7254 /* Escaped ppd-psversion string */
7255 type_str
[256], /* Escaped ppd-type string */
7257 /* String for requested attributes */
7260 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
7266 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7268 send_http_error(con
, status
, NULL
);
7273 * Run cups-driverd command with the given options...
7276 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7277 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7278 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7280 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7281 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7283 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7285 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7286 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7287 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7288 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7292 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7294 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7297 url_encode_attr(device
, device_str
, sizeof(device_str
));
7299 device_str
[0] = '\0';
7302 url_encode_attr(language
, language_str
, sizeof(language_str
));
7304 language_str
[0] = '\0';
7307 url_encode_attr(make
, make_str
, sizeof(make_str
));
7312 url_encode_attr(model
, model_str
, sizeof(model_str
));
7314 model_str
[0] = '\0';
7317 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7318 model_number
->values
[0].integer
);
7320 model_number_str
[0] = '\0';
7323 url_encode_attr(product
, product_str
, sizeof(product_str
));
7325 product_str
[0] = '\0';
7328 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7330 psversion_str
[0] = '\0';
7333 url_encode_attr(type
, type_str
, sizeof(type_str
));
7337 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7338 snprintf(options
, sizeof(options
),
7339 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7340 con
->request
->request
.op
.request_id
,
7341 limit
? limit
->values
[0].integer
: 0,
7343 device
? "%20" : "", device_str
,
7344 language
? "%20" : "", language_str
,
7345 make
? "%20" : "", make_str
,
7346 model
? "%20" : "", model_str
,
7347 model_number
? "%20" : "", model_number_str
,
7348 product
? "%20" : "", product_str
,
7349 psversion
? "%20" : "", psversion_str
,
7350 type
? "%20" : "", type_str
);
7352 if (cupsdSendCommand(con
, command
, options
, 0))
7355 * Command started successfully, don't send an IPP response here...
7358 ippDelete(con
->response
);
7359 con
->response
= NULL
;
7364 * Command failed, return "internal error" so the user knows something
7368 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7369 _("cups-driverd failed to execute."));
7375 * 'get_printer_attrs()' - Get printer attributes.
7379 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7380 ipp_attribute_t
*uri
) /* I - Printer URI */
7382 http_status_t status
; /* Policy status */
7383 cups_ptype_t dtype
; /* Destination type (printer/class) */
7384 cupsd_printer_t
*printer
; /* Printer/class */
7385 cups_array_t
*ra
; /* Requested attributes array */
7388 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7389 con
->http
.fd
, uri
->values
[0].string
.text
);
7392 * Is the destination valid?
7395 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7401 send_ipp_status(con
, IPP_NOT_FOUND
,
7402 _("The printer or class was not found."));
7410 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7412 send_http_error(con
, status
, printer
);
7417 * Send the attributes...
7420 ra
= create_requested_array(con
->request
);
7422 copy_printer_attrs(con
, printer
, ra
);
7424 cupsArrayDelete(ra
);
7426 con
->response
->request
.status
.status_code
= IPP_OK
;
7431 * 'get_printers()' - Get a list of printers or classes.
7435 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7436 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7438 http_status_t status
; /* Policy status */
7439 ipp_attribute_t
*attr
; /* Current attribute */
7440 int limit
; /* Max number of printers to return */
7441 int count
; /* Number of printers that match */
7442 cupsd_printer_t
*printer
; /* Current printer pointer */
7443 int printer_type
, /* printer-type attribute */
7444 printer_mask
; /* printer-type-mask attribute */
7445 char *location
; /* Location string */
7446 const char *username
; /* Current user */
7447 char *first_printer_name
; /* first-printer-name attribute */
7448 cups_array_t
*ra
; /* Requested attributes array */
7451 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7452 con
->http
.fd
, type
);
7458 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7460 send_http_error(con
, status
, NULL
);
7465 * Check for printers...
7468 if (!Printers
|| !cupsArrayCount(Printers
))
7470 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7475 * See if they want to limit the number of printers reported...
7478 if ((attr
= ippFindAttribute(con
->request
, "limit",
7479 IPP_TAG_INTEGER
)) != NULL
)
7480 limit
= attr
->values
[0].integer
;
7484 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7485 IPP_TAG_NAME
)) != NULL
)
7486 first_printer_name
= attr
->values
[0].string
.text
;
7488 first_printer_name
= NULL
;
7491 * Support filtering...
7494 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7495 IPP_TAG_ENUM
)) != NULL
)
7496 printer_type
= attr
->values
[0].integer
;
7500 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7501 IPP_TAG_ENUM
)) != NULL
)
7502 printer_mask
= attr
->values
[0].integer
;
7506 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7507 IPP_TAG_TEXT
)) != NULL
)
7508 location
= attr
->values
[0].string
.text
;
7512 if (con
->username
[0])
7513 username
= con
->username
;
7514 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7515 IPP_TAG_NAME
)) != NULL
)
7516 username
= attr
->values
[0].string
.text
;
7520 ra
= create_requested_array(con
->request
);
7523 * OK, build a list of printers for this printer...
7526 if (first_printer_name
)
7528 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7529 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7532 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7535 count
< limit
&& printer
;
7536 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7538 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7539 (printer
->type
& printer_mask
) == printer_type
&&
7540 (!location
|| !printer
->location
||
7541 !strcasecmp(printer
->location
, location
)))
7544 * If HideImplicitMembers is enabled, see if this printer or class
7545 * is a member of an implicit class...
7548 if (ImplicitClasses
&& HideImplicitMembers
&&
7549 printer
->in_implicit_class
)
7553 * If a username is specified, see if it is allowed or denied
7557 if (!(printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
7558 printer
->num_users
&& username
&& !user_allowed(printer
, username
))
7562 * Add the group separator as needed...
7566 ippAddSeparator(con
->response
);
7571 * Send the attributes...
7574 copy_printer_attrs(con
, printer
, ra
);
7578 cupsArrayDelete(ra
);
7580 con
->response
->request
.status
.status_code
= IPP_OK
;
7585 * 'get_subscription_attrs()' - Get subscription attributes.
7589 get_subscription_attrs(
7590 cupsd_client_t
*con
, /* I - Client connection */
7591 int sub_id
) /* I - Subscription ID */
7593 http_status_t status
; /* Policy status */
7594 cupsd_subscription_t
*sub
; /* Subscription */
7595 cups_array_t
*ra
; /* Requested attributes array */
7598 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7599 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7600 con
, con
->http
.fd
, sub_id
);
7603 * Is the subscription ID valid?
7606 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7609 * Bad subscription ID...
7612 send_ipp_status(con
, IPP_NOT_FOUND
,
7613 _("notify-subscription-id %d no good!"), sub_id
);
7621 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7623 con
, sub
->owner
)) != HTTP_OK
)
7625 send_http_error(con
, status
, sub
->dest
);
7630 * Copy the subscription attributes to the response using the
7631 * requested-attributes attribute that may be provided by the client.
7634 ra
= create_requested_array(con
->request
);
7636 copy_subscription_attrs(con
, sub
, ra
);
7638 cupsArrayDelete(ra
);
7640 con
->response
->request
.status
.status_code
= IPP_OK
;
7645 * 'get_subscriptions()' - Get subscriptions.
7649 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7650 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7652 http_status_t status
; /* Policy status */
7653 int count
; /* Number of subscriptions */
7654 int limit
; /* Limit */
7655 cupsd_subscription_t
*sub
; /* Subscription */
7656 cups_array_t
*ra
; /* Requested attributes array */
7657 ipp_attribute_t
*attr
; /* Attribute */
7658 cups_ptype_t dtype
; /* Destination type (printer/class) */
7659 char scheme
[HTTP_MAX_URI
],
7660 /* Scheme portion of URI */
7661 username
[HTTP_MAX_URI
],
7662 /* Username portion of URI */
7664 /* Host portion of URI */
7665 resource
[HTTP_MAX_URI
];
7666 /* Resource portion of URI */
7667 int port
; /* Port portion of URI */
7668 cupsd_job_t
*job
; /* Job pointer */
7669 cupsd_printer_t
*printer
; /* Printer */
7672 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7673 "get_subscriptions(con=%p[%d], uri=%s)",
7674 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7677 * Is the destination valid?
7680 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7681 sizeof(scheme
), username
, sizeof(username
), host
,
7682 sizeof(host
), &port
, resource
, sizeof(resource
));
7684 if (!strcmp(resource
, "/") ||
7685 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7686 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7687 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7692 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7695 job
= cupsdFindJob(atoi(resource
+ 6));
7699 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
7704 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7710 send_ipp_status(con
, IPP_NOT_FOUND
,
7711 _("The printer or class was not found."));
7714 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7715 IPP_TAG_INTEGER
)) != NULL
)
7717 job
= cupsdFindJob(attr
->values
[0].integer
);
7721 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
7722 attr
->values
[0].integer
);
7733 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
7735 con
, NULL
)) != HTTP_OK
)
7737 send_http_error(con
, status
, printer
);
7742 * Copy the subscription attributes to the response using the
7743 * requested-attributes attribute that may be provided by the client.
7746 ra
= create_requested_array(con
->request
);
7748 if ((attr
= ippFindAttribute(con
->request
, "limit",
7749 IPP_TAG_INTEGER
)) != NULL
)
7750 limit
= attr
->values
[0].integer
;
7755 * See if we only want to see subscriptions for a specific user...
7758 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7759 IPP_TAG_BOOLEAN
)) != NULL
&&
7760 attr
->values
[0].boolean
)
7761 strlcpy(username
, get_username(con
), sizeof(username
));
7765 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7767 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7768 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7769 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
7771 ippAddSeparator(con
->response
);
7772 copy_subscription_attrs(con
, sub
, ra
);
7775 if (limit
&& count
>= limit
)
7779 cupsArrayDelete(ra
);
7782 con
->response
->request
.status
.status_code
= IPP_OK
;
7784 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7789 * 'get_username()' - Get the username associated with a request.
7792 static const char * /* O - Username */
7793 get_username(cupsd_client_t
*con
) /* I - Connection */
7795 ipp_attribute_t
*attr
; /* Attribute */
7798 if (con
->username
[0])
7799 return (con
->username
);
7800 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7801 IPP_TAG_NAME
)) != NULL
)
7802 return (attr
->values
[0].string
.text
);
7804 return ("anonymous");
7809 * 'hold_job()' - Hold a print job.
7813 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7814 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7816 ipp_attribute_t
*attr
, /* Current job-hold-until */
7817 *newattr
; /* New job-hold-until */
7818 int jobid
; /* Job ID */
7819 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7820 username
[HTTP_MAX_URI
], /* Username portion of URI */
7821 host
[HTTP_MAX_URI
], /* Host portion of URI */
7822 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7823 int port
; /* Port portion of URI */
7824 cupsd_job_t
*job
; /* Job information */
7827 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7828 uri
->values
[0].string
.text
);
7831 * See if we have a job URI or a printer URI...
7834 if (!strcmp(uri
->name
, "printer-uri"))
7837 * Got a printer URI; see if we also have a job-id attribute...
7840 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7841 IPP_TAG_INTEGER
)) == NULL
)
7843 send_ipp_status(con
, IPP_BAD_REQUEST
,
7844 _("Got a printer-uri attribute but no job-id!"));
7848 jobid
= attr
->values
[0].integer
;
7853 * Got a job URI; parse it to get the job ID...
7856 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7857 sizeof(method
), username
, sizeof(username
), host
,
7858 sizeof(host
), &port
, resource
, sizeof(resource
));
7860 if (strncmp(resource
, "/jobs/", 6))
7866 send_ipp_status(con
, IPP_BAD_REQUEST
,
7867 _("Bad job-uri attribute \"%s\"!"),
7868 uri
->values
[0].string
.text
);
7872 jobid
= atoi(resource
+ 6);
7876 * See if the job exists...
7879 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7882 * Nope - return a "not found" error...
7885 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7890 * See if the job is owned by the requesting user...
7893 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7895 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
7900 * Hold the job and return...
7905 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
7906 "Job held by user.");
7908 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
7909 IPP_TAG_KEYWORD
)) == NULL
)
7910 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7912 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7913 IPP_TAG_KEYWORD
)) == NULL
)
7914 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7919 * Free the old hold value and copy the new one over...
7922 _cupsStrFree(attr
->values
[0].string
.text
);
7926 attr
->value_tag
= newattr
->value_tag
;
7927 attr
->values
[0].string
.text
=
7928 _cupsStrAlloc(newattr
->values
[0].string
.text
);
7932 attr
->value_tag
= IPP_TAG_KEYWORD
;
7933 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
7937 * Hold job until specified time...
7940 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
7942 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7943 "Job job-hold-until value changed by user.");
7946 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Held by \"%s\".", username
);
7948 con
->response
->request
.status
.status_code
= IPP_OK
;
7953 * 'move_job()' - Move a job to a new destination.
7957 move_job(cupsd_client_t
*con
, /* I - Client connection */
7958 ipp_attribute_t
*uri
) /* I - Job URI */
7960 http_status_t status
; /* Policy status */
7961 ipp_attribute_t
*attr
; /* Current attribute */
7962 int jobid
; /* Job ID */
7963 cupsd_job_t
*job
; /* Current job */
7964 const char *src
; /* Source printer/class */
7965 cups_ptype_t stype
, /* Source type (printer or class) */
7966 dtype
; /* Destination type (printer/class) */
7967 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7968 username
[HTTP_MAX_URI
], /* Username portion of URI */
7969 host
[HTTP_MAX_URI
], /* Host portion of URI */
7970 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7971 int port
; /* Port portion of URI */
7972 cupsd_printer_t
*sprinter
, /* Source printer */
7973 *dprinter
; /* Destination printer */
7976 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7977 uri
->values
[0].string
.text
);
7980 * Get the new printer or class...
7983 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7984 IPP_TAG_URI
)) == NULL
)
7987 * Need job-printer-uri...
7990 send_ipp_status(con
, IPP_BAD_REQUEST
,
7991 _("job-printer-uri attribute missing!"));
7995 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8001 send_ipp_status(con
, IPP_NOT_FOUND
,
8002 _("The printer or class was not found."));
8007 * See if we have a job URI or a printer URI...
8010 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8011 sizeof(scheme
), username
, sizeof(username
), host
,
8012 sizeof(host
), &port
, resource
, sizeof(resource
));
8014 if (!strcmp(uri
->name
, "printer-uri"))
8017 * Got a printer URI; see if we also have a job-id attribute...
8020 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8021 IPP_TAG_INTEGER
)) == NULL
)
8027 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8028 &sprinter
)) == NULL
)
8034 send_ipp_status(con
, IPP_NOT_FOUND
,
8035 _("The printer or class was not found."));
8044 * Otherwise, just move a single job...
8047 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8050 * Nope - return a "not found" error...
8053 send_ipp_status(con
, IPP_NOT_FOUND
,
8054 _("Job #%d does not exist!"), attr
->values
[0].integer
);
8060 * Job found, initialize source pointers...
8071 * Got a job URI; parse it to get the job ID...
8074 if (strncmp(resource
, "/jobs/", 6))
8080 send_ipp_status(con
, IPP_BAD_REQUEST
,
8081 _("Bad job-uri attribute \"%s\"!"),
8082 uri
->values
[0].string
.text
);
8087 * See if the job exists...
8090 jobid
= atoi(resource
+ 6);
8092 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8095 * Nope - return a "not found" error...
8098 send_ipp_status(con
, IPP_NOT_FOUND
,
8099 _("Job #%d does not exist!"), jobid
);
8105 * Job found, initialize source pointers...
8114 * Check the policy of the destination printer...
8117 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8118 job
? job
->username
: NULL
)) != HTTP_OK
)
8120 send_http_error(con
, status
, dprinter
);
8125 * Now move the job or jobs...
8131 * See if the job has been completed...
8134 if (job
->state_value
> IPP_JOB_STOPPED
)
8137 * Return a "not-possible" error...
8140 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8141 _("Job #%d is finished and cannot be altered!"),
8147 * See if the job is owned by the requesting user...
8150 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8152 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8157 * Move the job to a different printer or class...
8160 cupsdMoveJob(job
, dprinter
);
8165 * Got the source printer, now look through the jobs...
8168 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8170 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8173 * See if the job is pointing at the source printer or has not been
8177 if (strcasecmp(job
->dest
, src
) ||
8178 job
->state_value
> IPP_JOB_STOPPED
)
8182 * See if the job can be moved by the requesting user...
8185 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8189 * Move the job to a different printer or class...
8192 cupsdMoveJob(job
, dprinter
);
8197 * Start jobs if possible...
8203 * Return with "everything is OK" status...
8206 con
->response
->request
.status
.status_code
= IPP_OK
;
8211 * 'ppd_parse_line()' - Parse a PPD default line.
8214 static int /* O - 0 on success, -1 on failure */
8215 ppd_parse_line(const char *line
, /* I - Line */
8216 char *option
, /* O - Option name */
8217 int olen
, /* I - Size of option name */
8218 char *choice
, /* O - Choice name */
8219 int clen
) /* I - Size of choice name */
8222 * Verify this is a default option line...
8225 if (strncmp(line
, "*Default", 8))
8229 * Read the option name...
8232 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
8242 * Skip everything else up to the colon (:)...
8245 while (*line
&& *line
!= ':')
8254 * Now grab the option choice, skipping leading whitespace...
8257 while (isspace(*line
& 255))
8260 for (clen
--; isalnum(*line
& 255); line
++)
8270 * Return with no errors...
8278 * 'print_job()' - Print a file to a printer or class.
8282 print_job(cupsd_client_t
*con
, /* I - Client connection */
8283 ipp_attribute_t
*uri
) /* I - Printer URI */
8285 ipp_attribute_t
*attr
; /* Current attribute */
8286 ipp_attribute_t
*format
; /* Document-format attribute */
8287 const char *default_format
; /* document-format-default value */
8288 cupsd_job_t
*job
; /* New job */
8289 char filename
[1024]; /* Job filename */
8290 mime_type_t
*filetype
; /* Type of file */
8291 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8292 type
[MIME_MAX_TYPE
], /* Subtype of file */
8293 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8294 /* Textual name of mime type */
8295 cupsd_printer_t
*printer
; /* Printer data */
8296 struct stat fileinfo
; /* File information */
8297 int kbytes
; /* Size of file */
8298 int compression
; /* Document compression */
8301 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
8302 uri
->values
[0].string
.text
);
8305 * Validate print file attributes, for now just document-format and
8306 * compression (CUPS only supports "none" and "gzip")...
8309 compression
= CUPS_FILE_NONE
;
8311 if ((attr
= ippFindAttribute(con
->request
, "compression",
8312 IPP_TAG_KEYWORD
)) != NULL
)
8314 if (strcmp(attr
->values
[0].string
.text
, "none")
8316 && strcmp(attr
->values
[0].string
.text
, "gzip")
8317 #endif /* HAVE_LIBZ */
8320 send_ipp_status(con
, IPP_ATTRIBUTES
,
8321 _("Unsupported compression \"%s\"!"),
8322 attr
->values
[0].string
.text
);
8323 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8324 "compression", NULL
, attr
->values
[0].string
.text
);
8329 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8330 compression
= CUPS_FILE_GZIP
;
8331 #endif /* HAVE_LIBZ */
8335 * Do we have a file to print?
8340 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8345 * Is the destination valid?
8348 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8354 send_ipp_status(con
, IPP_NOT_FOUND
,
8355 _("The printer or class was not found."));
8360 * Is it a format we support?
8363 if ((format
= ippFindAttribute(con
->request
, "document-format",
8364 IPP_TAG_MIMETYPE
)) != NULL
)
8367 * Grab format from client...
8370 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
8373 send_ipp_status(con
, IPP_BAD_REQUEST
,
8374 _("Could not scan type \"%s\"!"),
8375 format
->values
[0].string
.text
);
8379 else if ((default_format
= cupsGetOption("document-format",
8380 printer
->num_options
,
8381 printer
->options
)) != NULL
)
8384 * Use default document format...
8387 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8389 send_ipp_status(con
, IPP_BAD_REQUEST
,
8390 _("Could not scan type \"%s\"!"),
8401 strcpy(super
, "application");
8402 strcpy(type
, "octet-stream");
8405 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8408 * Auto-type the file...
8411 ipp_attribute_t
*doc_name
; /* document-name attribute */
8414 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8416 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8417 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8418 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8422 filetype
= mimeType(MimeDatabase
, super
, type
);
8424 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8425 filetype
->super
, filetype
->type
);
8428 filetype
= mimeType(MimeDatabase
, super
, type
);
8432 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8435 * Replace the document-format attribute value with the auto-typed or
8439 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8444 _cupsStrFree(format
->values
[0].string
.text
);
8446 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8449 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8450 "document-format", NULL
, mimetype
);
8454 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8455 _("Unsupported format \'%s/%s\'!"), super
, type
);
8456 cupsdLogMessage(CUPSD_LOG_INFO
,
8457 "Hint: Do you have the raw file printing rules enabled?");
8460 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8461 "document-format", NULL
, format
->values
[0].string
.text
);
8467 * Read any embedded job ticket info from PS files...
8470 if (!strcasecmp(filetype
->super
, "application") &&
8471 !strcasecmp(filetype
->type
, "postscript"))
8472 read_ps_job_ticket(con
);
8475 * Create the job object...
8478 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8482 * Update quota data...
8485 if (stat(con
->filename
, &fileinfo
))
8488 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8490 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8492 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8493 IPP_TAG_INTEGER
)) != NULL
)
8494 attr
->values
[0].integer
+= kbytes
;
8497 * Add the job file...
8500 if (add_file(con
, job
, filetype
, compression
))
8503 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8505 rename(con
->filename
, filename
);
8506 cupsdClearString(&con
->filename
);
8509 * See if we need to add the ending sheet...
8512 if (cupsdTimeoutJob(job
))
8516 * Log and save the job...
8519 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8520 "File of type %s/%s queued by \"%s\".",
8521 filetype
->super
, filetype
->type
, job
->username
);
8522 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8525 * Start the job if possible...
8533 * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
8535 * This function only gets called when printing a single PostScript
8536 * file using the Print-Job operation. It doesn't work for Create-Job +
8537 * Send-File, since the job attributes need to be set at job creation
8538 * time for banners to work. The embedded PS job ticket stuff is here
8539 * only to allow the Windows printer driver for CUPS to pass in JCL
8540 * options and IPP attributes which otherwise would be lost.
8542 * The format of a PS job ticket is simple:
8544 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8546 * %cupsJobTicket: attr1=value1
8547 * %cupsJobTicket: attr2=value2
8549 * %cupsJobTicket: attrN=valueN
8551 * Job ticket lines must appear immediately after the first line that
8552 * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
8553 * looking for job ticket info when it finds a line that does not begin
8554 * with "%cupsJobTicket:".
8556 * The maximum length of a job ticket line, including the prefix, is
8557 * 255 characters to conform with the Adobe DSC.
8559 * Read-only attributes are rejected with a notice to the error log in
8560 * case a malicious user tries anything. Since the job ticket is read
8561 * prior to attribute validation in print_job(), job ticket attributes
8562 * will go through the same validation as IPP attributes...
8566 read_ps_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8568 cups_file_t
*fp
; /* File to read from */
8569 char line
[256]; /* Line data */
8570 int num_options
; /* Number of options */
8571 cups_option_t
*options
; /* Options */
8572 ipp_t
*ticket
; /* New attributes */
8573 ipp_attribute_t
*attr
, /* Current attribute */
8574 *attr2
, /* Job attribute */
8575 *prev2
; /* Previous job attribute */
8579 * First open the print file...
8582 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8584 cupsdLogMessage(CUPSD_LOG_ERROR
,
8585 "read_ps_job_ticket: Unable to open PostScript print file "
8592 * Skip the first line...
8595 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8597 cupsdLogMessage(CUPSD_LOG_ERROR
,
8598 "read_ps_job_ticket: Unable to read from PostScript print "
8605 if (strncmp(line
, "%!PS-Adobe-", 11))
8608 * Not a DSC-compliant file, so no job ticket info will be available...
8616 * Read job ticket info from the file...
8622 while (cupsFileGets(fp
, line
, sizeof(line
)))
8625 * Stop at the first non-ticket line...
8628 if (strncmp(line
, "%cupsJobTicket:", 15))
8632 * Add the options to the option array...
8635 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8639 * Done with the file; see if we have any options...
8644 if (num_options
== 0)
8648 * OK, convert the options to an attribute list, and apply them to
8653 cupsEncodeOptions(ticket
, num_options
, options
);
8656 * See what the user wants to change.
8659 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8661 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8664 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8665 !strcmp(attr
->name
, "job-originating-user-name") ||
8666 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8667 !strcmp(attr
->name
, "job-k-octets") ||
8668 !strcmp(attr
->name
, "job-id") ||
8669 !strncmp(attr
->name
, "job-state", 9) ||
8670 !strncmp(attr
->name
, "time-at-", 8))
8671 continue; /* Read-only attrs */
8673 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8674 IPP_TAG_ZERO
)) != NULL
)
8677 * Some other value; first free the old value...
8680 if (con
->request
->attrs
== attr2
)
8682 con
->request
->attrs
= attr2
->next
;
8687 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8688 if (prev2
->next
== attr2
)
8690 prev2
->next
= attr2
->next
;
8695 if (con
->request
->last
== attr2
)
8696 con
->request
->last
= prev2
;
8698 _ippFreeAttr(attr2
);
8702 * Add new option by copying it...
8705 copy_attribute(con
->request
, attr
, 0);
8709 * Then free the attribute list and option array...
8713 cupsFreeOptions(num_options
, options
);
8718 * 'reject_jobs()' - Reject print jobs to a printer.
8722 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8723 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8725 http_status_t status
; /* Policy status */
8726 cups_ptype_t dtype
; /* Destination type (printer/class) */
8727 cupsd_printer_t
*printer
; /* Printer data */
8728 ipp_attribute_t
*attr
; /* printer-state-message text */
8731 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8732 con
->http
.fd
, uri
->values
[0].string
.text
);
8735 * Is the destination valid?
8738 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8744 send_ipp_status(con
, IPP_NOT_FOUND
,
8745 _("The printer or class was not found."));
8753 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8755 send_http_error(con
, status
, printer
);
8760 * Reject jobs sent to the printer...
8763 printer
->accepting
= 0;
8765 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8766 IPP_TAG_TEXT
)) == NULL
)
8767 strcpy(printer
->state_message
, "Rejecting Jobs");
8769 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8770 sizeof(printer
->state_message
));
8772 cupsdAddPrinterHistory(printer
);
8774 if (dtype
& CUPS_PRINTER_CLASS
)
8776 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8778 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8779 printer
->name
, get_username(con
));
8783 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8785 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8786 printer
->name
, get_username(con
));
8790 * Everything was ok, so return OK status...
8793 con
->response
->request
.status
.status_code
= IPP_OK
;
8798 * 'release_job()' - Release a held print job.
8802 release_job(cupsd_client_t
*con
, /* I - Client connection */
8803 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8805 ipp_attribute_t
*attr
; /* Current attribute */
8806 int jobid
; /* Job ID */
8807 char method
[HTTP_MAX_URI
], /* Method portion of URI */
8808 username
[HTTP_MAX_URI
], /* Username portion of URI */
8809 host
[HTTP_MAX_URI
], /* Host portion of URI */
8810 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8811 int port
; /* Port portion of URI */
8812 cupsd_job_t
*job
; /* Job information */
8815 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8816 con
->http
.fd
, uri
->values
[0].string
.text
);
8819 * See if we have a job URI or a printer URI...
8822 if (!strcmp(uri
->name
, "printer-uri"))
8825 * Got a printer URI; see if we also have a job-id attribute...
8828 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8829 IPP_TAG_INTEGER
)) == NULL
)
8831 send_ipp_status(con
, IPP_BAD_REQUEST
,
8832 _("Got a printer-uri attribute but no job-id!"));
8836 jobid
= attr
->values
[0].integer
;
8841 * Got a job URI; parse it to get the job ID...
8844 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8845 sizeof(method
), username
, sizeof(username
), host
,
8846 sizeof(host
), &port
, resource
, sizeof(resource
));
8848 if (strncmp(resource
, "/jobs/", 6))
8854 send_ipp_status(con
, IPP_BAD_REQUEST
,
8855 _("Bad job-uri attribute \"%s\"!"),
8856 uri
->values
[0].string
.text
);
8860 jobid
= atoi(resource
+ 6);
8864 * See if the job exists...
8867 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8870 * Nope - return a "not found" error...
8873 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8878 * See if job is "held"...
8881 if (job
->state_value
!= IPP_JOB_HELD
)
8884 * Nope - return a "not possible" error...
8887 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
8892 * See if the job is owned by the requesting user...
8895 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8897 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
8902 * Reset the job-hold-until value to "no-hold"...
8905 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8906 IPP_TAG_KEYWORD
)) == NULL
)
8907 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8911 _cupsStrFree(attr
->values
[0].string
.text
);
8913 attr
->value_tag
= IPP_TAG_KEYWORD
;
8914 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8916 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8917 "Job job-hold-until value changed by user.");
8921 * Release the job and return...
8924 cupsdReleaseJob(job
);
8926 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8927 "Job released by user.");
8929 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8931 con
->response
->request
.status
.status_code
= IPP_OK
;
8936 * 'renew_subscription()' - Renew an existing subscription...
8941 cupsd_client_t
*con
, /* I - Client connection */
8942 int sub_id
) /* I - Subscription ID */
8944 http_status_t status
; /* Policy status */
8945 cupsd_subscription_t
*sub
; /* Subscription */
8946 ipp_attribute_t
*lease
; /* notify-lease-duration */
8949 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8950 "renew_subscription(con=%p[%d], sub_id=%d)",
8951 con
, con
->http
.fd
, sub_id
);
8954 * Is the subscription ID valid?
8957 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8960 * Bad subscription ID...
8963 send_ipp_status(con
, IPP_NOT_FOUND
,
8964 _("notify-subscription-id %d no good!"), sub_id
);
8971 * Job subscriptions cannot be renewed...
8974 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8975 _("Job subscriptions cannot be renewed!"));
8983 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8985 con
, sub
->owner
)) != HTTP_OK
)
8987 send_http_error(con
, status
, sub
->dest
);
8992 * Renew the subscription...
8995 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8998 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9000 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9002 cupsdLogMessage(CUPSD_LOG_INFO
,
9003 "renew_subscription: Limiting notify-lease-duration to "
9006 sub
->lease
= MaxLeaseDuration
;
9009 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9011 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9013 con
->response
->request
.status
.status_code
= IPP_OK
;
9015 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9016 "notify-lease-duration", sub
->lease
);
9021 * 'restart_job()' - Restart an old print job.
9025 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9026 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9028 ipp_attribute_t
*attr
; /* Current attribute */
9029 int jobid
; /* Job ID */
9030 char method
[HTTP_MAX_URI
], /* Method portion of URI */
9031 username
[HTTP_MAX_URI
], /* Username portion of URI */
9032 host
[HTTP_MAX_URI
], /* Host portion of URI */
9033 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9034 int port
; /* Port portion of URI */
9035 cupsd_job_t
*job
; /* Job information */
9038 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9039 con
->http
.fd
, uri
->values
[0].string
.text
);
9042 * See if we have a job URI or a printer URI...
9045 if (!strcmp(uri
->name
, "printer-uri"))
9048 * Got a printer URI; see if we also have a job-id attribute...
9051 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9052 IPP_TAG_INTEGER
)) == NULL
)
9054 send_ipp_status(con
, IPP_BAD_REQUEST
,
9055 _("Got a printer-uri attribute but no job-id!"));
9059 jobid
= attr
->values
[0].integer
;
9064 * Got a job URI; parse it to get the job ID...
9067 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9068 sizeof(method
), username
, sizeof(username
), host
,
9069 sizeof(host
), &port
, resource
, sizeof(resource
));
9071 if (strncmp(resource
, "/jobs/", 6))
9077 send_ipp_status(con
, IPP_BAD_REQUEST
,
9078 _("Bad job-uri attribute \"%s\"!"),
9079 uri
->values
[0].string
.text
);
9083 jobid
= atoi(resource
+ 6);
9087 * See if the job exists...
9090 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9093 * Nope - return a "not found" error...
9096 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9101 * See if job is in any of the "completed" states...
9104 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9107 * Nope - return a "not possible" error...
9110 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
9116 * See if we have retained the job files...
9121 if (!job
->attrs
|| job
->num_files
== 0)
9124 * Nope - return a "not possible" error...
9127 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9128 _("Job #%d cannot be restarted - no files!"), jobid
);
9133 * See if the job is owned by the requesting user...
9136 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9138 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9143 * Restart the job and return...
9146 cupsdRestartJob(job
);
9148 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9150 con
->response
->request
.status
.status_code
= IPP_OK
;
9155 * 'save_auth_info()' - Save authentication information for a job.
9160 cupsd_client_t
*con
, /* I - Client connection */
9161 cupsd_job_t
*job
, /* I - Job */
9162 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9164 int i
; /* Looping var */
9165 char filename
[1024]; /* Job authentication filename */
9166 cups_file_t
*fp
; /* Job authentication file */
9167 char line
[2048]; /* Line for file */
9168 cupsd_printer_t
*dest
; /* Destination printer/class */
9172 * This function saves the in-memory authentication information for
9173 * a job so that it can be used to authenticate with a remote host.
9174 * The information is stored in a file that is readable only by the
9175 * root user. The fields are Base-64 encoded, each on a separate line,
9176 * followed by random number (up to 1024) of newlines to limit the
9177 * amount of information that is exposed.
9179 * Because of the potential for exposing of authentication information,
9180 * this functionality is only enabled when running cupsd as root.
9182 * This caching only works for the Basic and BasicDigest authentication
9183 * types. Digest authentication cannot be cached this way, and in
9184 * the future Kerberos authentication may make all of this obsolete.
9186 * Authentication information is saved whenever an authenticated
9187 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9190 * This information is deleted after a job is completed or canceled,
9191 * so reprints may require subsequent re-authentication.
9197 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9201 * Create the authentication file and change permissions...
9204 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9205 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9207 cupsdLogMessage(CUPSD_LOG_ERROR
,
9208 "Unable to save authentication info to \"%s\" - %s",
9209 filename
, strerror(errno
));
9213 fchown(cupsFileNumber(fp
), 0, 0);
9214 fchmod(cupsFileNumber(fp
), 0400);
9216 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9219 * Write 1 to 3 auth values...
9222 cupsdClearString(&job
->auth_username
);
9223 cupsdClearString(&job
->auth_domain
);
9224 cupsdClearString(&job
->auth_password
);
9226 for (i
= 0; i
< auth_info
->num_values
; i
++)
9228 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9229 strlen(auth_info
->values
[i
].string
.text
));
9230 cupsFilePrintf(fp
, "%s\n", line
);
9232 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9233 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s",
9234 auth_info
->values
[i
].string
.text
);
9235 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9236 cupsdSetStringf(&job
->auth_domain
, "AUTH_DOMAIN=%s",
9237 auth_info
->values
[i
].string
.text
);
9238 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9239 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s",
9240 auth_info
->values
[i
].string
.text
);
9243 else if (con
->username
[0])
9246 * Write the authenticated username...
9249 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9250 cupsFilePrintf(fp
, "%s\n", line
);
9252 cupsdSetStringf(&job
->auth_username
, "AUTH_USERNAME=%s", con
->username
);
9253 cupsdClearString(&job
->auth_domain
);
9256 * Write the authenticated password...
9259 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9260 cupsFilePrintf(fp
, "%s\n", line
);
9262 cupsdSetStringf(&job
->auth_password
, "AUTH_PASSWORD=%s", con
->password
);
9266 * Write a random number of newlines to the end of the file...
9269 for (i
= (rand() % 1024); i
>= 0; i
--)
9270 cupsFilePutChar(fp
, '\n');
9273 * Close the file and return...
9278 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9279 if (con
->gss_have_creds
)
9280 save_krb5_creds(con
, job
);
9281 else if (job
->ccname
)
9282 cupsdClearString(&(job
->ccname
));
9283 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9287 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
9289 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
9293 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
9294 cupsd_job_t
*job
) /* I - Job */
9296 # if !defined(HAVE_KRB5_CC_NEW_UNIQUE) && !defined(HAVE_HEIMDAL)
9297 cupsdLogMessage(CUPSD_LOG_INFO
,
9298 "Sorry, your version of Kerberos does not support delegated "
9303 krb5_error_code error
; /* Kerberos error code */
9304 OM_uint32 major_status
, /* Major status code */
9305 minor_status
; /* Minor status code */
9306 krb5_principal principal
; /* Kerberos principal */
9311 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
9315 if (krb5_init_context
== NULL
)
9317 # endif /* __APPLE__ */
9320 * We MUST create a file-based cache because memory-based caches are
9321 * only valid for the current process/address space.
9323 * Due to various bugs/features in different versions of Kerberos, we
9324 * need either the krb5_cc_new_unique() function or Heimdal's version
9325 * of krb5_cc_gen_new() to create a new FILE: credential cache that
9326 * can be passed to the backend. These functions create a temporary
9327 * file (typically in /tmp) containing the cached credentials, which
9328 * are removed when we have successfully printed a job.
9331 # ifdef HAVE_KRB5_CC_NEW_UNIQUE
9332 if ((error
= krb5_cc_new_unique(KerberosContext
, "FILE", NULL
,
9333 &(job
->ccache
))) != 0)
9334 # else /* HAVE_HEIMDAL */
9335 if ((error
= krb5_cc_gen_new(KerberosContext
, &krb5_fcc_ops
,
9336 &(job
->ccache
))) != 0)
9337 # endif /* HAVE_KRB5_CC_NEW_UNIQUE */
9339 cupsdLogMessage(CUPSD_LOG_ERROR
,
9340 "Unable to create new credentials cache (%d/%s)",
9341 error
, strerror(errno
));
9346 if ((error
= krb5_parse_name(KerberosContext
, con
->username
, &principal
)) != 0)
9348 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to parse kerberos username (%d/%s)",
9349 error
, strerror(errno
));
9350 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9355 if ((error
= krb5_cc_initialize(KerberosContext
, job
->ccache
, principal
)))
9357 cupsdLogMessage(CUPSD_LOG_ERROR
,
9358 "Unable to initialize credentials cache (%d/%s)", error
,
9360 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9361 krb5_free_principal(KerberosContext
, principal
);
9366 krb5_free_principal(KerberosContext
, principal
);
9369 * Copy the user's credentials to the new cache file...
9372 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
9375 if (GSS_ERROR(major_status
))
9377 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
9378 "Unable to import client credentials cache");
9379 krb5_cc_destroy(KerberosContext
, job
->ccache
);
9385 * Add the KRB5CCNAME environment variable to the job so that the
9386 * backend can use the credentials when printing.
9389 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
9390 krb5_cc_get_name(KerberosContext
, job
->ccache
));
9392 cupsdLogJob(job
, CUPSD_LOG_DEBUG2
, "save_krb5_creds: %s", job
->ccname
);
9393 # endif /* HAVE_KRB5_CC_NEW_UNIQUE || HAVE_HEIMDAL */
9395 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
9399 * 'send_document()' - Send a file to a printer or class.
9403 send_document(cupsd_client_t
*con
, /* I - Client connection */
9404 ipp_attribute_t
*uri
) /* I - Printer URI */
9406 ipp_attribute_t
*attr
; /* Current attribute */
9407 ipp_attribute_t
*format
; /* Request's document-format attribute */
9408 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9409 const char *default_format
;/* document-format-default value */
9410 int jobid
; /* Job ID number */
9411 cupsd_job_t
*job
; /* Current job */
9412 char job_uri
[HTTP_MAX_URI
],
9414 method
[HTTP_MAX_URI
],
9415 /* Method portion of URI */
9416 username
[HTTP_MAX_URI
],
9417 /* Username portion of URI */
9419 /* Host portion of URI */
9420 resource
[HTTP_MAX_URI
];
9421 /* Resource portion of URI */
9422 int port
; /* Port portion of URI */
9423 mime_type_t
*filetype
; /* Type of file */
9424 char super
[MIME_MAX_SUPER
],
9425 /* Supertype of file */
9426 type
[MIME_MAX_TYPE
],
9427 /* Subtype of file */
9428 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9429 /* Textual name of mime type */
9430 char filename
[1024]; /* Job filename */
9431 cupsd_printer_t
*printer
; /* Current printer */
9432 struct stat fileinfo
; /* File information */
9433 int kbytes
; /* Size of file */
9434 int compression
; /* Type of compression */
9435 int start_job
; /* Start the job? */
9438 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9439 con
->http
.fd
, uri
->values
[0].string
.text
);
9442 * See if we have a job URI or a printer URI...
9445 if (!strcmp(uri
->name
, "printer-uri"))
9448 * Got a printer URI; see if we also have a job-id attribute...
9451 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9452 IPP_TAG_INTEGER
)) == NULL
)
9454 send_ipp_status(con
, IPP_BAD_REQUEST
,
9455 _("Got a printer-uri attribute but no job-id!"));
9459 jobid
= attr
->values
[0].integer
;
9464 * Got a job URI; parse it to get the job ID...
9467 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9468 sizeof(method
), username
, sizeof(username
), host
,
9469 sizeof(host
), &port
, resource
, sizeof(resource
));
9471 if (strncmp(resource
, "/jobs/", 6))
9477 send_ipp_status(con
, IPP_BAD_REQUEST
,
9478 _("Bad job-uri attribute \"%s\"!"),
9479 uri
->values
[0].string
.text
);
9483 jobid
= atoi(resource
+ 6);
9487 * See if the job exists...
9490 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9493 * Nope - return a "not found" error...
9496 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
9500 printer
= cupsdFindDest(job
->dest
);
9503 * See if the job is owned by the requesting user...
9506 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9508 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
9513 * OK, see if the client is sending the document compressed - CUPS
9514 * only supports "none" and "gzip".
9517 compression
= CUPS_FILE_NONE
;
9519 if ((attr
= ippFindAttribute(con
->request
, "compression",
9520 IPP_TAG_KEYWORD
)) != NULL
)
9522 if (strcmp(attr
->values
[0].string
.text
, "none")
9524 && strcmp(attr
->values
[0].string
.text
, "gzip")
9525 #endif /* HAVE_LIBZ */
9528 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
9529 attr
->values
[0].string
.text
);
9530 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9531 "compression", NULL
, attr
->values
[0].string
.text
);
9536 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9537 compression
= CUPS_FILE_GZIP
;
9538 #endif /* HAVE_LIBZ */
9542 * Do we have a file to print?
9547 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
9552 * Is it a format we support?
9555 if ((format
= ippFindAttribute(con
->request
, "document-format",
9556 IPP_TAG_MIMETYPE
)) != NULL
)
9559 * Grab format from client...
9562 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
9565 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9566 format
->values
[0].string
.text
);
9570 else if ((default_format
= cupsGetOption("document-format",
9571 printer
->num_options
,
9572 printer
->options
)) != NULL
)
9575 * Use default document format...
9578 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
9580 send_ipp_status(con
, IPP_BAD_REQUEST
,
9581 _("Could not scan type \"%s\"!"),
9589 * No document format attribute? Auto-type it!
9592 strcpy(super
, "application");
9593 strcpy(type
, "octet-stream");
9596 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9599 * Auto-type the file...
9602 ipp_attribute_t
*doc_name
; /* document-name attribute */
9605 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9607 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9608 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9609 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9613 filetype
= mimeType(MimeDatabase
, super
, type
);
9615 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9616 filetype
->super
, filetype
->type
);
9619 filetype
= mimeType(MimeDatabase
, super
, type
);
9621 jformat
= ippFindAttribute(job
->attrs
, "document-format", IPP_TAG_MIMETYPE
);
9625 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
9628 * Replace the document-format attribute value with the auto-typed or
9632 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9637 _cupsStrFree(jformat
->values
[0].string
.text
);
9639 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9642 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9643 "document-format", NULL
, mimetype
);
9647 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9648 _("Unsupported format \'%s/%s\'!"), super
, type
);
9649 cupsdLogMessage(CUPSD_LOG_INFO
,
9650 "Hint: Do you have the raw file printing rules enabled?");
9653 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9654 "document-format", NULL
, format
->values
[0].string
.text
);
9659 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9661 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9664 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9665 _("Unsupported format \'%s\'!"), mimetype
);
9667 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9668 "document-format", NULL
, mimetype
);
9674 * Add the file to the job...
9679 if (add_file(con
, job
, filetype
, compression
))
9682 if (stat(con
->filename
, &fileinfo
))
9685 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9687 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9689 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9690 IPP_TAG_INTEGER
)) != NULL
)
9691 attr
->values
[0].integer
+= kbytes
;
9693 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9695 rename(con
->filename
, filename
);
9697 cupsdClearString(&con
->filename
);
9699 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9700 filetype
->super
, filetype
->type
, job
->username
);
9703 * Start the job if this is the last document...
9706 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9707 IPP_TAG_BOOLEAN
)) != NULL
&&
9708 attr
->values
[0].boolean
)
9711 * See if we need to add the ending sheet...
9714 if (cupsdTimeoutJob(job
))
9717 if (job
->state_value
== IPP_JOB_STOPPED
)
9719 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9720 job
->state_value
= IPP_JOB_PENDING
;
9722 else if (job
->state_value
== IPP_JOB_HELD
)
9724 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9725 IPP_TAG_KEYWORD
)) == NULL
)
9726 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9728 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9730 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9731 job
->state_value
= IPP_JOB_PENDING
;
9736 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9742 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9743 IPP_TAG_KEYWORD
)) == NULL
)
9744 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9746 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9748 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9749 job
->state_value
= IPP_JOB_HELD
;
9750 job
->hold_until
= time(NULL
) + 60;
9753 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9760 * Fill in the response info...
9763 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
9766 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9769 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9771 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9773 add_job_state_reasons(con
, job
);
9775 con
->response
->request
.status
.status_code
= IPP_OK
;
9778 * Start the job if necessary...
9787 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9792 cupsd_client_t
*con
, /* I - Client connection */
9793 http_status_t status
, /* I - HTTP status code */
9794 cupsd_printer_t
*printer
) /* I - Printer, if any */
9796 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s",
9797 ippOpString(con
->request
->request
.op
.operation_id
),
9798 httpStatus(status
));
9800 if (status
== HTTP_UNAUTHORIZED
&&
9801 printer
&& printer
->num_auth_info_required
> 0 &&
9802 !strcmp(printer
->auth_info_required
[0], "negotiate"))
9803 cupsdSendError(con
, status
, CUPSD_AUTH_NEGOTIATE
);
9806 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9807 cupsd_location_t
*auth
; /* Pointer to authentication element */
9808 int auth_type
; /* Type of authentication required */
9811 if (printer
->type
& CUPS_PRINTER_CLASS
)
9812 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9814 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9816 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9817 auth
->type
== CUPSD_AUTH_NONE
)
9818 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9820 con
->request
->request
.op
.operation_id
:
9824 auth_type
= CUPSD_AUTH_NONE
;
9825 else if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9826 auth_type
= DefaultAuthType
;
9828 auth_type
= auth
->type
;
9830 cupsdSendError(con
, status
, auth_type
);
9833 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9835 ippDelete(con
->response
);
9836 con
->response
= NULL
;
9843 * 'send_ipp_status()' - Send a status back to the IPP client.
9847 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9848 ipp_status_t status
, /* I - IPP status code */
9849 const char *message
, /* I - Status message */
9850 ...) /* I - Additional args as needed */
9852 va_list ap
; /* Pointer to additional args */
9853 char formatted
[1024]; /* Formatted errror message */
9856 va_start(ap
, message
);
9857 vsnprintf(formatted
, sizeof(formatted
),
9858 _cupsLangString(con
->language
, message
), ap
);
9861 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9862 ippOpString(con
->request
->request
.op
.operation_id
),
9863 ippErrorString(status
), formatted
);
9865 con
->response
->request
.status
.status_code
= status
;
9867 if (ippFindAttribute(con
->response
, "attributes-charset",
9868 IPP_TAG_ZERO
) == NULL
)
9869 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9870 "attributes-charset", NULL
, DefaultCharset
);
9872 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9873 IPP_TAG_ZERO
) == NULL
)
9874 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9875 "attributes-natural-language", NULL
, DefaultLanguage
);
9877 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9878 "status-message", NULL
, formatted
);
9883 * 'set_default()' - Set the default destination...
9887 set_default(cupsd_client_t
*con
, /* I - Client connection */
9888 ipp_attribute_t
*uri
) /* I - Printer URI */
9890 http_status_t status
; /* Policy status */
9891 cups_ptype_t dtype
; /* Destination type (printer/class) */
9892 cupsd_printer_t
*printer
, /* Printer */
9893 *oldprinter
; /* Old default printer */
9896 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9897 con
->http
.fd
, uri
->values
[0].string
.text
);
9900 * Is the destination valid?
9903 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9909 send_ipp_status(con
, IPP_NOT_FOUND
,
9910 _("The printer or class was not found."));
9918 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9920 send_http_error(con
, status
, NULL
);
9925 * Set it as the default...
9928 oldprinter
= DefaultPrinter
;
9929 DefaultPrinter
= printer
;
9932 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9933 "%s is no longer the default printer.", oldprinter
->name
);
9935 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9936 "%s is now the default printer.", printer
->name
);
9938 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9939 CUPSD_DIRTY_REMOTE
| CUPSD_DIRTY_PRINTCAP
);
9941 cupsdLogMessage(CUPSD_LOG_INFO
,
9942 "Default destination set to \"%s\" by \"%s\".",
9943 printer
->name
, get_username(con
));
9946 * Everything was ok, so return OK status...
9949 con
->response
->request
.status
.status_code
= IPP_OK
;
9954 * 'set_job_attrs()' - Set job attributes.
9958 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9959 ipp_attribute_t
*uri
) /* I - Job URI */
9961 ipp_attribute_t
*attr
, /* Current attribute */
9962 *attr2
; /* Job attribute */
9963 int jobid
; /* Job ID */
9964 cupsd_job_t
*job
; /* Current job */
9965 char method
[HTTP_MAX_URI
],
9966 /* Method portion of URI */
9967 username
[HTTP_MAX_URI
],
9968 /* Username portion of URI */
9970 /* Host portion of URI */
9971 resource
[HTTP_MAX_URI
];
9972 /* Resource portion of URI */
9973 int port
; /* Port portion of URI */
9974 int event
; /* Events? */
9977 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9978 con
->http
.fd
, uri
->values
[0].string
.text
);
9981 * Start with "everything is OK" status...
9984 con
->response
->request
.status
.status_code
= IPP_OK
;
9987 * See if we have a job URI or a printer URI...
9990 if (!strcmp(uri
->name
, "printer-uri"))
9993 * Got a printer URI; see if we also have a job-id attribute...
9996 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9997 IPP_TAG_INTEGER
)) == NULL
)
9999 send_ipp_status(con
, IPP_BAD_REQUEST
,
10000 _("Got a printer-uri attribute but no job-id!"));
10004 jobid
= attr
->values
[0].integer
;
10009 * Got a job URI; parse it to get the job ID...
10012 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
10013 sizeof(method
), username
, sizeof(username
), host
,
10014 sizeof(host
), &port
, resource
, sizeof(resource
));
10016 if (strncmp(resource
, "/jobs/", 6))
10022 send_ipp_status(con
, IPP_BAD_REQUEST
,
10023 _("Bad job-uri attribute \"%s\"!"),
10024 uri
->values
[0].string
.text
);
10028 jobid
= atoi(resource
+ 6);
10032 * See if the job exists...
10035 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10038 * Nope - return a "not found" error...
10041 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
10046 * See if the job has been completed...
10049 if (job
->state_value
> IPP_JOB_STOPPED
)
10052 * Return a "not-possible" error...
10055 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10056 _("Job #%d is finished and cannot be altered!"), jobid
);
10061 * See if the job is owned by the requesting user...
10064 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10066 send_http_error(con
, HTTP_UNAUTHORIZED
, cupsdFindDest(job
->dest
));
10071 * See what the user wants to change.
10078 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10080 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10083 if (!strcmp(attr
->name
, "attributes-charset") ||
10084 !strcmp(attr
->name
, "attributes-natural-language") ||
10085 !strcmp(attr
->name
, "document-compression") ||
10086 !strcmp(attr
->name
, "document-format") ||
10087 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10088 !strcmp(attr
->name
, "job-document-access-errors") ||
10089 !strcmp(attr
->name
, "job-id") ||
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-impressions", 15) ||
10104 !strncmp(attr
->name
, "job-k-octets", 12) ||
10105 !strncmp(attr
->name
, "job-media-sheets", 16) ||
10106 !strncmp(attr
->name
, "time-at-", 8))
10112 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10113 _("%s cannot be changed."), attr
->name
);
10115 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10116 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10121 if (!strcmp(attr
->name
, "job-priority"))
10124 * Change the job priority...
10127 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10129 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
10131 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10132 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10134 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10136 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10137 _("Job is completed and cannot be changed."));
10140 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10142 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10143 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10144 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10147 else if (!strcmp(attr
->name
, "job-state"))
10150 * Change the job state...
10153 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10155 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
10157 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
10158 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
10162 switch (attr
->values
[0].integer
)
10164 case IPP_JOB_PENDING
:
10165 case IPP_JOB_HELD
:
10166 if (job
->state_value
> IPP_JOB_HELD
)
10168 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10169 _("Job state cannot be changed."));
10172 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10174 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
10175 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
10177 event
|= CUPSD_EVENT_JOB_STATE
;
10181 case IPP_JOB_PROCESSING
:
10182 case IPP_JOB_STOPPED
:
10183 if (job
->state_value
!= attr
->values
[0].integer
)
10185 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10186 _("Job state cannot be changed."));
10191 case IPP_JOB_CANCELED
:
10192 case IPP_JOB_ABORTED
:
10193 case IPP_JOB_COMPLETED
:
10194 if (job
->state_value
> IPP_JOB_PROCESSING
)
10196 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10197 _("Job state cannot be changed."));
10200 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10201 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
10206 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10208 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10209 IPP_TAG_ZERO
)) != NULL
)
10212 * Some other value; first free the old value...
10215 if (job
->attrs
->prev
)
10216 job
->attrs
->prev
->next
= attr2
->next
;
10218 job
->attrs
->attrs
= attr2
->next
;
10220 if (job
->attrs
->last
== attr2
)
10221 job
->attrs
->last
= job
->attrs
->prev
;
10223 _ippFreeAttr(attr2
);
10226 * Then copy the attribute...
10229 copy_attribute(job
->attrs
, attr
, 0);
10232 * See if the job-name or job-hold-until is being changed.
10235 if (!strcmp(attr
->name
, "job-hold-until"))
10237 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
10239 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10240 cupsdReleaseJob(job
);
10244 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10247 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10250 * Delete the attribute...
10253 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10254 IPP_TAG_ZERO
)) != NULL
)
10256 if (job
->attrs
->prev
)
10257 job
->attrs
->prev
->next
= attr2
->next
;
10259 job
->attrs
->attrs
= attr2
->next
;
10261 if (attr2
== job
->attrs
->last
)
10262 job
->attrs
->last
= job
->attrs
->prev
;
10264 _ippFreeAttr(attr2
);
10266 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10272 * Add new option by copying it...
10275 copy_attribute(job
->attrs
, attr
, 0);
10277 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10286 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10289 * Send events as needed...
10292 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10293 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10294 cupsdFindDest(job
->dest
), job
,
10295 "Job priority changed by user.");
10297 if (event
& CUPSD_EVENT_JOB_STATE
)
10298 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10299 job
->state_value
== IPP_JOB_HELD
?
10300 "Job held by user." : "Job restarted by user.");
10302 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10303 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10304 "Job options changed by user.");
10307 * Start jobs if possible...
10315 * 'set_printer_defaults()' - Set printer default options from a request.
10319 set_printer_defaults(
10320 cupsd_client_t
*con
, /* I - Client connection */
10321 cupsd_printer_t
*printer
) /* I - Printer */
10323 int i
; /* Looping var */
10324 ipp_attribute_t
*attr
; /* Current attribute */
10325 int namelen
; /* Length of attribute name */
10326 char name
[256], /* New attribute name */
10327 value
[256]; /* String version of integer attrs */
10330 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10333 * Skip non-printer attributes...
10336 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10339 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10341 if (!strcmp(attr
->name
, "job-sheets-default"))
10344 * Only allow keywords and names...
10347 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10351 * Only allow job-sheets-default to be set when running without a
10352 * system high classification level...
10355 if (Classification
)
10358 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10360 if (attr
->num_values
> 1)
10361 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10363 cupsdSetString(&printer
->job_sheets
[1], "none");
10365 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10367 cupsdFreePrinterUsers(printer
);
10369 printer
->deny_users
= 0;
10371 if (attr
->value_tag
== IPP_TAG_NAME
&&
10372 (attr
->num_values
> 1 ||
10373 strcmp(attr
->values
[0].string
.text
, "all")))
10375 for (i
= 0; i
< attr
->num_values
; i
++)
10376 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10379 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10381 cupsdFreePrinterUsers(printer
);
10383 printer
->deny_users
= 1;
10385 if (attr
->value_tag
== IPP_TAG_NAME
&&
10386 (attr
->num_values
> 1 ||
10387 strcmp(attr
->values
[0].string
.text
, "none")))
10389 for (i
= 0; i
< attr
->num_values
; i
++)
10390 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
10393 else if (!strcmp(attr
->name
, "job-quota-period"))
10395 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10398 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10399 attr
->values
[0].integer
);
10400 cupsdFreeQuotas(printer
);
10402 printer
->quota_period
= attr
->values
[0].integer
;
10404 else if (!strcmp(attr
->name
, "job-k-limit"))
10406 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10409 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10410 attr
->values
[0].integer
);
10411 cupsdFreeQuotas(printer
);
10413 printer
->k_limit
= attr
->values
[0].integer
;
10415 else if (!strcmp(attr
->name
, "job-page-limit"))
10417 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10420 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10421 attr
->values
[0].integer
);
10422 cupsdFreeQuotas(printer
);
10424 printer
->page_limit
= attr
->values
[0].integer
;
10426 else if (!strcmp(attr
->name
, "printer-op-policy"))
10428 cupsd_policy_t
*p
; /* Policy */
10431 if (attr
->value_tag
!= IPP_TAG_NAME
)
10434 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10436 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10437 "Setting printer-op-policy to \"%s\"...",
10438 attr
->values
[0].string
.text
);
10439 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10440 printer
->op_policy_ptr
= p
;
10444 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10445 _("Unknown printer-op-policy \"%s\"."),
10446 attr
->values
[0].string
.text
);
10450 else if (!strcmp(attr
->name
, "printer-error-policy"))
10452 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10455 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10456 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10457 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
10459 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10460 _("Unknown printer-error-policy \"%s\"."),
10461 attr
->values
[0].string
.text
);
10465 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10466 "Setting printer-error-policy to \"%s\"...",
10467 attr
->values
[0].string
.text
);
10468 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10472 * Skip any other non-default attributes...
10475 namelen
= strlen(attr
->name
);
10476 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10477 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10481 * OK, anything else must be a user-defined default...
10484 strlcpy(name
, attr
->name
, sizeof(name
));
10485 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10487 switch (attr
->value_tag
)
10489 case IPP_TAG_DELETEATTR
:
10490 printer
->num_options
= cupsRemoveOption(name
,
10491 printer
->num_options
,
10492 &(printer
->options
));
10493 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10494 "Deleting %s", attr
->name
);
10497 case IPP_TAG_NAME
:
10498 case IPP_TAG_KEYWORD
:
10500 printer
->num_options
= cupsAddOption(name
,
10501 attr
->values
[0].string
.text
,
10502 printer
->num_options
,
10503 &(printer
->options
));
10504 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10505 "Setting %s to \"%s\"...", attr
->name
,
10506 attr
->values
[0].string
.text
);
10509 case IPP_TAG_BOOLEAN
:
10510 printer
->num_options
= cupsAddOption(name
,
10511 attr
->values
[0].boolean
?
10513 printer
->num_options
,
10514 &(printer
->options
));
10515 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10516 "Setting %s to %s...", attr
->name
,
10517 attr
->values
[0].boolean
? "true" : "false");
10520 case IPP_TAG_INTEGER
:
10521 case IPP_TAG_ENUM
:
10522 sprintf(value
, "%d", attr
->values
[0].integer
);
10523 printer
->num_options
= cupsAddOption(name
, value
,
10524 printer
->num_options
,
10525 &(printer
->options
));
10526 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10527 "Setting %s to %s...", attr
->name
, value
);
10530 case IPP_TAG_RANGE
:
10531 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10532 attr
->values
[0].range
.upper
);
10533 printer
->num_options
= cupsAddOption(name
, value
,
10534 printer
->num_options
,
10535 &(printer
->options
));
10536 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10537 "Setting %s to %s...", attr
->name
, value
);
10540 case IPP_TAG_RESOLUTION
:
10541 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10542 attr
->values
[0].resolution
.yres
,
10543 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10545 printer
->num_options
= cupsAddOption(name
, value
,
10546 printer
->num_options
,
10547 &(printer
->options
));
10548 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10549 "Setting %s to %s...", attr
->name
, value
);
10553 /* Do nothing for other values */
10561 * 'start_printer()' - Start a printer.
10565 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10566 ipp_attribute_t
*uri
) /* I - Printer URI */
10568 http_status_t status
; /* Policy status */
10569 cups_ptype_t dtype
; /* Destination type (printer/class) */
10570 cupsd_printer_t
*printer
; /* Printer data */
10573 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10574 con
->http
.fd
, uri
->values
[0].string
.text
);
10577 * Is the destination valid?
10580 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10586 send_ipp_status(con
, IPP_NOT_FOUND
,
10587 _("The printer or class was not found."));
10595 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10597 send_http_error(con
, status
, printer
);
10602 * Start the printer...
10605 printer
->state_message
[0] = '\0';
10607 cupsdStartPrinter(printer
, 1);
10609 if (dtype
& CUPS_PRINTER_CLASS
)
10610 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10611 printer
->name
, get_username(con
));
10613 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10614 printer
->name
, get_username(con
));
10619 * Everything was ok, so return OK status...
10622 con
->response
->request
.status
.status_code
= IPP_OK
;
10627 * 'stop_printer()' - Stop a printer.
10631 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10632 ipp_attribute_t
*uri
) /* I - Printer URI */
10634 http_status_t status
; /* Policy status */
10635 cups_ptype_t dtype
; /* Destination type (printer/class) */
10636 cupsd_printer_t
*printer
; /* Printer data */
10637 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10640 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10641 con
->http
.fd
, uri
->values
[0].string
.text
);
10644 * Is the destination valid?
10647 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10653 send_ipp_status(con
, IPP_NOT_FOUND
,
10654 _("The printer or class was not found."));
10662 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10664 send_http_error(con
, status
, printer
);
10669 * Stop the printer...
10672 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10673 IPP_TAG_TEXT
)) == NULL
)
10674 strcpy(printer
->state_message
, "Paused");
10677 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10678 sizeof(printer
->state_message
));
10681 cupsdStopPrinter(printer
, 1);
10683 if (dtype
& CUPS_PRINTER_CLASS
)
10684 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10685 printer
->name
, get_username(con
));
10687 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10688 printer
->name
, get_username(con
));
10691 * Everything was ok, so return OK status...
10694 con
->response
->request
.status
.status_code
= IPP_OK
;
10699 * 'url_encode_attr()' - URL-encode a string attribute.
10703 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10704 char *buffer
,/* I - String buffer */
10705 int bufsize
)/* I - Size of buffer */
10707 int i
; /* Looping var */
10708 char *bufptr
, /* Pointer into buffer */
10709 *bufend
; /* End of buffer */
10712 strlcpy(buffer
, attr
->name
, bufsize
);
10713 bufptr
= buffer
+ strlen(buffer
);
10714 bufend
= buffer
+ bufsize
- 1;
10716 for (i
= 0; i
< attr
->num_values
; i
++)
10718 if (bufptr
>= bufend
)
10726 if (bufptr
>= bufend
)
10731 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10732 bufptr
, bufend
- bufptr
+ 1);
10734 if (bufptr
>= bufend
)
10745 * 'url_encode_string()' - URL-encode a string.
10748 static char * /* O - End of string */
10749 url_encode_string(const char *s
, /* I - String */
10750 char *buffer
, /* I - String buffer */
10751 int bufsize
) /* I - Size of buffer */
10753 char *bufptr
, /* Pointer into buffer */
10754 *bufend
; /* End of buffer */
10755 static const char *hex
= "0123456789ABCDEF";
10760 bufend
= buffer
+ bufsize
- 1;
10762 while (*s
&& bufptr
< bufend
)
10764 if (*s
== ' ' || *s
== '%')
10766 if (bufptr
>= (bufend
- 2))
10770 *bufptr
++ = hex
[(*s
>> 4) & 15];
10771 *bufptr
++ = hex
[*s
& 15];
10775 else if (*s
== '\'' || *s
== '\\')
10777 if (bufptr
>= (bufend
- 1))
10794 * 'user_allowed()' - See if a user is allowed to print to a queue.
10797 static int /* O - 0 if not allowed, 1 if allowed */
10798 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10799 const char *username
) /* I - Username */
10801 int i
; /* Looping var */
10802 struct passwd
*pw
; /* User password data */
10803 char baseuser
[256], /* Base username */
10804 *baseptr
; /* Pointer to "@" in base username */
10807 if (p
->num_users
== 0)
10810 if (!strcmp(username
, "root"))
10813 if (strchr(username
, '@'))
10816 * Strip @REALM for username check...
10819 strlcpy(baseuser
, username
, sizeof(baseuser
));
10821 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10824 username
= baseuser
;
10827 pw
= getpwnam(username
);
10830 for (i
= 0; i
< p
->num_users
; i
++)
10832 if (p
->users
[i
][0] == '@')
10835 * Check group membership...
10838 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
10841 else if (p
->users
[i
][0] == '#')
10847 if (cupsdCheckGroup(username
, pw
, p
->users
[i
]))
10850 else if (!strcasecmp(username
, p
->users
[i
]))
10854 return ((i
< p
->num_users
) != p
->deny_users
);
10859 * 'validate_job()' - Validate printer options and destination.
10863 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10864 ipp_attribute_t
*uri
) /* I - Printer URI */
10866 http_status_t status
; /* Policy status */
10867 ipp_attribute_t
*attr
; /* Current attribute */
10868 ipp_attribute_t
*format
; /* Document-format attribute */
10869 cups_ptype_t dtype
; /* Destination type (printer/class) */
10870 char super
[MIME_MAX_SUPER
],
10871 /* Supertype of file */
10872 type
[MIME_MAX_TYPE
];
10873 /* Subtype of file */
10874 cupsd_printer_t
*printer
; /* Printer */
10877 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10878 con
->http
.fd
, uri
->values
[0].string
.text
);
10881 * OK, see if the client is sending the document compressed - CUPS
10882 * doesn't support compression yet...
10885 if ((attr
= ippFindAttribute(con
->request
, "compression",
10886 IPP_TAG_KEYWORD
)) != NULL
&&
10887 !strcmp(attr
->values
[0].string
.text
, "none"))
10889 send_ipp_status(con
, IPP_ATTRIBUTES
,
10890 _("Unsupported compression attribute %s!"),
10891 attr
->values
[0].string
.text
);
10892 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10893 "compression", NULL
, attr
->values
[0].string
.text
);
10898 * Is it a format we support?
10901 if ((format
= ippFindAttribute(con
->request
, "document-format",
10902 IPP_TAG_MIMETYPE
)) != NULL
)
10904 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]",
10907 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
10908 format
->values
[0].string
.text
);
10912 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10913 !mimeType(MimeDatabase
, super
, type
))
10915 cupsdLogMessage(CUPSD_LOG_INFO
,
10916 "Hint: Do you have the raw file printing rules enabled?");
10917 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10918 _("Unsupported format \"%s\"!"),
10919 format
->values
[0].string
.text
);
10920 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10921 "document-format", NULL
, format
->values
[0].string
.text
);
10927 * Is the destination valid?
10930 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10936 send_ipp_status(con
, IPP_NOT_FOUND
,
10937 _("The printer or class was not found."));
10945 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10947 send_http_error(con
, status
, printer
);
10952 * Everything was ok, so return OK status...
10955 con
->response
->request
.status
.status_code
= IPP_OK
;
10960 * 'validate_name()' - Make sure the printer name only contains valid chars.
10963 static int /* O - 0 if name is no good, 1 if good */
10964 validate_name(const char *name
) /* I - Name to check */
10966 const char *ptr
; /* Pointer into name */
10970 * Scan the whole name...
10973 for (ptr
= name
; *ptr
; ptr
++)
10974 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
10978 * All the characters are good; validate the length, too...
10981 return ((ptr
- name
) < 128);
10986 * 'validate_user()' - Validate the user for the request.
10989 static int /* O - 1 if permitted, 0 otherwise */
10990 validate_user(cupsd_job_t
*job
, /* I - Job */
10991 cupsd_client_t
*con
, /* I - Client connection */
10992 const char *owner
, /* I - Owner of job/resource */
10993 char *username
, /* O - Authenticated username */
10994 int userlen
) /* I - Length of username */
10996 cupsd_printer_t
*printer
; /* Printer for job */
10999 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
11000 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
11002 job
->id
, con
? con
->http
.fd
: 0,
11003 owner
? owner
: "(null)", username
, userlen
);
11006 * Validate input...
11009 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11013 * Get the best authenticated username that is available.
11016 strlcpy(username
, get_username(con
), userlen
);
11019 * Check the username against the owner...
11022 printer
= cupsdFindDest(job
->dest
);
11024 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11025 con
, owner
) == HTTP_OK
);
11030 * End of "$Id: ipp.c 7682 2008-06-21 00:06:02Z mike $".