2 * "$Id: ipp.c 12067 2014-07-31 00:02:30Z msweet $"
4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2014 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 * Include necessary headers...
24 #include <cups/ppd-private.h>
27 /*# include <ApplicationServices/ApplicationServices.h>
28 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
29 # include <CoreFoundation/CoreFoundation.h>*/
30 # ifdef HAVE_MEMBERSHIP_H
31 # include <membership.h>
32 # endif /* HAVE_MEMBERSHIP_H */
33 # ifdef HAVE_MEMBERSHIPPRIV_H
34 # include <membershipPriv.h>
36 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
37 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
38 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
39 # endif /* HAVE_MEMBERSHIPPRIV_H */
40 #endif /* __APPLE__ */
47 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
48 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
49 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
50 mime_type_t
*filetype
, int compression
);
51 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
52 mime_type_t
*filetype
);
53 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
54 static void add_job_uuid(cupsd_job_t
*job
);
55 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
56 static void add_printer_state_reasons(cupsd_client_t
*con
,
58 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
59 static void apply_printer_defaults(cupsd_printer_t
*printer
,
61 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
62 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
63 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
64 static void cancel_subscription(cupsd_client_t
*con
, int id
);
65 static int check_rss_recipient(const char *recipient
);
66 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
67 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
68 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
69 ipp_tag_t group
, int quickcopy
,
70 cups_array_t
*exclude
);
71 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
73 static int copy_file(const char *from
, const char *to
);
74 static int copy_model(cupsd_client_t
*con
, const char *from
,
76 static void copy_job_attrs(cupsd_client_t
*con
,
78 cups_array_t
*ra
, cups_array_t
*exclude
);
79 static void copy_printer_attrs(cupsd_client_t
*con
,
80 cupsd_printer_t
*printer
,
82 static void copy_subscription_attrs(cupsd_client_t
*con
,
83 cupsd_subscription_t
*sub
,
85 cups_array_t
*exclude
);
86 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
87 static cups_array_t
*create_requested_array(ipp_t
*request
);
88 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
90 static void get_default(cupsd_client_t
*con
);
91 static void get_devices(cupsd_client_t
*con
);
92 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
93 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
94 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
95 static void get_notifications(cupsd_client_t
*con
);
96 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
97 static void get_ppds(cupsd_client_t
*con
);
98 static void get_printers(cupsd_client_t
*con
, int type
);
99 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
100 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
101 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
102 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
103 static const char *get_username(cupsd_client_t
*con
);
104 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
105 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
107 static int ppd_parse_line(const char *line
, char *option
, int olen
,
108 char *choice
, int clen
);
109 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
110 static void read_job_ticket(cupsd_client_t
*con
);
111 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
112 static void release_held_new_jobs(cupsd_client_t
*con
,
113 ipp_attribute_t
*uri
);
114 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
115 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
116 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
117 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
118 ipp_attribute_t
*auth_info
);
119 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
120 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
121 cupsd_printer_t
*printer
);
122 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
123 const char *message
, ...)
124 __attribute__((__format__(__printf__
, 3, 4)));
125 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
126 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
127 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
128 static void set_printer_defaults(cupsd_client_t
*con
,
129 cupsd_printer_t
*printer
);
130 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
132 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
133 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
134 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
135 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
136 static int validate_name(const char *name
);
137 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
141 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
144 int /* O - 1 on success, 0 on failure */
145 cupsdProcessIPPRequest(
146 cupsd_client_t
*con
) /* I - Client connection */
148 ipp_tag_t group
; /* Current group tag */
149 ipp_attribute_t
*attr
; /* Current attribute */
150 ipp_attribute_t
*charset
; /* Character set attribute */
151 ipp_attribute_t
*language
; /* Language attribute */
152 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
153 ipp_attribute_t
*username
; /* requesting-user-name attr */
154 int sub_id
; /* Subscription ID */
157 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
158 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
159 con
, con
->number
, con
->request
->request
.op
.operation_id
);
162 * First build an empty response message for this request...
165 con
->response
= ippNew();
167 con
->response
->request
.status
.version
[0] =
168 con
->request
->request
.op
.version
[0];
169 con
->response
->request
.status
.version
[1] =
170 con
->request
->request
.op
.version
[1];
171 con
->response
->request
.status
.request_id
=
172 con
->request
->request
.op
.request_id
;
175 * Then validate the request header and required attributes...
178 if (con
->request
->request
.any
.version
[0] != 1 &&
179 con
->request
->request
.any
.version
[0] != 2)
182 * Return an error, since we only support IPP 1.x and 2.x.
185 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
186 "%04X %s Bad request version number %d.%d",
187 IPP_VERSION_NOT_SUPPORTED
, con
->http
->hostname
,
188 con
->request
->request
.any
.version
[0],
189 con
->request
->request
.any
.version
[1]);
191 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
192 _("Bad request version number %d.%d."),
193 con
->request
->request
.any
.version
[0],
194 con
->request
->request
.any
.version
[1]);
196 else if (con
->request
->request
.any
.request_id
< 1)
199 * Return an error, since request IDs must be between 1 and 2^31-1
202 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
203 "%04X %s Bad request ID %d",
204 IPP_BAD_REQUEST
, con
->http
->hostname
,
205 con
->request
->request
.any
.request_id
);
207 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
208 con
->request
->request
.any
.request_id
);
210 else if (!con
->request
->attrs
)
212 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
213 "%04X %s No attributes in request",
214 IPP_BAD_REQUEST
, con
->http
->hostname
);
216 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
221 * Make sure that the attributes are provided in the correct order and
222 * don't repeat groups...
225 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
228 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
231 * Out of order; return an error...
234 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
235 "%04X %s Attribute groups are out of order",
236 IPP_BAD_REQUEST
, con
->http
->hostname
);
238 send_ipp_status(con
, IPP_BAD_REQUEST
,
239 _("Attribute groups are out of order (%x < %x)."),
240 attr
->group_tag
, group
);
244 group
= attr
->group_tag
;
249 * Then make sure that the first three attributes are:
252 * attributes-natural-language
253 * printer-uri/job-uri
256 attr
= con
->request
->attrs
;
257 if (attr
&& attr
->name
&&
258 !strcmp(attr
->name
, "attributes-charset") &&
259 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
267 if (attr
&& attr
->name
&&
268 !strcmp(attr
->name
, "attributes-natural-language") &&
269 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
274 * Reset language for this request if different from Accept-Language.
277 if (!con
->language
||
278 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
280 cupsLangFree(con
->language
);
281 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
287 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
288 IPP_TAG_URI
)) != NULL
)
290 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
291 IPP_TAG_URI
)) != NULL
)
293 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
294 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
299 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
300 "attributes-charset", NULL
,
301 charset
->values
[0].string
.text
);
303 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
304 "attributes-charset", NULL
, "utf-8");
307 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
308 "attributes-natural-language", NULL
,
309 language
->values
[0].string
.text
);
311 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
312 "attributes-natural-language", NULL
, DefaultLanguage
);
315 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
316 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
319 * Bad character set...
322 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
323 charset
->values
[0].string
.text
);
324 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
325 "%04X %s Unsupported attributes-charset value \"%s\"",
326 IPP_CHARSET
, con
->http
->hostname
,
327 charset
->values
[0].string
.text
);
328 send_ipp_status(con
, IPP_BAD_REQUEST
,
329 _("Unsupported character set \"%s\"."),
330 charset
->values
[0].string
.text
);
332 else if (!charset
|| !language
||
334 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
335 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
336 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
337 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
338 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
341 * Return an error, since attributes-charset,
342 * attributes-natural-language, and printer-uri/job-uri are required
343 * for all operations.
348 cupsdLogMessage(CUPSD_LOG_ERROR
,
349 "Missing attributes-charset attribute");
351 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
352 "%04X %s Missing attributes-charset attribute",
353 IPP_BAD_REQUEST
, con
->http
->hostname
);
358 cupsdLogMessage(CUPSD_LOG_ERROR
,
359 "Missing attributes-natural-language attribute");
361 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
362 "%04X %s Missing attributes-natural-language attribute",
363 IPP_BAD_REQUEST
, con
->http
->hostname
);
368 cupsdLogMessage(CUPSD_LOG_ERROR
,
369 "Missing printer-uri, job-uri, or ppd-name "
372 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
373 "%04X %s Missing printer-uri, job-uri, or ppd-name "
374 "attribute", IPP_BAD_REQUEST
, con
->http
->hostname
);
377 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
379 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
380 cupsdLogMessage(CUPSD_LOG_DEBUG
,
381 "attr \"%s\": group_tag = %x, value_tag = %x",
382 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
385 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
387 send_ipp_status(con
, IPP_BAD_REQUEST
,
388 _("Missing required attributes."));
393 * OK, all the checks pass so far; make sure requesting-user-name is
394 * not "root" from a remote host...
397 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
398 IPP_TAG_NAME
)) != NULL
)
401 * Check for root user...
404 if (!strcmp(username
->values
[0].string
.text
, "root") &&
405 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
406 strcmp(con
->username
, "root"))
409 * Remote unauthenticated user masquerading as local root...
412 _cupsStrFree(username
->values
[0].string
.text
);
413 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
417 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
418 IPP_TAG_INTEGER
)) != NULL
)
419 sub_id
= attr
->values
[0].integer
;
424 * Then try processing the operation...
428 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
429 ippOpString(con
->request
->request
.op
.operation_id
),
430 uri
->values
[0].string
.text
);
432 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
433 ippOpString(con
->request
->request
.op
.operation_id
));
435 switch (con
->request
->request
.op
.operation_id
)
437 case IPP_OP_PRINT_JOB
:
441 case IPP_OP_VALIDATE_JOB
:
442 validate_job(con
, uri
);
445 case IPP_OP_CREATE_JOB
:
446 create_job(con
, uri
);
449 case IPP_OP_SEND_DOCUMENT
:
450 send_document(con
, uri
);
453 case IPP_OP_CANCEL_JOB
:
454 cancel_job(con
, uri
);
457 case IPP_OP_GET_JOB_ATTRIBUTES
:
458 get_job_attrs(con
, uri
);
461 case IPP_OP_GET_JOBS
:
465 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
466 get_printer_attrs(con
, uri
);
469 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
470 get_printer_supported(con
, uri
);
473 case IPP_OP_HOLD_JOB
:
477 case IPP_OP_RELEASE_JOB
:
478 release_job(con
, uri
);
481 case IPP_OP_RESTART_JOB
:
482 restart_job(con
, uri
);
485 case IPP_OP_PAUSE_PRINTER
:
486 stop_printer(con
, uri
);
489 case IPP_OP_RESUME_PRINTER
:
490 start_printer(con
, uri
);
493 case IPP_OP_PURGE_JOBS
:
494 case IPP_OP_CANCEL_JOBS
:
495 case IPP_OP_CANCEL_MY_JOBS
:
496 cancel_all_jobs(con
, uri
);
499 case IPP_OP_SET_JOB_ATTRIBUTES
:
500 set_job_attrs(con
, uri
);
503 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
504 set_printer_attrs(con
, uri
);
507 case IPP_OP_HOLD_NEW_JOBS
:
508 hold_new_jobs(con
, uri
);
511 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
512 release_held_new_jobs(con
, uri
);
515 case IPP_OP_CLOSE_JOB
:
519 case IPP_OP_CUPS_GET_DEFAULT
:
523 case IPP_OP_CUPS_GET_PRINTERS
:
524 get_printers(con
, 0);
527 case IPP_OP_CUPS_GET_CLASSES
:
528 get_printers(con
, CUPS_PRINTER_CLASS
);
531 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
532 add_printer(con
, uri
);
535 case IPP_OP_CUPS_DELETE_PRINTER
:
536 delete_printer(con
, uri
);
539 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
543 case IPP_OP_CUPS_DELETE_CLASS
:
544 delete_printer(con
, uri
);
547 case IPP_OP_CUPS_ACCEPT_JOBS
:
548 case IPP_OP_ENABLE_PRINTER
:
549 accept_jobs(con
, uri
);
552 case IPP_OP_CUPS_REJECT_JOBS
:
553 case IPP_OP_DISABLE_PRINTER
:
554 reject_jobs(con
, uri
);
557 case IPP_OP_CUPS_SET_DEFAULT
:
558 set_default(con
, uri
);
561 case IPP_OP_CUPS_GET_DEVICES
:
565 case IPP_OP_CUPS_GET_DOCUMENT
:
566 get_document(con
, uri
);
569 case IPP_OP_CUPS_GET_PPD
:
573 case IPP_OP_CUPS_GET_PPDS
:
577 case IPP_OP_CUPS_MOVE_JOB
:
581 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
582 authenticate_job(con
, uri
);
585 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
586 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
587 create_subscriptions(con
, uri
);
590 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
591 get_subscription_attrs(con
, sub_id
);
594 case IPP_OP_GET_SUBSCRIPTIONS
:
595 get_subscriptions(con
, uri
);
598 case IPP_OP_RENEW_SUBSCRIPTION
:
599 renew_subscription(con
, sub_id
);
602 case IPP_OP_CANCEL_SUBSCRIPTION
:
603 cancel_subscription(con
, sub_id
);
606 case IPP_OP_GET_NOTIFICATIONS
:
607 get_notifications(con
);
611 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
612 "%04X %s Operation %04X (%s) not supported",
613 IPP_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
,
614 con
->request
->request
.op
.operation_id
,
615 ippOpString(con
->request
->request
.op
.operation_id
));
617 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
618 _("%s not supported."),
620 con
->request
->request
.op
.operation_id
));
630 * Sending data from the scheduler...
633 cupsdLogMessage(con
->response
->request
.status
.status_code
634 >= IPP_BAD_REQUEST
&&
635 con
->response
->request
.status
.status_code
636 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
637 "[Client %d] Returning IPP %s for %s (%s) from %s",
639 ippErrorString(con
->response
->request
.status
.status_code
),
640 ippOpString(con
->request
->request
.op
.operation_id
),
641 uri
? uri
->values
[0].string
.text
: "no URI",
642 con
->http
->hostname
);
644 httpClearFields(con
->http
);
646 #ifdef CUPSD_USE_CHUNKING
648 * Because older versions of CUPS (1.1.17 and older) and some IPP
649 * clients do not implement chunking properly, we cannot use
650 * chunking by default. This may become the default in future
651 * CUPS releases, or we might add a configuration directive for
655 if (con
->http
->version
== HTTP_1_1
)
657 cupsdLogMessage(CUPSD_LOG_DEBUG
,
658 "[Client %d] Transfer-Encoding: chunked",
661 cupsdSetLength(con
->http
, 0);
664 #endif /* CUPSD_USE_CHUNKING */
666 size_t length
; /* Length of response */
669 length
= ippLength(con
->response
);
671 if (con
->file
>= 0 && !con
->pipe_pid
)
673 struct stat fileinfo
; /* File information */
675 if (!fstat(con
->file
, &fileinfo
))
676 length
+= (size_t)fileinfo
.st_size
;
679 cupsdLogMessage(CUPSD_LOG_DEBUG
,
680 "[Client %d] Content-Length: " CUPS_LLFMT
,
681 con
->number
, CUPS_LLCAST length
);
682 httpSetLength(con
->http
, length
);
685 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
688 * Tell the caller the response header was sent successfully...
691 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
,
692 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
699 * Tell the caller the response header could not be sent...
708 * Sending data from a subprocess like cups-deviced; tell the caller
709 * everything is A-OK so far...
718 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
721 int /* O - 0 on success, -1 on error */
722 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
724 cupsd_printer_t
*printer
; /* Destination printer or class */
725 ipp_attribute_t
*attr
; /* job-sheets attribute */
726 int kbytes
; /* Kilobytes in banner */
729 job
->pending_timeout
= 0;
732 * See if we need to add the ending sheet...
735 if (!cupsdLoadJob(job
))
738 printer
= cupsdFindDest(job
->dest
);
739 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
741 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
742 attr
&& attr
->num_values
> 1)
748 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
749 attr
->values
[1].string
.text
);
751 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
754 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
762 * 'accept_jobs()' - Accept print jobs to a printer.
766 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
767 ipp_attribute_t
*uri
) /* I - Printer or class URI */
769 http_status_t status
; /* Policy status */
770 cups_ptype_t dtype
; /* Destination type (printer/class) */
771 cupsd_printer_t
*printer
; /* Printer data */
774 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
775 con
->number
, uri
->values
[0].string
.text
);
778 * Is the destination valid?
781 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
787 send_ipp_status(con
, IPP_NOT_FOUND
,
788 _("The printer or class does not exist."));
796 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
798 send_http_error(con
, status
, printer
);
803 * Accept jobs sent to the printer...
806 printer
->accepting
= 1;
807 printer
->state_message
[0] = '\0';
809 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
810 "Now accepting jobs.");
812 if (dtype
& CUPS_PRINTER_CLASS
)
814 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
816 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
817 printer
->name
, get_username(con
));
821 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
823 cupsdLogMessage(CUPSD_LOG_INFO
,
824 "Printer \"%s\" now accepting jobs (\"%s\").",
825 printer
->name
, get_username(con
));
829 * Everything was ok, so return OK status...
832 con
->response
->request
.status
.status_code
= IPP_OK
;
837 * 'add_class()' - Add a class to the system.
841 add_class(cupsd_client_t
*con
, /* I - Client connection */
842 ipp_attribute_t
*uri
) /* I - URI of class */
844 http_status_t status
; /* Policy status */
845 int i
; /* Looping var */
846 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
847 username
[HTTP_MAX_URI
], /* Username portion of URI */
848 host
[HTTP_MAX_URI
], /* Host portion of URI */
849 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
850 int port
; /* Port portion of URI */
851 cupsd_printer_t
*pclass
, /* Class */
852 *member
; /* Member printer/class */
853 cups_ptype_t dtype
; /* Destination type */
854 ipp_attribute_t
*attr
; /* Printer attribute */
855 int modify
; /* Non-zero if we just modified */
856 int need_restart_job
; /* Need to restart job? */
859 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
860 con
->number
, uri
->values
[0].string
.text
);
863 * Do we have a valid URI?
866 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
867 sizeof(scheme
), username
, sizeof(username
), host
,
868 sizeof(host
), &port
, resource
, sizeof(resource
));
871 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
874 * No, return an error...
877 send_ipp_status(con
, IPP_BAD_REQUEST
,
878 _("The printer-uri must be of the form "
879 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
884 * Do we have a valid printer name?
887 if (!validate_name(resource
+ 9))
890 * No, return an error...
893 send_ipp_status(con
, IPP_BAD_REQUEST
,
894 _("The printer-uri \"%s\" contains invalid characters."),
895 uri
->values
[0].string
.text
);
900 * See if the class already exists; if not, create a new class...
903 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
906 * Class doesn't exist; see if we have a printer of the same name...
909 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
912 * Yes, return an error...
915 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
916 _("A printer named \"%s\" already exists."),
922 * No, check the default policy and then add the class...
925 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
927 send_http_error(con
, status
, NULL
);
931 pclass
= cupsdAddClass(resource
+ 9);
934 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
937 send_http_error(con
, status
, pclass
);
944 * Look for attributes and copy them over as needed...
947 need_restart_job
= 0;
949 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
950 IPP_TAG_TEXT
)) != NULL
)
951 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
953 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
954 IPP_TAG_TEXT
)) != NULL
)
955 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
957 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
958 IPP_TAG_BOOLEAN
)) != NULL
&&
959 attr
->values
[0].boolean
!= pclass
->accepting
)
961 cupsdLogMessage(CUPSD_LOG_INFO
,
962 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
963 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
965 pclass
->accepting
= attr
->values
[0].boolean
;
967 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
968 pclass
->accepting
? "Now" : "No longer");
971 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
972 IPP_TAG_BOOLEAN
)) != NULL
)
974 if (pclass
->shared
&& !attr
->values
[0].boolean
)
975 cupsdDeregisterPrinter(pclass
, 1);
977 cupsdLogMessage(CUPSD_LOG_INFO
,
978 "Setting %s printer-is-shared to %d (was %d.)",
979 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
981 pclass
->shared
= attr
->values
[0].boolean
;
984 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
985 IPP_TAG_ENUM
)) != NULL
)
987 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
988 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
990 send_ipp_status(con
, IPP_BAD_REQUEST
,
991 _("Attempt to set %s printer-state to bad value %d."),
992 pclass
->name
, attr
->values
[0].integer
);
996 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
997 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
999 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1000 cupsdStopPrinter(pclass
, 0);
1003 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1004 need_restart_job
= 1;
1007 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1008 IPP_TAG_TEXT
)) != NULL
)
1010 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1011 sizeof(pclass
->state_message
));
1013 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1014 pclass
->state_message
);
1016 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1017 IPP_TAG_URI
)) != NULL
)
1020 * Clear the printer array as needed...
1023 need_restart_job
= 1;
1025 if (pclass
->num_printers
> 0)
1027 free(pclass
->printers
);
1028 pclass
->num_printers
= 0;
1032 * Add each printer or class that is listed...
1035 for (i
= 0; i
< attr
->num_values
; i
++)
1038 * Search for the printer or class URI...
1041 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1047 send_ipp_status(con
, IPP_NOT_FOUND
,
1048 _("The printer or class does not exist."));
1051 else if (dtype
& CUPS_PRINTER_CLASS
)
1053 send_ipp_status(con
, IPP_BAD_REQUEST
,
1054 _("Nested classes are not allowed."));
1059 * Add it to the class...
1062 cupsdAddPrinterToClass(pclass
, member
);
1066 set_printer_defaults(con
, pclass
);
1068 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1069 IPP_TAG_KEYWORD
)) != NULL
)
1070 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1073 * Update the printer class attributes and return...
1076 cupsdSetPrinterAttrs(pclass
);
1077 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1079 if (need_restart_job
&& pclass
->job
)
1082 * Reset the current job to a "pending" status...
1085 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1086 "Job restarted because the class was modified.");
1089 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1093 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1094 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1095 pclass
->name
, get_username(con
));
1097 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1098 pclass
->name
, get_username(con
));
1102 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1103 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1104 pclass
->name
, get_username(con
));
1106 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1107 pclass
->name
, get_username(con
));
1110 con
->response
->request
.status
.status_code
= IPP_OK
;
1115 * 'add_file()' - Add a file to a job.
1118 static int /* O - 0 on success, -1 on error */
1119 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1120 cupsd_job_t
*job
, /* I - Job to add to */
1121 mime_type_t
*filetype
, /* I - Type of file */
1122 int compression
) /* I - Compression */
1124 mime_type_t
**filetypes
; /* New filetypes array... */
1125 int *compressions
; /* New compressions array... */
1128 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1129 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1130 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1131 filetype
->super
, filetype
->type
, compression
);
1134 * Add the file to the job...
1137 if (job
->num_files
== 0)
1139 compressions
= (int *)malloc(sizeof(int));
1140 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1144 compressions
= (int *)realloc(job
->compressions
,
1145 (size_t)(job
->num_files
+ 1) * sizeof(int));
1146 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1147 (size_t)(job
->num_files
+ 1) *
1148 sizeof(mime_type_t
*));
1152 job
->compressions
= compressions
;
1155 job
->filetypes
= filetypes
;
1157 if (!compressions
|| !filetypes
)
1159 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1160 "Job aborted because the scheduler ran out of memory.");
1163 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1164 _("Unable to allocate memory for file types."));
1169 job
->compressions
[job
->num_files
] = compression
;
1170 job
->filetypes
[job
->num_files
] = filetype
;
1175 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1182 * 'add_job()' - Add a job to a print queue.
1185 static cupsd_job_t
* /* O - Job object */
1186 add_job(cupsd_client_t
*con
, /* I - Client connection */
1187 cupsd_printer_t
*printer
, /* I - Destination printer */
1188 mime_type_t
*filetype
) /* I - First print file type, if any */
1190 http_status_t status
; /* Policy status */
1191 ipp_attribute_t
*attr
, /* Current attribute */
1192 *auth_info
; /* auth-info attribute */
1193 const char *mandatory
; /* Current mandatory job attribute */
1194 const char *val
; /* Default option value */
1195 int priority
; /* Job priority */
1196 cupsd_job_t
*job
; /* Current job */
1197 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1198 int kbytes
; /* Size of print file */
1199 int i
; /* Looping var */
1200 int lowerpagerange
; /* Page range bound */
1201 int exact
; /* Did we have an exact match? */
1202 ipp_attribute_t
*media_col
, /* media-col attribute */
1203 *media_margin
; /* media-*-margin attribute */
1204 ipp_t
*unsup_col
; /* media-col in unsupported response */
1205 static const char * const readonly
[] =/* List of read-only attributes */
1208 "job-k-octets-completed",
1209 "job-impressions-completed",
1210 "job-media-sheets-completed",
1212 "job-state-message",
1213 "job-state-reasons",
1214 "time-at-completed",
1216 "time-at-processing"
1220 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1221 con
, con
->number
, printer
, printer
->name
,
1222 filetype
, filetype
? filetype
->super
: "none",
1223 filetype
? filetype
->type
: "none");
1226 * Check remote printing to non-shared printer...
1229 if (!printer
->shared
&&
1230 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1231 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1233 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1234 _("The printer or class is not shared."));
1242 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1244 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1246 send_http_error(con
, status
, printer
);
1249 else if (printer
->num_auth_info_required
== 1 &&
1250 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1253 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1257 else if (auth_info
&& !con
->http
->tls
&&
1258 !httpAddrLocalhost(con
->http
->hostaddr
))
1261 * Require encryption of auth-info over non-local connections...
1264 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1267 #endif /* HAVE_SSL */
1270 * See if the printer is accepting jobs...
1273 if (!printer
->accepting
)
1275 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1276 _("Destination \"%s\" is not accepting jobs."),
1282 * Validate job template attributes; for now just document-format,
1283 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1287 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1289 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
],
1290 IPP_TAG_ZERO
)) != NULL
)
1292 ippDeleteAttribute(con
->request
, attr
);
1294 if (StrictConformance
)
1296 send_ipp_status(con
, IPP_BAD_REQUEST
,
1297 _("The '%s' Job Description attribute cannot be "
1298 "supplied in a job creation request."), readonly
[i
]);
1302 cupsdLogMessage(CUPSD_LOG_INFO
,
1303 "Unexpected '%s' Job Description attribute in a job "
1304 "creation request.", readonly
[i
]);
1310 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1312 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1314 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1317 * Missing a required attribute...
1320 send_ipp_status(con
, IPP_CONFLICT
,
1321 _("The \"%s\" attribute is required for print jobs."),
1328 if (filetype
&& printer
->filetypes
&&
1329 !cupsArrayFind(printer
->filetypes
, filetype
))
1331 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1332 /* MIME media type string */
1335 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1338 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1339 _("Unsupported format \"%s\"."), mimetype
);
1341 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1342 "document-format", NULL
, mimetype
);
1347 if ((attr
= ippFindAttribute(con
->request
, "copies",
1348 IPP_TAG_INTEGER
)) != NULL
)
1350 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1352 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1353 attr
->values
[0].integer
);
1354 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1355 "copies", attr
->values
[0].integer
);
1360 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1361 IPP_TAG_ZERO
)) != NULL
)
1363 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1364 attr
->value_tag
!= IPP_TAG_NAME
)
1366 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1370 if (attr
->num_values
> 2)
1372 send_ipp_status(con
, IPP_BAD_REQUEST
,
1373 _("Too many job-sheets values (%d > 2)."),
1378 for (i
= 0; i
< attr
->num_values
; i
++)
1379 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1380 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1382 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1383 attr
->values
[i
].string
.text
);
1388 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1389 IPP_TAG_INTEGER
)) != NULL
)
1391 if (attr
->values
[0].integer
!= 1 &&
1392 attr
->values
[0].integer
!= 2 &&
1393 attr
->values
[0].integer
!= 4 &&
1394 attr
->values
[0].integer
!= 6 &&
1395 attr
->values
[0].integer
!= 9 &&
1396 attr
->values
[0].integer
!= 16)
1398 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1399 attr
->values
[0].integer
);
1400 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1401 "number-up", attr
->values
[0].integer
);
1406 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1407 IPP_TAG_RANGE
)) != NULL
)
1409 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1411 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1412 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1414 send_ipp_status(con
, IPP_BAD_REQUEST
,
1415 _("Bad page-ranges values %d-%d."),
1416 attr
->values
[i
].range
.lower
,
1417 attr
->values
[i
].range
.upper
);
1421 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1426 * Do media selection as needed...
1429 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1430 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1431 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1434 (media_col
= ippFindAttribute(con
->request
, "media-col",
1435 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1437 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1439 unsup_col
= ippNew();
1440 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1441 "media-bottom-margin",
1442 IPP_TAG_INTEGER
)) != NULL
)
1443 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1444 "media-bottom-margin", media_margin
->values
[0].integer
);
1446 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1447 "media-left-margin",
1448 IPP_TAG_INTEGER
)) != NULL
)
1449 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1450 "media-left-margin", media_margin
->values
[0].integer
);
1452 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1453 "media-right-margin",
1454 IPP_TAG_INTEGER
)) != NULL
)
1455 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1456 "media-right-margin", media_margin
->values
[0].integer
);
1458 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1460 IPP_TAG_INTEGER
)) != NULL
)
1461 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1462 "media-top-margin", media_margin
->values
[0].integer
);
1464 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1466 ippDelete(unsup_col
);
1471 * Make sure we aren't over our limit...
1474 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1477 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1479 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1483 if ((i
= check_quotas(con
, printer
)) < 0)
1485 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1490 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1495 * Create the job and set things up...
1498 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1499 IPP_TAG_INTEGER
)) != NULL
)
1500 priority
= attr
->values
[0].integer
;
1503 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1504 printer
->options
)) != NULL
)
1505 priority
= atoi(val
);
1509 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1513 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1514 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1515 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1516 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1517 attr
->num_values
!= 1)
1519 send_ipp_status(con
, IPP_ATTRIBUTES
,
1520 _("Bad job-name value: Wrong type or count."));
1521 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1522 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1525 else if (!ippValidateAttribute(attr
))
1527 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1528 cupsLastErrorString());
1529 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1530 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1534 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1536 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1537 _("Unable to add job for destination \"%s\"."),
1542 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1543 job
->attrs
= con
->request
;
1545 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1547 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1550 apply_printer_defaults(printer
, job
);
1552 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1554 if (con
->username
[0])
1556 cupsdSetString(&job
->username
, con
->username
);
1559 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1563 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1564 "add_job: requesting-user-name=\"%s\"",
1565 attr
->values
[0].string
.text
);
1567 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1570 cupsdSetString(&job
->username
, "anonymous");
1573 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1574 "job-originating-user-name", NULL
, job
->username
);
1577 attr
->group_tag
= IPP_TAG_JOB
;
1578 _cupsStrFree(attr
->name
);
1579 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1582 if (con
->username
[0] || auth_info
)
1584 save_auth_info(con
, job
, auth_info
);
1587 * Remove the auth-info attribute from the attribute data...
1591 ippDeleteAttribute(job
->attrs
, auth_info
);
1594 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1595 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1597 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1598 IPP_TAG_ZERO
)) != NULL
)
1601 * Request contains a job-originating-host-name attribute; validate it...
1604 if (attr
->value_tag
!= IPP_TAG_NAME
||
1605 attr
->num_values
!= 1 ||
1606 strcmp(con
->http
->hostname
, "localhost"))
1609 * Can't override the value if we aren't connected via localhost.
1610 * Also, we can only have 1 value and it must be a name value.
1613 switch (attr
->value_tag
)
1615 case IPP_TAG_STRING
:
1616 case IPP_TAG_TEXTLANG
:
1617 case IPP_TAG_NAMELANG
:
1620 case IPP_TAG_KEYWORD
:
1622 case IPP_TAG_URISCHEME
:
1623 case IPP_TAG_CHARSET
:
1624 case IPP_TAG_LANGUAGE
:
1625 case IPP_TAG_MIMETYPE
:
1627 * Free old strings...
1630 for (i
= 0; i
< attr
->num_values
; i
++)
1632 _cupsStrFree(attr
->values
[i
].string
.text
);
1633 attr
->values
[i
].string
.text
= NULL
;
1634 if (attr
->values
[i
].string
.language
)
1636 _cupsStrFree(attr
->values
[i
].string
.language
);
1637 attr
->values
[i
].string
.language
= NULL
;
1646 * Use the default connection hostname instead...
1649 attr
->value_tag
= IPP_TAG_NAME
;
1650 attr
->num_values
= 1;
1651 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
->hostname
);
1654 attr
->group_tag
= IPP_TAG_JOB
;
1659 * No job-originating-host-name attribute, so use the hostname from
1663 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1664 "job-originating-host-name", NULL
, con
->http
->hostname
);
1667 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1669 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1670 "time-at-processing", 0);
1671 attr
->value_tag
= IPP_TAG_NOVALUE
;
1672 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1673 "time-at-completed", 0);
1674 attr
->value_tag
= IPP_TAG_NOVALUE
;
1677 * Add remaining job attributes...
1680 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1681 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1682 "job-state", IPP_JOB_STOPPED
);
1683 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1684 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1685 "job-state-reasons", NULL
, "job-incoming");
1686 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1687 "job-media-sheets-completed", 0);
1688 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1691 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1692 attr
->values
[0].integer
= 0;
1694 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1696 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1697 IPP_TAG_KEYWORD
)) == NULL
)
1698 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1701 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1702 printer
->options
)) == NULL
)
1705 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1706 "job-hold-until", NULL
, val
);
1708 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1711 * Hold job until specified time...
1714 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1716 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1717 job
->state_value
= IPP_JOB_HELD
;
1719 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1721 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1723 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1724 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1725 job
->state_value
= IPP_JOB_HELD
;
1729 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1730 job
->state_value
= IPP_JOB_PENDING
;
1732 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1735 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1738 * Add job sheets options...
1741 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1742 IPP_TAG_ZERO
)) == NULL
)
1744 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1745 "Adding default job-sheets values \"%s,%s\"...",
1746 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1748 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1750 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1751 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1754 job
->job_sheets
= attr
;
1757 * Enforce classification level if set...
1762 cupsdLogMessage(CUPSD_LOG_INFO
,
1763 "Classification=\"%s\", ClassifyOverride=%d",
1764 Classification
? Classification
: "(null)",
1767 if (ClassifyOverride
)
1769 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1770 (attr
->num_values
== 1 ||
1771 !strcmp(attr
->values
[1].string
.text
, "none")))
1774 * Force the leading banner to have the classification on it...
1777 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1779 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1780 "job-sheets=\"%s,none\", "
1781 "job-originating-user-name=\"%s\"",
1782 Classification
, job
->username
);
1784 else if (attr
->num_values
== 2 &&
1785 strcmp(attr
->values
[0].string
.text
,
1786 attr
->values
[1].string
.text
) &&
1787 strcmp(attr
->values
[0].string
.text
, "none") &&
1788 strcmp(attr
->values
[1].string
.text
, "none"))
1791 * Can't put two different security markings on the same document!
1794 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1796 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1797 "job-sheets=\"%s,%s\", "
1798 "job-originating-user-name=\"%s\"",
1799 attr
->values
[0].string
.text
,
1800 attr
->values
[1].string
.text
, job
->username
);
1802 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1803 strcmp(attr
->values
[0].string
.text
, "none") &&
1804 (attr
->num_values
== 1 ||
1805 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1806 strcmp(attr
->values
[1].string
.text
, "none"))))
1808 if (attr
->num_values
== 1)
1809 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1810 "CLASSIFICATION OVERRIDDEN "
1811 "job-sheets=\"%s\", "
1812 "job-originating-user-name=\"%s\"",
1813 attr
->values
[0].string
.text
, job
->username
);
1815 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1816 "CLASSIFICATION OVERRIDDEN "
1817 "job-sheets=\"%s,%s\",fffff "
1818 "job-originating-user-name=\"%s\"",
1819 attr
->values
[0].string
.text
,
1820 attr
->values
[1].string
.text
, job
->username
);
1823 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1824 (attr
->num_values
== 1 ||
1825 strcmp(attr
->values
[1].string
.text
, Classification
)))
1828 * Force the banner to have the classification on it...
1831 if (attr
->num_values
> 1 &&
1832 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1834 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1835 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1839 if (attr
->num_values
== 1 ||
1840 strcmp(attr
->values
[0].string
.text
, "none"))
1841 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1843 if (attr
->num_values
> 1 &&
1844 strcmp(attr
->values
[1].string
.text
, "none"))
1845 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1848 if (attr
->num_values
> 1)
1849 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1850 "CLASSIFICATION FORCED "
1851 "job-sheets=\"%s,%s\", "
1852 "job-originating-user-name=\"%s\"",
1853 attr
->values
[0].string
.text
,
1854 attr
->values
[1].string
.text
, job
->username
);
1856 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1857 "CLASSIFICATION FORCED "
1858 "job-sheets=\"%s\", "
1859 "job-originating-user-name=\"%s\"",
1860 Classification
, job
->username
);
1865 * See if we need to add the starting sheet...
1868 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1870 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1871 attr
->values
[0].string
.text
);
1873 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1875 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1876 "Aborting job because the start banner could not be "
1881 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1884 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1885 IPP_TAG_ZERO
)) != NULL
)
1886 job
->job_sheets
= attr
;
1889 * Fill in the response info...
1892 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1893 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1894 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1897 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1899 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1901 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1902 NULL
, job
->reasons
->values
[0].string
.text
);
1904 con
->response
->request
.status
.status_code
= IPP_OK
;
1907 * Add any job subscriptions...
1910 add_job_subscriptions(con
, job
);
1913 * Set all but the first two attributes to the job attributes group...
1916 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1917 attr
->group_tag
= IPP_TAG_JOB
;
1920 * Fire the "job created" event...
1923 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1926 * Return the new job...
1934 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1938 add_job_subscriptions(
1939 cupsd_client_t
*con
, /* I - Client connection */
1940 cupsd_job_t
*job
) /* I - Newly created job */
1942 int i
; /* Looping var */
1943 ipp_attribute_t
*prev
, /* Previous attribute */
1944 *next
, /* Next attribute */
1945 *attr
; /* Current attribute */
1946 cupsd_subscription_t
*sub
; /* Subscription object */
1947 const char *recipient
, /* notify-recipient-uri */
1948 *pullmethod
; /* notify-pull-method */
1949 ipp_attribute_t
*user_data
; /* notify-user-data */
1950 int interval
; /* notify-time-interval */
1951 unsigned mask
; /* notify-events */
1955 * Find the first subscription group attribute; return if we have
1959 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1960 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1967 * Process the subscription attributes in the request...
1976 mask
= CUPSD_EVENT_NONE
;
1978 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1980 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1981 attr
->value_tag
== IPP_TAG_URI
)
1984 * Validate the recipient scheme against the ServerBin/notifier
1988 char notifier
[1024], /* Notifier filename */
1989 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
1990 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
1991 host
[HTTP_MAX_URI
], /* Host portion of URI */
1992 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1993 int port
; /* Port portion of URI */
1996 recipient
= attr
->values
[0].string
.text
;
1998 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
1999 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2000 host
, sizeof(host
), &port
,
2001 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2003 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2004 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2005 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2006 "notify-status-code", IPP_URI_SCHEME
);
2010 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2012 if (access(notifier
, X_OK
))
2014 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2015 _("notify-recipient-uri URI \"%s\" uses unknown "
2016 "scheme."), recipient
);
2017 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2018 "notify-status-code", IPP_URI_SCHEME
);
2022 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2024 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2025 _("notify-recipient-uri URI \"%s\" is already used."),
2027 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2028 "notify-status-code", IPP_ATTRIBUTES
);
2032 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2033 attr
->value_tag
== IPP_TAG_KEYWORD
)
2035 pullmethod
= attr
->values
[0].string
.text
;
2037 if (strcmp(pullmethod
, "ippget"))
2039 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2040 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2041 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2042 "notify-status-code", IPP_ATTRIBUTES
);
2046 else if (!strcmp(attr
->name
, "notify-charset") &&
2047 attr
->value_tag
== IPP_TAG_CHARSET
&&
2048 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2049 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2051 send_ipp_status(con
, IPP_CHARSET
,
2052 _("Character set \"%s\" not supported."),
2053 attr
->values
[0].string
.text
);
2056 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2057 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2058 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2060 send_ipp_status(con
, IPP_CHARSET
,
2061 _("Language \"%s\" not supported."),
2062 attr
->values
[0].string
.text
);
2065 else if (!strcmp(attr
->name
, "notify-user-data") &&
2066 attr
->value_tag
== IPP_TAG_STRING
)
2068 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2070 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2071 _("The notify-user-data value is too large "
2072 "(%d > 63 octets)."),
2073 attr
->values
[0].unknown
.length
);
2079 else if (!strcmp(attr
->name
, "notify-events") &&
2080 attr
->value_tag
== IPP_TAG_KEYWORD
)
2082 for (i
= 0; i
< attr
->num_values
; i
++)
2083 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2085 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2087 send_ipp_status(con
, IPP_BAD_REQUEST
,
2088 _("The notify-lease-duration attribute cannot be "
2089 "used with job subscriptions."));
2092 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2093 attr
->value_tag
== IPP_TAG_INTEGER
)
2094 interval
= attr
->values
[0].integer
;
2099 if (!recipient
&& !pullmethod
)
2102 if (mask
== CUPSD_EVENT_NONE
)
2103 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2105 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2106 recipient
, 0)) != NULL
)
2108 sub
->interval
= interval
;
2110 cupsdSetString(&sub
->owner
, job
->username
);
2114 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2115 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2116 (size_t)sub
->user_data_len
);
2119 ippAddSeparator(con
->response
);
2120 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2121 "notify-subscription-id", sub
->id
);
2123 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2131 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2134 * Remove all of the subscription attributes from the job request...
2136 * TODO: Optimize this since subscription groups have to come at the
2137 * end of the request...
2140 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2144 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2145 attr
->group_tag
== IPP_TAG_ZERO
)
2148 * Free and remove this attribute...
2151 ippDeleteAttribute(NULL
, attr
);
2156 job
->attrs
->attrs
= next
;
2162 job
->attrs
->last
= prev
;
2163 job
->attrs
->current
= prev
;
2168 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2170 * See RFC 4122 for the definition of UUIDs and the format.
2174 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2176 char uuid
[64]; /* job-uuid string */
2180 * Add a job-uuid attribute if none exists...
2183 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2184 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2185 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2186 uuid
, sizeof(uuid
)));
2191 * 'add_printer()' - Add a printer to the system.
2195 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2196 ipp_attribute_t
*uri
) /* I - URI of printer */
2198 http_status_t status
; /* Policy status */
2199 int i
; /* Looping var */
2200 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2201 username
[HTTP_MAX_URI
], /* Username portion of URI */
2202 host
[HTTP_MAX_URI
], /* Host portion of URI */
2203 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2204 int port
; /* Port portion of URI */
2205 cupsd_printer_t
*printer
; /* Printer/class */
2206 ipp_attribute_t
*attr
; /* Printer attribute */
2207 cups_file_t
*fp
; /* Script/PPD file */
2208 char line
[1024]; /* Line from file... */
2209 char srcfile
[1024], /* Source Script/PPD file */
2210 dstfile
[1024]; /* Destination Script/PPD file */
2211 int modify
; /* Non-zero if we are modifying */
2212 int changed_driver
, /* Changed the PPD/interface script? */
2213 need_restart_job
, /* Need to restart job? */
2214 set_device_uri
, /* Did we set the device URI? */
2215 set_port_monitor
; /* Did we set the port monitor? */
2218 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2219 con
->number
, uri
->values
[0].string
.text
);
2222 * Do we have a valid URI?
2225 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2226 sizeof(scheme
), username
, sizeof(username
), host
,
2227 sizeof(host
), &port
, resource
, sizeof(resource
));
2229 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2232 * No, return an error...
2235 send_ipp_status(con
, IPP_BAD_REQUEST
,
2236 _("The printer-uri must be of the form "
2237 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2242 * Do we have a valid printer name?
2245 if (!validate_name(resource
+ 10))
2248 * No, return an error...
2251 send_ipp_status(con
, IPP_BAD_REQUEST
,
2252 _("The printer-uri \"%s\" contains invalid characters."),
2253 uri
->values
[0].string
.text
);
2258 * See if the printer already exists; if not, create a new printer...
2261 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2264 * Printer doesn't exist; see if we have a class of the same name...
2267 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2270 * Yes, return an error...
2273 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2274 _("A class named \"%s\" already exists."),
2280 * No, check the default policy then add the printer...
2283 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2285 send_http_error(con
, status
, NULL
);
2289 printer
= cupsdAddPrinter(resource
+ 10);
2292 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2295 send_http_error(con
, status
, printer
);
2302 * Look for attributes and copy them over as needed...
2306 need_restart_job
= 0;
2308 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2309 IPP_TAG_TEXT
)) != NULL
)
2310 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2312 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2313 IPP_TAG_TEXT
)) != NULL
)
2314 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2318 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2319 IPP_TAG_URI
)) != NULL
)
2322 * Do we have a valid device URI?
2325 http_uri_status_t uri_status
; /* URI separation status */
2326 char old_device_uri
[1024];
2327 /* Old device URI */
2328 static const char * const uri_status_strings
[] =
2331 "Bad arguments to function.",
2332 "Bad resource path.",
2334 "Bad hostname/address.",
2335 "Bad username/password.",
2339 "Missing URI scheme.",
2340 "Unknown URI scheme",
2341 "Missing resource path."
2345 need_restart_job
= 1;
2347 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2348 attr
->values
[0].string
.text
,
2349 scheme
, sizeof(scheme
),
2350 username
, sizeof(username
),
2351 host
, sizeof(host
), &port
,
2352 resource
, sizeof(resource
));
2354 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2355 "%s device-uri: %s", printer
->name
,
2356 uri_status_strings
[uri_status
- HTTP_URI_STATUS_OVERFLOW
]);
2358 if (uri_status
< HTTP_URI_OK
)
2360 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2361 attr
->values
[0].string
.text
);
2365 if (!strcmp(scheme
, "file"))
2368 * See if the administrator has enabled file devices...
2371 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2374 * File devices are disabled and the URL is not file:/dev/null...
2377 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2378 _("File device URIs have been disabled. "
2379 "To enable, see the FileDevice directive in "
2380 "\"%s/cups-files.conf\"."),
2388 * See if the backend exists and is executable...
2391 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2392 if (access(srcfile
, X_OK
))
2395 * Could not find device in list!
2398 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2399 _("Bad device-uri scheme \"%s\"."), scheme
);
2404 if (printer
->sanitized_device_uri
)
2405 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2406 sizeof(old_device_uri
));
2408 old_device_uri
[0] = '\0';
2410 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2412 cupsdLogMessage(CUPSD_LOG_INFO
,
2413 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2414 printer
->name
, printer
->sanitized_device_uri
,
2420 set_port_monitor
= 0;
2422 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2423 IPP_TAG_NAME
)) != NULL
)
2425 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2428 need_restart_job
= 1;
2430 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2434 for (i
= 0; i
< supported
->num_values
; i
++)
2435 if (!strcmp(supported
->values
[i
].string
.text
,
2436 attr
->values
[0].string
.text
))
2440 if (!supported
|| i
>= supported
->num_values
)
2442 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2443 attr
->values
[0].string
.text
);
2447 cupsdLogMessage(CUPSD_LOG_INFO
,
2448 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2449 printer
->name
, attr
->values
[0].string
.text
,
2450 printer
->port_monitor
? printer
->port_monitor
: "none");
2452 if (strcmp(attr
->values
[0].string
.text
, "none"))
2453 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2455 cupsdClearString(&printer
->port_monitor
);
2457 set_port_monitor
= 1;
2460 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2461 IPP_TAG_BOOLEAN
)) != NULL
&&
2462 attr
->values
[0].boolean
!= printer
->accepting
)
2464 cupsdLogMessage(CUPSD_LOG_INFO
,
2465 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2466 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2468 printer
->accepting
= attr
->values
[0].boolean
;
2470 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2471 "%s accepting jobs.",
2472 printer
->accepting
? "Now" : "No longer");
2475 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2476 IPP_TAG_BOOLEAN
)) != NULL
)
2478 if (attr
->values
[0].boolean
&&
2479 printer
->num_auth_info_required
== 1 &&
2480 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2482 send_ipp_status(con
, IPP_BAD_REQUEST
,
2483 _("Cannot share a remote Kerberized printer."));
2487 if (printer
->shared
&& !attr
->values
[0].boolean
)
2488 cupsdDeregisterPrinter(printer
, 1);
2490 cupsdLogMessage(CUPSD_LOG_INFO
,
2491 "Setting %s printer-is-shared to %d (was %d.)",
2492 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2494 printer
->shared
= attr
->values
[0].boolean
;
2497 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2498 IPP_TAG_ENUM
)) != NULL
)
2500 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2501 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2503 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2504 attr
->values
[0].integer
);
2508 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2509 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2511 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2512 cupsdStopPrinter(printer
, 0);
2515 need_restart_job
= 1;
2516 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2520 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2521 IPP_TAG_TEXT
)) != NULL
)
2523 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2524 sizeof(printer
->state_message
));
2526 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2527 printer
->state_message
);
2530 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2531 IPP_TAG_KEYWORD
)) != NULL
)
2533 if (attr
->num_values
>
2534 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2536 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2537 _("Too many printer-state-reasons values (%d > %d)."),
2539 (int)(sizeof(printer
->reasons
) /
2540 sizeof(printer
->reasons
[0])));
2544 for (i
= 0; i
< printer
->num_reasons
; i
++)
2545 _cupsStrFree(printer
->reasons
[i
]);
2547 printer
->num_reasons
= 0;
2548 for (i
= 0; i
< attr
->num_values
; i
++)
2550 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2553 printer
->reasons
[printer
->num_reasons
] =
2554 _cupsStrRetain(attr
->values
[i
].string
.text
);
2555 printer
->num_reasons
++;
2557 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2558 printer
->state
!= IPP_PRINTER_STOPPED
)
2560 cupsdLogMessage(CUPSD_LOG_INFO
,
2561 "Setting %s printer-state to %d (was %d.)",
2562 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2563 cupsdStopPrinter(printer
, 0);
2567 if (PrintcapFormat
== PRINTCAP_PLIST
)
2568 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2570 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2571 "Printer \"%s\" state changed.", printer
->name
);
2574 set_printer_defaults(con
, printer
);
2576 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2577 IPP_TAG_KEYWORD
)) != NULL
)
2578 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2581 * See if we have all required attributes...
2584 if (!printer
->device_uri
)
2585 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2588 * See if we have an interface script or PPD file attached to the request...
2593 need_restart_job
= 1;
2596 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2598 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2601 * Yes; get the first line from it...
2605 cupsFileGets(fp
, line
, sizeof(line
));
2609 * Then see what kind of file it is...
2612 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2615 if (!strncmp(line
, "*PPD-Adobe", 10))
2618 * The new file is a PPD file, so remove any old interface script
2619 * that might be lying around...
2627 * This must be an interface script, so move the file over to the
2628 * interfaces directory and make it executable...
2631 if (copy_file(srcfile
, dstfile
))
2633 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2634 _("Unable to copy interface script - %s"),
2639 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2640 "Copied interface script successfully");
2641 chmod(dstfile
, 0755);
2644 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2647 if (!strncmp(line
, "*PPD-Adobe", 10))
2650 * The new file is a PPD file, so move the file over to the
2651 * ppd directory and make it readable by all...
2654 if (copy_file(srcfile
, dstfile
))
2656 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2657 _("Unable to copy PPD file - %s"),
2662 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2663 "Copied PPD file successfully");
2664 chmod(dstfile
, 0644);
2669 * This must be an interface script, so remove any old PPD file that
2670 * may be lying around...
2677 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2678 IPP_TAG_NAME
)) != NULL
)
2680 need_restart_job
= 1;
2683 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2686 * Raw driver, remove any existing PPD or interface script files.
2689 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2693 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2703 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2707 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2710 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2712 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2716 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2717 "Copied PPD file successfully");
2718 chmod(dstfile
, 0644);
2725 * If we changed the PPD/interface script, then remove the printer's cache
2726 * file and clear the printer-state-reasons...
2729 char cache_name
[1024]; /* Cache filename for printer attrs */
2731 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2735 cupsdSetPrinterReasons(printer
, "none");
2738 * (Re)register color profiles...
2741 cupsdRegisterColor(printer
);
2745 * If we set the device URI but not the port monitor, check which port
2746 * monitor to use by default...
2749 if (set_device_uri
&& !set_port_monitor
)
2751 ppd_file_t
*ppd
; /* PPD file */
2752 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2755 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2756 sizeof(scheme
), username
, sizeof(username
), host
,
2757 sizeof(host
), &port
, resource
, sizeof(resource
));
2759 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2761 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2763 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2765 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2766 if (!strcmp(scheme
, ppdattr
->spec
))
2768 cupsdLogMessage(CUPSD_LOG_INFO
,
2769 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2770 printer
->name
, ppdattr
->value
,
2771 printer
->port_monitor
? printer
->port_monitor
2774 if (strcmp(ppdattr
->value
, "none"))
2775 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2777 cupsdClearString(&printer
->port_monitor
);
2787 * Update the printer attributes and return...
2790 cupsdSetPrinterAttrs(printer
);
2791 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2793 if (need_restart_job
&& printer
->job
)
2796 * Restart the current job...
2799 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2800 "Job restarted because the printer was modified.");
2803 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2807 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2808 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2809 printer
->name
, get_username(con
));
2811 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2812 printer
->name
, get_username(con
));
2816 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2817 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2818 printer
->name
, get_username(con
));
2820 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2821 printer
->name
, get_username(con
));
2824 con
->response
->request
.status
.status_code
= IPP_OK
;
2829 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2830 * based upon the printer state...
2834 add_printer_state_reasons(
2835 cupsd_client_t
*con
, /* I - Client connection */
2836 cupsd_printer_t
*p
) /* I - Printer info */
2838 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2839 "add_printer_state_reasons(%p[%d], %p[%s])",
2840 con
, con
->number
, p
, p
->name
);
2842 if (p
->num_reasons
== 0)
2843 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2844 "printer-state-reasons", NULL
, "none");
2846 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2847 "printer-state-reasons", p
->num_reasons
, NULL
,
2848 (const char * const *)p
->reasons
);
2853 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2854 * the specified printer or class.
2858 add_queued_job_count(
2859 cupsd_client_t
*con
, /* I - Client connection */
2860 cupsd_printer_t
*p
) /* I - Printer or class */
2862 int count
; /* Number of jobs on destination */
2865 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2866 con
, con
->number
, p
, p
->name
);
2868 count
= cupsdGetPrinterJobCount(p
->name
);
2870 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2871 "queued-job-count", count
);
2876 * 'apply_printer_defaults()' - Apply printer default options to a job.
2880 apply_printer_defaults(
2881 cupsd_printer_t
*printer
, /* I - Printer */
2882 cupsd_job_t
*job
) /* I - Job */
2884 int i
, /* Looping var */
2885 num_options
; /* Number of default options */
2886 cups_option_t
*options
, /* Default options */
2887 *option
; /* Current option */
2891 * Collect all of the default options and add the missing ones to the
2895 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2896 option
= printer
->options
;
2899 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2901 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2906 * Encode these options as attributes in the job object...
2909 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2910 cupsFreeOptions(num_options
, options
);
2915 * 'authenticate_job()' - Set job authentication info.
2919 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2920 ipp_attribute_t
*uri
) /* I - Job URI */
2922 ipp_attribute_t
*attr
, /* job-id attribute */
2923 *auth_info
; /* auth-info attribute */
2924 int jobid
; /* Job ID */
2925 cupsd_job_t
*job
; /* Current job */
2926 char scheme
[HTTP_MAX_URI
],
2927 /* Method portion of URI */
2928 username
[HTTP_MAX_URI
],
2929 /* Username portion of URI */
2931 /* Host portion of URI */
2932 resource
[HTTP_MAX_URI
];
2933 /* Resource portion of URI */
2934 int port
; /* Port portion of URI */
2937 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2938 con
, con
->number
, uri
->values
[0].string
.text
);
2941 * Start with "everything is OK" status...
2944 con
->response
->request
.status
.status_code
= IPP_OK
;
2947 * See if we have a job URI or a printer URI...
2950 if (!strcmp(uri
->name
, "printer-uri"))
2953 * Got a printer URI; see if we also have a job-id attribute...
2956 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2957 IPP_TAG_INTEGER
)) == NULL
)
2959 send_ipp_status(con
, IPP_BAD_REQUEST
,
2960 _("Got a printer-uri attribute but no job-id."));
2964 jobid
= attr
->values
[0].integer
;
2969 * Got a job URI; parse it to get the job ID...
2972 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2973 sizeof(scheme
), username
, sizeof(username
), host
,
2974 sizeof(host
), &port
, resource
, sizeof(resource
));
2976 if (strncmp(resource
, "/jobs/", 6))
2982 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
2983 uri
->values
[0].string
.text
);
2987 jobid
= atoi(resource
+ 6);
2991 * See if the job exists...
2994 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2997 * Nope - return a "not found" error...
3000 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3005 * See if the job has been completed...
3008 if (job
->state_value
!= IPP_JOB_HELD
)
3011 * Return a "not-possible" error...
3014 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3015 _("Job #%d is not held for authentication."),
3021 * See if we have already authenticated...
3024 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3026 if (!con
->username
[0] && !auth_info
)
3028 cupsd_printer_t
*printer
; /* Job destination */
3031 * No auth data. If we need to authenticate via Kerberos, send a
3032 * HTTP auth challenge, otherwise just return an IPP error...
3035 printer
= cupsdFindDest(job
->dest
);
3037 if (printer
&& printer
->num_auth_info_required
> 0 &&
3038 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3039 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3041 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3042 _("No authentication information provided."));
3047 * See if the job is owned by the requesting user...
3050 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3052 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3053 cupsdFindDest(job
->dest
));
3058 * Save the authentication information for this job...
3061 save_auth_info(con
, job
, auth_info
);
3064 * Reset the job-hold-until value to "no-hold"...
3067 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3068 IPP_TAG_KEYWORD
)) == NULL
)
3069 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3073 attr
->value_tag
= IPP_TAG_KEYWORD
;
3074 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3078 * Release the job and return...
3081 cupsdReleaseJob(job
);
3083 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3085 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3092 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3096 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3097 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3099 int i
; /* Looping var */
3100 http_status_t status
; /* Policy status */
3101 cups_ptype_t dtype
; /* Destination type */
3102 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3103 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3104 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3105 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3106 int port
; /* Port portion of URI */
3107 ipp_attribute_t
*attr
; /* Attribute in request */
3108 const char *username
= NULL
; /* Username */
3109 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3111 cupsd_printer_t
*printer
; /* Printer */
3112 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3113 cupsd_job_t
*job
; /* Job */
3116 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3117 con
->number
, uri
->values
[0].string
.text
);
3120 * Get the jobs to cancel/purge...
3123 switch (con
->request
->request
.op
.operation_id
)
3125 case IPP_PURGE_JOBS
:
3127 * Get the username (if any) for the jobs we want to cancel (only if
3128 * "my-jobs" is specified...
3131 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3132 IPP_TAG_BOOLEAN
)) != NULL
&&
3133 attr
->values
[0].boolean
)
3135 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3136 IPP_TAG_NAME
)) != NULL
)
3137 username
= attr
->values
[0].string
.text
;
3140 send_ipp_status(con
, IPP_BAD_REQUEST
,
3141 _("Missing requesting-user-name attribute."));
3147 * Look for the "purge-jobs" attribute...
3150 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3151 IPP_TAG_BOOLEAN
)) != NULL
)
3152 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3154 purge
= CUPSD_JOB_PURGE
;
3157 case IPP_CANCEL_MY_JOBS
:
3158 if (con
->username
[0])
3159 username
= con
->username
;
3160 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3161 IPP_TAG_NAME
)) != NULL
)
3162 username
= attr
->values
[0].string
.text
;
3165 send_ipp_status(con
, IPP_BAD_REQUEST
,
3166 _("Missing requesting-user-name attribute."));
3174 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3177 * See if we have a printer URI...
3180 if (strcmp(uri
->name
, "printer-uri"))
3182 send_ipp_status(con
, IPP_BAD_REQUEST
,
3183 _("The printer-uri attribute is required."));
3188 * And if the destination is valid...
3191 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3197 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3198 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3199 hostname
, sizeof(hostname
), &port
,
3200 resource
, sizeof(resource
));
3202 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3203 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3205 send_ipp_status(con
, IPP_NOT_FOUND
,
3206 _("The printer or class does not exist."));
3214 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3216 send_http_error(con
, status
, NULL
);
3222 for (i
= 0; i
< job_ids
->num_values
; i
++)
3224 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3227 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3228 _cups_strcasecmp(job
->username
, username
))
3232 if (i
< job_ids
->num_values
)
3234 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3235 job_ids
->values
[i
].integer
);
3239 for (i
= 0; i
< job_ids
->num_values
; i
++)
3241 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3243 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3244 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3245 "Job canceled by user.");
3248 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3249 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3255 * Cancel all jobs on all printers...
3258 cupsdCancelJobs(NULL
, username
, purge
);
3260 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3261 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3271 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3274 send_http_error(con
, status
, printer
);
3280 for (i
= 0; i
< job_ids
->num_values
; i
++)
3282 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3283 _cups_strcasecmp(job
->dest
, printer
->name
))
3286 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3287 _cups_strcasecmp(job
->username
, username
))
3291 if (i
< job_ids
->num_values
)
3293 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3294 job_ids
->values
[i
].integer
);
3298 for (i
= 0; i
< job_ids
->num_values
; i
++)
3300 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3302 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3303 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3304 "Job canceled by user.");
3307 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3308 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3314 * Cancel all of the jobs on the named printer...
3317 cupsdCancelJobs(printer
->name
, username
, purge
);
3319 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3321 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3326 con
->response
->request
.status
.status_code
= IPP_OK
;
3331 * 'cancel_job()' - Cancel a print job.
3335 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3336 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3338 ipp_attribute_t
*attr
; /* Current attribute */
3339 int jobid
; /* Job ID */
3340 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3341 username
[HTTP_MAX_URI
], /* Username portion of URI */
3342 host
[HTTP_MAX_URI
], /* Host portion of URI */
3343 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3344 int port
; /* Port portion of URI */
3345 cupsd_job_t
*job
; /* Job information */
3346 cups_ptype_t dtype
; /* Destination type (printer/class) */
3347 cupsd_printer_t
*printer
; /* Printer data */
3348 cupsd_jobaction_t purge
; /* Purge the job? */
3351 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3352 con
->number
, uri
->values
[0].string
.text
);
3355 * See if we have a job URI or a printer URI...
3358 if (!strcmp(uri
->name
, "printer-uri"))
3361 * Got a printer URI; see if we also have a job-id attribute...
3364 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3365 IPP_TAG_INTEGER
)) == NULL
)
3367 send_ipp_status(con
, IPP_BAD_REQUEST
,
3368 _("Got a printer-uri attribute but no job-id."));
3372 if ((jobid
= attr
->values
[0].integer
) == 0)
3375 * Find the current job on the specified printer...
3378 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3384 send_ipp_status(con
, IPP_NOT_FOUND
,
3385 _("The printer or class does not exist."));
3390 * See if there are any pending jobs...
3393 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3395 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3396 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3397 !_cups_strcasecmp(job
->dest
, printer
->name
))
3405 * No, try stopped jobs...
3408 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3410 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3411 if (job
->state_value
== IPP_JOB_STOPPED
&&
3412 !_cups_strcasecmp(job
->dest
, printer
->name
))
3419 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3429 * Got a job URI; parse it to get the job ID...
3432 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3433 sizeof(scheme
), username
, sizeof(username
), host
,
3434 sizeof(host
), &port
, resource
, sizeof(resource
));
3436 if (strncmp(resource
, "/jobs/", 6))
3442 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3443 uri
->values
[0].string
.text
);
3447 jobid
= atoi(resource
+ 6);
3451 * Look for the "purge-job" attribute...
3454 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3455 IPP_TAG_BOOLEAN
)) != NULL
)
3456 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3458 purge
= CUPSD_JOB_DEFAULT
;
3461 * See if the job exists...
3464 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3467 * Nope - return a "not found" error...
3470 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3475 * See if the job is owned by the requesting user...
3478 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3480 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3481 cupsdFindDest(job
->dest
));
3486 * See if the job is already completed, canceled, or aborted; if so,
3487 * we can't cancel...
3490 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3492 switch (job
->state_value
)
3494 case IPP_JOB_CANCELED
:
3495 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3496 _("Job #%d is already canceled - can\'t cancel."),
3500 case IPP_JOB_ABORTED
:
3501 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3502 _("Job #%d is already aborted - can\'t cancel."),
3507 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3508 _("Job #%d is already completed - can\'t cancel."),
3517 * Cancel the job and return...
3520 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3521 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3522 "Job canceled by \"%s\"",
3526 if (purge
== CUPSD_JOB_PURGE
)
3527 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3530 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3533 con
->response
->request
.status
.status_code
= IPP_OK
;
3538 * 'cancel_subscription()' - Cancel a subscription.
3542 cancel_subscription(
3543 cupsd_client_t
*con
, /* I - Client connection */
3544 int sub_id
) /* I - Subscription ID */
3546 http_status_t status
; /* Policy status */
3547 cupsd_subscription_t
*sub
; /* Subscription */
3550 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3551 "cancel_subscription(con=%p[%d], sub_id=%d)",
3552 con
, con
->number
, sub_id
);
3555 * Is the subscription ID valid?
3558 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3561 * Bad subscription ID...
3564 send_ipp_status(con
, IPP_NOT_FOUND
,
3565 _("Subscription #%d does not exist."), sub_id
);
3573 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3575 con
, sub
->owner
)) != HTTP_OK
)
3577 send_http_error(con
, status
, sub
->dest
);
3582 * Cancel the subscription...
3585 cupsdDeleteSubscription(sub
, 1);
3587 con
->response
->request
.status
.status_code
= IPP_OK
;
3592 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3595 static int /* O - 1 if OK, 0 if not */
3596 check_rss_recipient(
3597 const char *recipient
) /* I - Recipient URI */
3599 cupsd_subscription_t
*sub
; /* Current subscription */
3602 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3604 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3608 * Compare the URIs up to the first ?...
3611 const char *r1
, *r2
;
3613 for (r1
= recipient
, r2
= sub
->recipient
;
3614 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3626 * 'check_quotas()' - Check quotas for a printer and user.
3629 static int /* O - 1 if OK, 0 if forbidden,
3630 -1 if limit reached */
3631 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3632 cupsd_printer_t
*p
) /* I - Printer or class */
3634 char username
[33], /* Username */
3635 *name
; /* Current user name */
3636 cupsd_quota_t
*q
; /* Quota data */
3637 #ifdef HAVE_MBR_UID_TO_UUID
3639 * Use Apple membership APIs which require that all names represent
3640 * valid user account or group records accessible by the server.
3643 uuid_t usr_uuid
; /* UUID for job requesting user */
3644 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3645 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3646 int mbr_err
; /* Error from membership function */
3647 int is_member
; /* Is this user a member? */
3650 * Use standard POSIX APIs for checking users and groups...
3653 struct passwd
*pw
; /* User password data */
3654 #endif /* HAVE_MBR_UID_TO_UUID */
3657 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3658 con
, con
->number
, p
, p
->name
);
3661 * Figure out who is printing...
3664 strlcpy(username
, get_username(con
), sizeof(username
));
3666 if ((name
= strchr(username
, '@')) != NULL
)
3667 *name
= '\0'; /* Strip @REALM */
3670 * Check global active job limits for printers and users...
3673 if (MaxJobsPerPrinter
)
3676 * Check if there are too many pending jobs on this printer...
3679 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3681 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3690 * Check if there are too many pending jobs for this user...
3693 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3695 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3702 * Check against users...
3705 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3708 if (cupsArrayCount(p
->users
))
3710 #ifdef HAVE_MBR_UID_TO_UUID
3712 * Get UUID for job requesting user...
3715 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3721 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3722 "check_quotas: UUID lookup failed for user \"%s\"",
3724 cupsdLogMessage(CUPSD_LOG_INFO
,
3725 "Denying user \"%s\" access to printer \"%s\" "
3726 "(unknown user)...",
3732 * Get UID and GID of requesting user...
3735 pw
= getpwnam(username
);
3737 #endif /* HAVE_MBR_UID_TO_UUID */
3739 for (name
= (char *)cupsArrayFirst(p
->users
);
3741 name
= (char *)cupsArrayNext(p
->users
))
3745 * Check group membership...
3748 #ifdef HAVE_MBR_UID_TO_UUID
3751 if (uuid_parse(name
+ 2, grp_uuid
))
3752 uuid_clear(grp_uuid
);
3754 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3757 * Invalid ACL entries are ignored for matching; just record a
3758 * warning in the log...
3761 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3762 "check_quotas: UUID lookup failed for ACL entry "
3763 "\"%s\" (err=%d)", name
, mbr_err
);
3764 cupsdLogMessage(CUPSD_LOG_WARN
,
3765 "Access control entry \"%s\" not a valid group name; "
3766 "entry ignored", name
);
3769 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3773 * At this point, there should be no errors, but check anyways...
3776 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3777 "check_quotas: group \"%s\" membership check "
3778 "failed (err=%d)", name
+ 1, mbr_err
);
3783 * Stop if we found a match...
3790 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3792 #endif /* HAVE_MBR_UID_TO_UUID */
3794 #ifdef HAVE_MBR_UID_TO_UUID
3799 if (uuid_parse(name
+ 1, usr2_uuid
))
3800 uuid_clear(usr2_uuid
);
3802 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3805 * Invalid ACL entries are ignored for matching; just record a
3806 * warning in the log...
3809 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3810 "check_quotas: UUID lookup failed for ACL entry "
3811 "\"%s\" (err=%d)", name
, mbr_err
);
3812 cupsdLogMessage(CUPSD_LOG_WARN
,
3813 "Access control entry \"%s\" not a valid user name; "
3814 "entry ignored", name
);
3817 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3821 else if (!_cups_strcasecmp(username
, name
))
3823 #endif /* HAVE_MBR_UID_TO_UUID */
3825 if ((name
!= NULL
) == p
->deny_users
)
3827 cupsdLogMessage(CUPSD_LOG_INFO
,
3828 "Denying user \"%s\" access to printer \"%s\"...",
3838 if (p
->k_limit
|| p
->page_limit
)
3840 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3842 cupsdLogMessage(CUPSD_LOG_ERROR
,
3843 "Unable to allocate quota data for user \"%s\"",
3848 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3849 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3851 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3858 * If we have gotten this far, we're done!
3866 * 'close_job()' - Close a multi-file job.
3870 close_job(cupsd_client_t
*con
, /* I - Client connection */
3871 ipp_attribute_t
*uri
) /* I - Printer URI */
3873 cupsd_job_t
*job
; /* Job */
3874 ipp_attribute_t
*attr
; /* Attribute */
3875 char job_uri
[HTTP_MAX_URI
],
3877 username
[256]; /* User name */
3880 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3881 con
->number
, uri
->values
[0].string
.text
);
3884 * See if we have a job URI or a printer URI...
3887 if (strcmp(uri
->name
, "printer-uri"))
3890 * job-uri is not supported by Close-Job!
3893 send_ipp_status(con
, IPP_BAD_REQUEST
,
3894 _("Close-Job doesn't support the job-uri attribute."));
3899 * Got a printer URI; see if we also have a job-id attribute...
3902 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3903 IPP_TAG_INTEGER
)) == NULL
)
3905 send_ipp_status(con
, IPP_BAD_REQUEST
,
3906 _("Got a printer-uri attribute but no job-id."));
3910 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3913 * Nope - return a "not found" error...
3916 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3917 attr
->values
[0].integer
);
3922 * See if the job is owned by the requesting user...
3925 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3927 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3928 cupsdFindDest(job
->dest
));
3933 * Add any ending sheet...
3936 if (cupsdTimeoutJob(job
))
3939 if (job
->state_value
== IPP_JOB_STOPPED
)
3941 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3942 job
->state_value
= IPP_JOB_PENDING
;
3944 else if (job
->state_value
== IPP_JOB_HELD
)
3946 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3947 IPP_TAG_KEYWORD
)) == NULL
)
3948 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3950 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3952 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3953 job
->state_value
= IPP_JOB_PENDING
;
3958 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3961 * Fill in the response info...
3964 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3965 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3966 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3969 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3971 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
3974 con
->response
->request
.status
.status_code
= IPP_OK
;
3977 * Start the job if necessary...
3985 * 'copy_attrs()' - Copy attributes from one request to another.
3989 copy_attrs(ipp_t
*to
, /* I - Destination request */
3990 ipp_t
*from
, /* I - Source request */
3991 cups_array_t
*ra
, /* I - Requested attributes */
3992 ipp_tag_t group
, /* I - Group to copy */
3993 int quickcopy
, /* I - Do a quick copy? */
3994 cups_array_t
*exclude
) /* I - Attributes to exclude? */
3996 ipp_attribute_t
*fromattr
; /* Source attribute */
3999 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4000 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4001 to
, from
, ra
, group
, quickcopy
);
4006 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4009 * Filter attributes as needed...
4012 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4013 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4016 if (!strcmp(fromattr
->name
, "document-password") ||
4017 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4018 !strcmp(fromattr
->name
, "job-password") ||
4019 !strcmp(fromattr
->name
, "job-password-encryption") ||
4020 !strcmp(fromattr
->name
, "job-printer-uri"))
4024 (cupsArrayFind(exclude
, fromattr
->name
) ||
4025 cupsArrayFind(exclude
, "all")))
4028 * We need to exclude this attribute for security reasons; we require the
4029 * job-id attribute regardless of the security settings for IPP
4032 * The job-printer-uri attribute is handled by copy_job_attrs().
4034 * Subscription attribute security is handled by copy_subscription_attrs().
4037 if (strcmp(fromattr
->name
, "job-id"))
4041 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4044 * Don't send collection attributes by default to IPP/1.x clients
4045 * since many do not support collections. Also don't send
4046 * media-col-database unless specifically requested by the client.
4049 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4051 (to
->request
.status
.version
[0] == 1 ||
4052 !strcmp(fromattr
->name
, "media-col-database")))
4055 ippCopyAttribute(to
, fromattr
, quickcopy
);
4062 * 'copy_banner()' - Copy a banner file to the requests directory for the
4066 static int /* O - Size of banner file in kbytes */
4067 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4068 cupsd_job_t
*job
, /* I - Job information */
4069 const char *name
) /* I - Name of banner */
4071 int i
; /* Looping var */
4072 int kbytes
; /* Size of banner file in kbytes */
4073 char filename
[1024]; /* Job filename */
4074 cupsd_banner_t
*banner
; /* Pointer to banner */
4075 cups_file_t
*in
; /* Input file */
4076 cups_file_t
*out
; /* Output file */
4077 int ch
; /* Character from file */
4078 char attrname
[255], /* Name of attribute */
4079 *s
; /* Pointer into name */
4080 ipp_attribute_t
*attr
; /* Attribute */
4083 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4084 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4085 con
, con
? con
->number
: -1, job
, job
->id
,
4086 name
? name
: "(null)");
4089 * Find the banner; return if not found or "none"...
4092 if (!name
|| !strcmp(name
, "none") ||
4093 (banner
= cupsdFindBanner(name
)) == NULL
)
4097 * Open the banner and job files...
4100 if (add_file(con
, job
, banner
->filetype
, 0))
4103 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4105 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4107 cupsdLogMessage(CUPSD_LOG_ERROR
,
4108 "Unable to create banner job file %s - %s",
4109 filename
, strerror(errno
));
4114 fchmod(cupsFileNumber(out
), 0640);
4115 fchown(cupsFileNumber(out
), RunUser
, Group
);
4118 * Try the localized banner file under the subdirectory...
4121 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4123 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4126 * Convert ll-cc to ll_CC...
4130 attrname
[3] = (char)toupper(attrname
[3] & 255);
4131 attrname
[4] = (char)toupper(attrname
[4] & 255);
4134 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4137 if (access(filename
, 0) && strlen(attrname
) > 2)
4140 * Wasn't able to find "ll_CC" locale file; try the non-national
4141 * localization banner directory.
4146 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4150 if (access(filename
, 0))
4153 * Use the non-localized banner file.
4156 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4159 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4163 cupsdLogMessage(CUPSD_LOG_ERROR
,
4164 "Unable to open banner template file %s - %s",
4165 filename
, strerror(errno
));
4171 * Parse the file to the end...
4174 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4178 * Get an attribute name...
4181 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4182 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4184 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4194 * Ignore { followed by stuff that is not an attribute name...
4197 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4202 * See if it is defined...
4205 if (attrname
[0] == '?')
4210 if (!strcmp(s
, "printer-name"))
4212 cupsFilePuts(out
, job
->dest
);
4215 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4218 * See if we have a leading question mark...
4221 if (attrname
[0] != '?')
4224 * Nope, write to file as-is; probably a PostScript procedure...
4227 cupsFilePrintf(out
, "{%s}", attrname
);
4234 * Output value(s)...
4237 for (i
= 0; i
< attr
->num_values
; i
++)
4240 cupsFilePutChar(out
, ',');
4242 switch (attr
->value_tag
)
4244 case IPP_TAG_INTEGER
:
4246 if (!strncmp(s
, "time-at-", 8))
4248 struct timeval tv
; /* Time value */
4250 tv
.tv_sec
= attr
->values
[i
].integer
;
4253 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4256 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4259 case IPP_TAG_BOOLEAN
:
4260 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4263 case IPP_TAG_NOVALUE
:
4264 cupsFilePuts(out
, "novalue");
4267 case IPP_TAG_RANGE
:
4268 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4269 attr
->values
[i
].range
.upper
);
4272 case IPP_TAG_RESOLUTION
:
4273 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4274 attr
->values
[i
].resolution
.yres
,
4275 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4280 case IPP_TAG_STRING
:
4283 case IPP_TAG_KEYWORD
:
4284 case IPP_TAG_CHARSET
:
4285 case IPP_TAG_LANGUAGE
:
4286 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4289 * Need to quote strings for PS banners...
4294 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4296 if (*p
== '(' || *p
== ')' || *p
== '\\')
4298 cupsFilePutChar(out
, '\\');
4299 cupsFilePutChar(out
, *p
);
4301 else if (*p
< 32 || *p
> 126)
4302 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4304 cupsFilePutChar(out
, *p
);
4308 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4312 break; /* anti-compiler-warning-code */
4316 else if (ch
== '\\') /* Quoted char */
4318 ch
= cupsFileGetChar(in
);
4320 if (ch
!= '{') /* Only do special handling for \{ */
4321 cupsFilePutChar(out
, '\\');
4323 cupsFilePutChar(out
, ch
);
4326 cupsFilePutChar(out
, ch
);
4330 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4332 job
->koctets
+= kbytes
;
4334 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4335 attr
->values
[0].integer
+= kbytes
;
4344 * 'copy_file()' - Copy a PPD file or interface script...
4347 static int /* O - 0 = success, -1 = error */
4348 copy_file(const char *from
, /* I - Source file */
4349 const char *to
) /* I - Destination file */
4351 cups_file_t
*src
, /* Source file */
4352 *dst
; /* Destination file */
4353 int bytes
; /* Bytes to read/write */
4354 char buffer
[2048]; /* Copy buffer */
4357 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4360 * Open the source and destination file for a copy...
4363 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4366 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4373 * Copy the source file to the destination...
4376 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4377 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4385 * Close both files and return...
4390 return (cupsFileClose(dst
));
4395 * 'copy_model()' - Copy a PPD model file, substituting default values
4399 static int /* O - 0 = success, -1 = error */
4400 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4401 const char *from
, /* I - Source file */
4402 const char *to
) /* I - Destination file */
4404 fd_set input
; /* select() input set */
4405 struct timeval timeout
; /* select() timeout */
4406 int maxfd
; /* Max file descriptor for select() */
4407 char tempfile
[1024]; /* Temporary PPD file */
4408 int tempfd
; /* Temporary PPD file descriptor */
4409 int temppid
; /* Process ID of cups-driverd */
4410 int temppipe
[2]; /* Temporary pipes */
4411 char *argv
[4], /* Command-line arguments */
4412 *envp
[MAX_ENV
]; /* Environment */
4413 cups_file_t
*src
, /* Source file */
4414 *dst
; /* Destination file */
4415 ppd_file_t
*ppd
; /* PPD file */
4416 int bytes
, /* Bytes from pipe */
4417 total
; /* Total bytes from pipe */
4418 char buffer
[2048]; /* Copy buffer */
4419 int i
; /* Looping var */
4420 char option
[PPD_MAX_NAME
], /* Option name */
4421 choice
[PPD_MAX_NAME
]; /* Choice name */
4422 ppd_size_t
*size
; /* Default size */
4423 int num_defaults
; /* Number of default options */
4424 cups_option_t
*defaults
; /* Default options */
4425 char cups_protocol
[PPD_MAX_LINE
];
4426 /* cupsProtocol attribute */
4429 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4430 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4434 * Run cups-driverd to get the PPD file...
4437 argv
[0] = "cups-driverd";
4439 argv
[2] = (char *)from
;
4442 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4444 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4445 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4446 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4447 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4450 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4451 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4453 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4454 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4465 * Wait up to 30 seconds for the PPD file to be copied...
4470 if (temppipe
[0] > CGIPipes
[0])
4471 maxfd
= temppipe
[0] + 1;
4473 maxfd
= CGIPipes
[0] + 1;
4478 * See if we have data ready...
4482 FD_SET(temppipe
[0], &input
);
4483 FD_SET(CGIPipes
[0], &input
);
4485 timeout
.tv_sec
= 30;
4486 timeout
.tv_usec
= 0;
4488 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4498 * We have timed out...
4504 if (FD_ISSET(temppipe
[0], &input
))
4507 * Read the PPD file from the pipe, and write it to the PPD file.
4510 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4512 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4521 if (FD_ISSET(CGIPipes
[0], &input
))
4531 * No data from cups-deviced...
4534 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4540 * Open the source file for a copy...
4543 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4550 * Read the source file and see what page sizes are supported...
4553 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4561 * Open the destination (if possible) and set the default options...
4566 cups_protocol
[0] = '\0';
4568 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4571 * Read all of the default lines from the old PPD...
4574 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4575 if (!strncmp(buffer
, "*Default", 8))
4578 * Add the default option...
4581 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4582 choice
, sizeof(choice
)))
4584 ppd_option_t
*ppdo
; /* PPD option */
4588 * Only add the default if the default hasn't already been
4589 * set and the choice exists in the new PPD...
4592 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4593 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4594 ppdFindChoice(ppdo
, choice
))
4595 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4599 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4600 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4604 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4607 * Add the default media sizes...
4610 num_defaults
= cupsAddOption("PageSize", size
->name
,
4611 num_defaults
, &defaults
);
4612 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4613 num_defaults
, &defaults
);
4614 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4615 num_defaults
, &defaults
);
4616 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4617 num_defaults
, &defaults
);
4623 * Open the destination file for a copy...
4626 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4628 cupsFreeOptions(num_defaults
, defaults
);
4635 * Copy the source file to the destination...
4638 cupsFileRewind(src
);
4640 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4642 if (!strncmp(buffer
, "*Default", 8))
4645 * Check for an previous default option choice...
4648 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4649 choice
, sizeof(choice
)))
4651 const char *val
; /* Default option value */
4654 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4657 * Substitute the previous choice...
4660 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4665 cupsFilePrintf(dst
, "%s\n", buffer
);
4668 if (cups_protocol
[0])
4669 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4671 cupsFreeOptions(num_defaults
, defaults
);
4674 * Close both files and return...
4681 return (cupsFileClose(dst
));
4686 * 'copy_job_attrs()' - Copy job attributes.
4690 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4691 cupsd_job_t
*job
, /* I - Job */
4692 cups_array_t
*ra
, /* I - Requested attributes array */
4693 cups_array_t
*exclude
) /* I - Private attributes array */
4695 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4699 * Send the requested attributes for each job...
4702 if (!cupsArrayFind(exclude
, "all"))
4704 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4705 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4706 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4707 "number-of-documents", job
->num_files
);
4709 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4710 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4711 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4712 "job-media-progress", job
->progress
);
4714 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4715 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4717 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4718 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4720 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4721 "job-more-info", NULL
, job_uri
);
4724 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4725 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4726 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4727 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4728 job
->num_files
> 0);
4730 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4731 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4732 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4733 "job-printer-up-time", time(NULL
));
4736 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4738 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4739 con
->clientname
, con
->clientport
,
4740 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4743 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4744 "job-printer-uri", NULL
, job_uri
);
4747 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4749 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4750 con
->clientname
, con
->clientport
, "/jobs/%d",
4752 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4753 "job-uri", NULL
, job_uri
);
4758 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4763 * Generate attributes from the job structure...
4766 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4767 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4769 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4770 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4772 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4773 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4775 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4776 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4778 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4779 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4781 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4783 switch (job
->state_value
)
4785 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4787 case IPP_JSTATE_ABORTED
:
4788 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4790 case IPP_JSTATE_CANCELED
:
4791 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4793 case IPP_JSTATE_COMPLETED
:
4794 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4799 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4800 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4802 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4803 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4809 * 'copy_printer_attrs()' - Copy printer attributes.
4814 cupsd_client_t
*con
, /* I - Client connection */
4815 cupsd_printer_t
*printer
, /* I - Printer */
4816 cups_array_t
*ra
) /* I - Requested attributes array */
4818 char printer_uri
[HTTP_MAX_URI
];
4820 char printer_icons
[HTTP_MAX_URI
];
4822 time_t curtime
; /* Current time */
4823 int i
; /* Looping var */
4827 * Copy the printer attributes to the response using requested-attributes
4828 * and document-format attributes that may be provided by the client.
4831 curtime
= time(NULL
);
4833 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4834 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4835 "marker-change-time", printer
->marker_time
);
4837 if (printer
->num_printers
> 0 &&
4838 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4840 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4841 cupsd_printer_t
*p2
; /* Printer in class */
4842 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4845 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4846 IPP_TAG_URI
, "member-uris",
4847 printer
->num_printers
, NULL
,
4850 for (i
= 0; i
< printer
->num_printers
; i
++)
4852 p2
= printer
->printers
[i
];
4854 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4855 IPP_TAG_URI
)) != NULL
)
4856 member_uris
->values
[i
].string
.text
=
4857 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4860 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4861 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4863 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4864 "/classes/%s" : "/printers/%s", p2
->name
);
4865 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4871 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4872 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4873 "printer-alert", NULL
, printer
->alert
);
4875 if (printer
->alert_description
&&
4876 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4877 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4878 "printer-alert-description", NULL
,
4879 printer
->alert_description
);
4881 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4882 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4883 ippTimeToDate(curtime
));
4885 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4886 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4888 if (printer
->reg_name
)
4889 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4890 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4892 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4893 "printer-dns-sd-name", 0);
4895 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4897 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4898 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4899 "printer-error-policy", NULL
, printer
->error_policy
);
4901 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4903 static const char * const errors
[] =/* printer-error-policy-supported values */
4906 "retry-current-job",
4911 if (printer
->type
& CUPS_PRINTER_CLASS
)
4912 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4913 "printer-error-policy-supported", NULL
, "retry-current-job");
4915 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4916 "printer-error-policy-supported",
4917 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4920 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4922 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4923 "http", NULL
, con
->clientname
, con
->clientport
,
4924 "/icons/%s.png", printer
->name
);
4925 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4926 NULL
, printer_icons
);
4927 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4930 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4931 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4933 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4934 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4936 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4938 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4939 "http", NULL
, con
->clientname
, con
->clientport
,
4940 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4941 "/classes/%s" : "/printers/%s", printer
->name
);
4942 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4943 "printer-more-info", NULL
, printer_uri
);
4946 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4947 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4948 "printer-op-policy", NULL
, printer
->op_policy
);
4950 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4951 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4954 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4955 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4956 "printer-state-change-time", printer
->state_time
);
4958 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4959 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4960 "printer-state-message", NULL
, printer
->state_message
);
4962 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4963 add_printer_state_reasons(con
, printer
);
4965 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4967 cups_ptype_t type
; /* printer-type value */
4970 * Add the CUPS-specific printer-type attribute...
4973 type
= printer
->type
;
4975 if (printer
== DefaultPrinter
)
4976 type
|= CUPS_PRINTER_DEFAULT
;
4978 if (!printer
->accepting
)
4979 type
|= CUPS_PRINTER_REJECTING
;
4981 if (!printer
->shared
)
4982 type
|= CUPS_PRINTER_NOT_SHARED
;
4984 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
4987 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4988 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4989 "printer-up-time", curtime
);
4991 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
4993 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4994 "ipp", NULL
, con
->clientname
, con
->clientport
,
4995 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4996 "/classes/%s" : "/printers/%s", printer
->name
);
4997 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4998 "printer-uri-supported", NULL
, printer_uri
);
4999 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
5003 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5004 add_queued_job_count(con
, printer
);
5006 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5007 if (printer
->ppd_attrs
)
5008 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5009 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5014 * 'copy_subscription_attrs()' - Copy subscription attributes.
5018 copy_subscription_attrs(
5019 cupsd_client_t
*con
, /* I - Client connection */
5020 cupsd_subscription_t
*sub
, /* I - Subscription */
5021 cups_array_t
*ra
, /* I - Requested attributes array */
5022 cups_array_t
*exclude
) /* I - Private attributes array */
5024 ipp_attribute_t
*attr
; /* Current attribute */
5025 char printer_uri
[HTTP_MAX_URI
];
5027 int count
; /* Number of events */
5028 unsigned mask
; /* Current event mask */
5029 const char *name
; /* Current event name */
5032 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5033 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5034 con
, sub
, ra
, exclude
);
5037 * Copy the subscription attributes to the response using the
5038 * requested-attributes attribute that may be provided by the client.
5041 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5043 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5044 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5046 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5048 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5051 * Simple event list...
5054 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5055 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5056 "notify-events", NULL
, name
);
5061 * Complex event list...
5064 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5065 if (sub
->mask
& mask
)
5068 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5069 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5070 "notify-events", count
, NULL
, NULL
);
5072 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5073 if (sub
->mask
& mask
)
5075 attr
->values
[count
].string
.text
=
5076 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5083 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5084 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5085 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5086 "notify-lease-duration", sub
->lease
);
5088 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5089 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5090 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5091 "notify-recipient-uri", NULL
, sub
->recipient
);
5092 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5093 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5094 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5095 "notify-pull-method", NULL
, "ippget");
5097 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5098 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5099 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5100 "notify-subscriber-user-name", NULL
, sub
->owner
);
5102 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5103 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5104 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5105 "notify-time-interval", sub
->interval
);
5107 if (sub
->user_data_len
> 0 &&
5108 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5109 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5110 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5111 sub
->user_data
, sub
->user_data_len
);
5114 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5115 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5116 "notify-job-id", sub
->job
->id
);
5118 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5120 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5121 "ipp", NULL
, con
->clientname
, con
->clientport
,
5122 "/printers/%s", sub
->dest
->name
);
5123 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5124 "notify-printer-uri", NULL
, printer_uri
);
5127 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5128 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5129 "notify-subscription-id", sub
->id
);
5134 * 'create_job()' - Print a file to a printer or class.
5138 create_job(cupsd_client_t
*con
, /* I - Client connection */
5139 ipp_attribute_t
*uri
) /* I - Printer URI */
5141 int i
; /* Looping var */
5142 cupsd_printer_t
*printer
; /* Printer */
5143 cupsd_job_t
*job
; /* New job */
5144 static const char * const forbidden_attrs
[] =
5145 { /* List of forbidden attributes */
5149 "document-natural-language"
5153 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5154 con
->number
, uri
->values
[0].string
.text
);
5157 * Is the destination valid?
5160 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5166 send_ipp_status(con
, IPP_NOT_FOUND
,
5167 _("The printer or class does not exist."));
5172 * Check for invalid Create-Job attributes and log a warning or error depending
5173 * on whether cupsd is running in "strict conformance" mode...
5177 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5179 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5181 if (StrictConformance
)
5183 send_ipp_status(con
, IPP_BAD_REQUEST
,
5184 _("The '%s' operation attribute cannot be supplied in a "
5185 "Create-Job request."), forbidden_attrs
[i
]);
5189 cupsdLogMessage(CUPSD_LOG_WARN
,
5190 "Unexpected '%s' operation attribute in a Create-Job "
5191 "request.", forbidden_attrs
[i
]);
5195 * Create the job object...
5198 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5201 job
->pending_timeout
= 1;
5204 * Save and log the job...
5207 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5208 job
->dest
, job
->username
);
5213 * 'create_requested_array()' - Create an array for the requested-attributes.
5216 static cups_array_t
* /* O - Array of attributes or NULL */
5217 create_requested_array(ipp_t
*request
) /* I - IPP request */
5219 cups_array_t
*ra
; /* Requested attributes array */
5223 * Create the array for standard attributes...
5226 ra
= ippCreateRequestedArray(request
);
5229 * Add CUPS defaults as needed...
5232 if (cupsArrayFind(ra
, "printer-defaults"))
5235 * Include user-set defaults...
5238 char *name
; /* Option name */
5240 cupsArrayRemove(ra
, "printer-defaults");
5242 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5244 name
= (char *)cupsArrayNext(CommonDefaults
))
5245 if (!cupsArrayFind(ra
, name
))
5246 cupsArrayAdd(ra
, name
);
5254 * 'create_subscriptions()' - Create one or more notification subscriptions.
5258 create_subscriptions(
5259 cupsd_client_t
*con
, /* I - Client connection */
5260 ipp_attribute_t
*uri
) /* I - Printer URI */
5262 http_status_t status
; /* Policy status */
5263 int i
; /* Looping var */
5264 ipp_attribute_t
*attr
; /* Current attribute */
5265 cups_ptype_t dtype
; /* Destination type (printer/class) */
5266 char scheme
[HTTP_MAX_URI
],
5267 /* Scheme portion of URI */
5268 userpass
[HTTP_MAX_URI
],
5269 /* Username portion of URI */
5271 /* Host portion of URI */
5272 resource
[HTTP_MAX_URI
];
5273 /* Resource portion of URI */
5274 int port
; /* Port portion of URI */
5275 cupsd_printer_t
*printer
; /* Printer/class */
5276 cupsd_job_t
*job
; /* Job */
5277 int jobid
; /* Job ID */
5278 cupsd_subscription_t
*sub
; /* Subscription object */
5279 const char *username
, /* requesting-user-name or
5280 authenticated username */
5281 *recipient
, /* notify-recipient-uri */
5282 *pullmethod
; /* notify-pull-method */
5283 ipp_attribute_t
*user_data
; /* notify-user-data */
5284 int interval
, /* notify-time-interval */
5285 lease
; /* notify-lease-duration */
5286 unsigned mask
; /* notify-events */
5287 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5288 *notify_lease
; /* notify-lease-duration(-default) */
5292 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5294 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5295 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5296 attr
->value_tag
, attr
->name
);
5298 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5303 * Is the destination valid?
5306 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5308 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5309 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5310 sizeof(host
), &port
, resource
, sizeof(resource
));
5312 if (!strcmp(resource
, "/"))
5314 dtype
= (cups_ptype_t
)0;
5317 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5319 dtype
= (cups_ptype_t
)0;
5322 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5324 dtype
= CUPS_PRINTER_CLASS
;
5327 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5333 send_ipp_status(con
, IPP_NOT_FOUND
,
5334 _("The printer or class does not exist."));
5344 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5347 send_http_error(con
, status
, printer
);
5351 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5353 send_http_error(con
, status
, NULL
);
5358 * Get the user that is requesting the subscription...
5361 username
= get_username(con
);
5364 * Find the first subscription group attribute; return if we have
5368 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5369 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5374 send_ipp_status(con
, IPP_BAD_REQUEST
,
5375 _("No subscription attributes in request."));
5380 * Process the subscription attributes in the request...
5383 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5391 lease
= DefaultLeaseDuration
;
5393 mask
= CUPSD_EVENT_NONE
;
5397 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5399 notify_lease
= ippFindAttribute(printer
->attrs
,
5400 "notify-lease-duration-default",
5404 lease
= notify_lease
->values
[0].integer
;
5408 notify_events
= NULL
;
5409 notify_lease
= NULL
;
5412 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5414 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5415 attr
->value_tag
== IPP_TAG_URI
)
5418 * Validate the recipient scheme against the ServerBin/notifier
5422 char notifier
[1024]; /* Notifier filename */
5425 recipient
= attr
->values
[0].string
.text
;
5427 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5428 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5429 host
, sizeof(host
), &port
,
5430 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5432 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5433 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5434 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5435 "notify-status-code", IPP_URI_SCHEME
);
5439 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5441 if (access(notifier
, X_OK
))
5443 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5444 _("notify-recipient-uri URI \"%s\" uses unknown "
5445 "scheme."), recipient
);
5446 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5447 "notify-status-code", IPP_URI_SCHEME
);
5451 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5453 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5454 _("notify-recipient-uri URI \"%s\" is already used."),
5456 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5457 "notify-status-code", IPP_ATTRIBUTES
);
5461 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5462 attr
->value_tag
== IPP_TAG_KEYWORD
)
5464 pullmethod
= attr
->values
[0].string
.text
;
5466 if (strcmp(pullmethod
, "ippget"))
5468 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5469 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5470 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5471 "notify-status-code", IPP_ATTRIBUTES
);
5475 else if (!strcmp(attr
->name
, "notify-charset") &&
5476 attr
->value_tag
== IPP_TAG_CHARSET
&&
5477 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5478 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5480 send_ipp_status(con
, IPP_CHARSET
,
5481 _("Character set \"%s\" not supported."),
5482 attr
->values
[0].string
.text
);
5485 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5486 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5487 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5489 send_ipp_status(con
, IPP_CHARSET
,
5490 _("Language \"%s\" not supported."),
5491 attr
->values
[0].string
.text
);
5494 else if (!strcmp(attr
->name
, "notify-user-data") &&
5495 attr
->value_tag
== IPP_TAG_STRING
)
5497 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5499 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5500 _("The notify-user-data value is too large "
5501 "(%d > 63 octets)."),
5502 attr
->values
[0].unknown
.length
);
5508 else if (!strcmp(attr
->name
, "notify-events") &&
5509 attr
->value_tag
== IPP_TAG_KEYWORD
)
5510 notify_events
= attr
;
5511 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5512 attr
->value_tag
== IPP_TAG_INTEGER
)
5513 lease
= attr
->values
[0].integer
;
5514 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5515 attr
->value_tag
== IPP_TAG_INTEGER
)
5516 interval
= attr
->values
[0].integer
;
5517 else if (!strcmp(attr
->name
, "notify-job-id") &&
5518 attr
->value_tag
== IPP_TAG_INTEGER
)
5519 jobid
= attr
->values
[0].integer
;
5526 for (i
= 0; i
< notify_events
->num_values
; i
++)
5527 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5531 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5533 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5534 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5535 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5537 if (!recipient
&& !pullmethod
)
5540 if (mask
== CUPSD_EVENT_NONE
)
5543 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5545 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5548 send_ipp_status(con
, IPP_BAD_REQUEST
,
5549 _("notify-events not specified."));
5554 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5556 cupsdLogMessage(CUPSD_LOG_INFO
,
5557 "create_subscriptions: Limiting notify-lease-duration to "
5560 lease
= MaxLeaseDuration
;
5565 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5567 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5575 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5577 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5578 _("There are too many subscriptions."));
5583 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5586 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5587 "Added subscription #%d for printer \"%s\".",
5588 sub
->id
, printer
->name
);
5590 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5593 sub
->interval
= interval
;
5595 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5597 cupsdSetString(&sub
->owner
, username
);
5601 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5602 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5603 (size_t)sub
->user_data_len
);
5606 ippAddSeparator(con
->response
);
5607 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5608 "notify-subscription-id", sub
->id
);
5610 con
->response
->request
.status
.status_code
= IPP_OK
;
5616 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5621 * 'delete_printer()' - Remove a printer or class from the system.
5625 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5626 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5628 http_status_t status
; /* Policy status */
5629 cups_ptype_t dtype
; /* Destination type (printer/class) */
5630 cupsd_printer_t
*printer
; /* Printer/class */
5631 char filename
[1024]; /* Script/PPD filename */
5634 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5635 con
->number
, uri
->values
[0].string
.text
);
5638 * Do we have a valid URI?
5641 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5647 send_ipp_status(con
, IPP_NOT_FOUND
,
5648 _("The printer or class does not exist."));
5656 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5658 send_http_error(con
, status
, NULL
);
5663 * Remove old jobs...
5666 cupsdCancelJobs(printer
->name
, NULL
, 1);
5669 * Remove old subscriptions and send a "deleted printer" event...
5672 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5673 "%s \"%s\" deleted by \"%s\".",
5674 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5675 printer
->name
, get_username(con
));
5677 cupsdExpireSubscriptions(printer
, NULL
);
5680 * Remove any old PPD or script files...
5683 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5686 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s.O", ServerRoot
,
5690 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5693 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5697 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5700 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5704 * Unregister color profiles...
5707 cupsdUnregisterColor(printer
);
5709 if (dtype
& CUPS_PRINTER_CLASS
)
5711 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5712 printer
->name
, get_username(con
));
5714 cupsdDeletePrinter(printer
, 0);
5715 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5719 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5720 printer
->name
, get_username(con
));
5722 if (cupsdDeletePrinter(printer
, 0))
5723 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5725 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5728 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5731 * Return with no errors...
5734 con
->response
->request
.status
.status_code
= IPP_OK
;
5739 * 'get_default()' - Get the default destination.
5743 get_default(cupsd_client_t
*con
) /* I - Client connection */
5745 http_status_t status
; /* Policy status */
5746 cups_array_t
*ra
; /* Requested attributes array */
5749 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
5755 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5757 send_http_error(con
, status
, NULL
);
5763 ra
= create_requested_array(con
->request
);
5765 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5767 cupsArrayDelete(ra
);
5769 con
->response
->request
.status
.status_code
= IPP_OK
;
5772 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5777 * 'get_devices()' - Get the list of available devices on the local system.
5781 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5783 http_status_t status
; /* Policy status */
5784 ipp_attribute_t
*limit
, /* limit attribute */
5785 *timeout
, /* timeout attribute */
5786 *requested
, /* requested-attributes attribute */
5787 *exclude
, /* exclude-schemes attribute */
5788 *include
; /* include-schemes attribute */
5789 char command
[1024], /* cups-deviced command */
5790 options
[2048], /* Options to pass to command */
5792 /* String for requested attributes */
5794 /* String for excluded schemes */
5796 /* String for included schemes */
5799 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
5805 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5807 send_http_error(con
, status
, NULL
);
5812 * Run cups-deviced command with the given options...
5815 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5816 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5817 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5819 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5820 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5823 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5825 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5828 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5830 exclude_str
[0] = '\0';
5833 url_encode_attr(include
, include_str
, sizeof(include_str
));
5835 include_str
[0] = '\0';
5837 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5838 snprintf(options
, sizeof(options
),
5839 "%d+%d+%d+%d+%s%s%s%s%s",
5840 con
->request
->request
.op
.request_id
,
5841 limit
? limit
->values
[0].integer
: 0,
5842 timeout
? timeout
->values
[0].integer
: 15,
5845 exclude_str
[0] ? "%20" : "", exclude_str
,
5846 include_str
[0] ? "%20" : "", include_str
);
5848 if (cupsdSendCommand(con
, command
, options
, 1))
5851 * Command started successfully, don't send an IPP response here...
5854 ippDelete(con
->response
);
5855 con
->response
= NULL
;
5860 * Command failed, return "internal error" so the user knows something
5864 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5865 _("cups-deviced failed to execute."));
5871 * 'get_document()' - Get a copy of a job file.
5875 get_document(cupsd_client_t
*con
, /* I - Client connection */
5876 ipp_attribute_t
*uri
) /* I - Job URI */
5878 http_status_t status
; /* Policy status */
5879 ipp_attribute_t
*attr
; /* Current attribute */
5880 int jobid
; /* Job ID */
5881 int docnum
; /* Document number */
5882 cupsd_job_t
*job
; /* Current job */
5883 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
5884 username
[HTTP_MAX_URI
], /* Username portion of URI */
5885 host
[HTTP_MAX_URI
], /* Host portion of URI */
5886 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5887 int port
; /* Port portion of URI */
5888 char filename
[1024], /* Filename for document */
5889 format
[1024]; /* Format for document */
5892 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
5893 con
->number
, uri
->values
[0].string
.text
);
5896 * See if we have a job URI or a printer URI...
5899 if (!strcmp(uri
->name
, "printer-uri"))
5902 * Got a printer URI; see if we also have a job-id attribute...
5905 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5906 IPP_TAG_INTEGER
)) == NULL
)
5908 send_ipp_status(con
, IPP_BAD_REQUEST
,
5909 _("Got a printer-uri attribute but no job-id."));
5913 jobid
= attr
->values
[0].integer
;
5918 * Got a job URI; parse it to get the job ID...
5921 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5922 sizeof(scheme
), username
, sizeof(username
), host
,
5923 sizeof(host
), &port
, resource
, sizeof(resource
));
5925 if (strncmp(resource
, "/jobs/", 6))
5931 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
5932 uri
->values
[0].string
.text
);
5936 jobid
= atoi(resource
+ 6);
5940 * See if the job exists...
5943 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5946 * Nope - return a "not found" error...
5949 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
5957 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
5958 job
->username
)) != HTTP_OK
)
5960 send_http_error(con
, status
, NULL
);
5965 * Get the document number...
5968 if ((attr
= ippFindAttribute(con
->request
, "document-number",
5969 IPP_TAG_INTEGER
)) == NULL
)
5971 send_ipp_status(con
, IPP_BAD_REQUEST
,
5972 _("Missing document-number attribute."));
5976 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
5977 attr
->num_values
> 1)
5979 send_ipp_status(con
, IPP_NOT_FOUND
,
5980 _("Document #%d does not exist in job #%d."), docnum
,
5985 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
5987 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
5989 cupsdLogMessage(CUPSD_LOG_ERROR
,
5990 "Unable to open document %d in job %d - %s", docnum
, jobid
,
5992 send_ipp_status(con
, IPP_NOT_FOUND
,
5993 _("Unable to open document #%d in job #%d."), docnum
,
5998 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6002 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6003 job
->filetypes
[docnum
- 1]->type
);
6005 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6007 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6009 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6010 IPP_TAG_NAME
)) != NULL
)
6011 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6012 NULL
, attr
->values
[0].string
.text
);
6017 * 'get_job_attrs()' - Get job attributes.
6021 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6022 ipp_attribute_t
*uri
) /* I - Job URI */
6024 http_status_t status
; /* Policy status */
6025 ipp_attribute_t
*attr
; /* Current attribute */
6026 int jobid
; /* Job ID */
6027 cupsd_job_t
*job
; /* Current job */
6028 cupsd_printer_t
*printer
; /* Current printer */
6029 cupsd_policy_t
*policy
; /* Current security policy */
6030 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6031 username
[HTTP_MAX_URI
], /* Username portion of URI */
6032 host
[HTTP_MAX_URI
], /* Host portion of URI */
6033 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6034 int port
; /* Port portion of URI */
6035 cups_array_t
*ra
, /* Requested attributes array */
6036 *exclude
; /* Private attributes array */
6039 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6040 con
->number
, uri
->values
[0].string
.text
);
6043 * See if we have a job URI or a printer URI...
6046 if (!strcmp(uri
->name
, "printer-uri"))
6049 * Got a printer URI; see if we also have a job-id attribute...
6052 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6053 IPP_TAG_INTEGER
)) == NULL
)
6055 send_ipp_status(con
, IPP_BAD_REQUEST
,
6056 _("Got a printer-uri attribute but no job-id."));
6060 jobid
= attr
->values
[0].integer
;
6065 * Got a job URI; parse it to get the job ID...
6068 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6069 sizeof(scheme
), username
, sizeof(username
), host
,
6070 sizeof(host
), &port
, resource
, sizeof(resource
));
6072 if (strncmp(resource
, "/jobs/", 6))
6078 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6079 uri
->values
[0].string
.text
);
6083 jobid
= atoi(resource
+ 6);
6087 * See if the job exists...
6090 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6093 * Nope - return a "not found" error...
6096 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6104 if ((printer
= job
->printer
) == NULL
)
6105 printer
= cupsdFindDest(job
->dest
);
6108 policy
= printer
->op_policy_ptr
;
6110 policy
= DefaultPolicyPtr
;
6112 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6114 send_http_error(con
, status
, NULL
);
6118 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6121 * Copy attributes...
6126 ra
= create_requested_array(con
->request
);
6127 copy_job_attrs(con
, job
, ra
, exclude
);
6128 cupsArrayDelete(ra
);
6130 con
->response
->request
.status
.status_code
= IPP_OK
;
6135 * 'get_jobs()' - Get a list of jobs for the specified printer.
6139 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6140 ipp_attribute_t
*uri
) /* I - Printer URI */
6142 http_status_t status
; /* Policy status */
6143 ipp_attribute_t
*attr
; /* Current attribute */
6144 const char *dest
; /* Destination */
6145 cups_ptype_t dtype
; /* Destination type (printer/class) */
6146 cups_ptype_t dmask
; /* Destination type mask */
6147 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6148 username
[HTTP_MAX_URI
], /* Username portion of URI */
6149 host
[HTTP_MAX_URI
], /* Host portion of URI */
6150 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6151 int port
; /* Port portion of URI */
6152 int job_comparison
; /* Job comparison */
6153 ipp_jstate_t job_state
; /* job-state value */
6154 int first_job_id
= 1, /* First job ID */
6155 first_index
= 1, /* First index */
6156 current_index
= 0; /* Current index */
6157 int limit
= 0; /* Maximum number of jobs to return */
6158 int count
; /* Number of jobs that match */
6159 int need_load_job
= 0; /* Do we need to load the job? */
6160 const char *job_attr
; /* Job attribute requested */
6161 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6162 cupsd_job_t
*job
; /* Current job pointer */
6163 cupsd_printer_t
*printer
; /* Printer */
6164 cups_array_t
*list
; /* Which job list... */
6165 int delete_list
= 0; /* Delete the list afterwards? */
6166 cups_array_t
*ra
, /* Requested attributes array */
6167 *exclude
; /* Private attributes array */
6168 cupsd_policy_t
*policy
; /* Current policy */
6171 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6172 uri
->values
[0].string
.text
);
6175 * Is the destination valid?
6178 if (strcmp(uri
->name
, "printer-uri"))
6180 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6184 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6185 sizeof(scheme
), username
, sizeof(username
), host
,
6186 sizeof(host
), &port
, resource
, sizeof(resource
));
6188 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6191 dtype
= (cups_ptype_t
)0;
6192 dmask
= (cups_ptype_t
)0;
6195 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6198 dtype
= (cups_ptype_t
)0;
6199 dmask
= CUPS_PRINTER_CLASS
;
6202 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6205 dtype
= CUPS_PRINTER_CLASS
;
6206 dmask
= CUPS_PRINTER_CLASS
;
6209 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6216 send_ipp_status(con
, IPP_NOT_FOUND
,
6217 _("The printer or class does not exist."));
6222 dtype
&= CUPS_PRINTER_CLASS
;
6223 dmask
= CUPS_PRINTER_CLASS
;
6231 policy
= printer
->op_policy_ptr
;
6233 policy
= DefaultPolicyPtr
;
6235 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6237 send_http_error(con
, status
, NULL
);
6241 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6244 * See if the "which-jobs" attribute have been specified...
6247 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6248 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6250 send_ipp_status(con
, IPP_CONFLICT
,
6251 _("The %s attribute cannot be provided with job-ids."),
6255 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6257 job_comparison
= -1;
6258 job_state
= IPP_JOB_STOPPED
;
6261 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6264 job_state
= IPP_JOB_CANCELED
;
6265 list
= cupsdGetCompletedJobs(printer
);
6268 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6271 job_state
= IPP_JOB_ABORTED
;
6272 list
= cupsdGetCompletedJobs(printer
);
6275 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6278 job_state
= IPP_JOB_PENDING
;
6281 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6284 job_state
= IPP_JOB_CANCELED
;
6285 list
= cupsdGetCompletedJobs(printer
);
6288 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6291 job_state
= IPP_JOB_PENDING
;
6294 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6297 job_state
= IPP_JOB_HELD
;
6300 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6303 job_state
= IPP_JOB_PROCESSING
;
6304 list
= PrintingJobs
;
6306 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6309 job_state
= IPP_JOB_STOPPED
;
6314 send_ipp_status(con
, IPP_ATTRIBUTES
,
6315 _("The which-jobs value \"%s\" is not supported."),
6316 attr
->values
[0].string
.text
);
6317 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6318 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6323 * See if they want to limit the number of jobs reported...
6326 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6330 send_ipp_status(con
, IPP_CONFLICT
,
6331 _("The %s attribute cannot be provided with job-ids."),
6336 limit
= attr
->values
[0].integer
;
6339 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6343 send_ipp_status(con
, IPP_CONFLICT
,
6344 _("The %s attribute cannot be provided with job-ids."),
6349 first_index
= attr
->values
[0].integer
;
6351 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6355 send_ipp_status(con
, IPP_CONFLICT
,
6356 _("The %s attribute cannot be provided with job-ids."),
6361 first_job_id
= attr
->values
[0].integer
;
6365 * See if we only want to see jobs for a specific user...
6368 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6370 send_ipp_status(con
, IPP_CONFLICT
,
6371 _("The %s attribute cannot be provided with job-ids."),
6375 else if (attr
&& attr
->values
[0].boolean
)
6376 strlcpy(username
, get_username(con
), sizeof(username
));
6380 ra
= create_requested_array(con
->request
);
6381 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6382 if (strcmp(job_attr
, "job-id") &&
6383 strcmp(job_attr
, "job-k-octets") &&
6384 strcmp(job_attr
, "job-media-progress") &&
6385 strcmp(job_attr
, "job-more-info") &&
6386 strcmp(job_attr
, "job-name") &&
6387 strcmp(job_attr
, "job-originating-user-name") &&
6388 strcmp(job_attr
, "job-preserved") &&
6389 strcmp(job_attr
, "job-printer-up-time") &&
6390 strcmp(job_attr
, "job-printer-uri") &&
6391 strcmp(job_attr
, "job-state") &&
6392 strcmp(job_attr
, "job-state-reasons") &&
6393 strcmp(job_attr
, "job-uri") &&
6394 strcmp(job_attr
, "time-at-completed") &&
6395 strcmp(job_attr
, "time-at-creation") &&
6396 strcmp(job_attr
, "number-of-documents"))
6402 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6405 * Limit expensive Get-Jobs for job history to 500 jobs...
6408 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6411 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6415 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6419 * OK, build a list of jobs for this printer...
6424 int i
; /* Looping var */
6426 for (i
= 0; i
< job_ids
->num_values
; i
++)
6428 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6432 if (i
< job_ids
->num_values
)
6434 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6435 job_ids
->values
[i
].integer
);
6439 for (i
= 0; i
< job_ids
->num_values
; i
++)
6441 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6443 if (need_load_job
&& !job
->attrs
)
6449 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6455 ippAddSeparator(con
->response
);
6457 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6458 job
->printer
->op_policy_ptr
:
6459 policy
, con
, job
->printer
,
6462 copy_job_attrs(con
, job
, ra
, exclude
);
6467 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6468 (limit
<= 0 || count
< limit
) && job
;
6469 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6472 * Filter out jobs that don't match...
6475 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6476 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6477 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6478 job
->username
, job
->state_value
, job
->attrs
);
6480 if (!job
->dest
|| !job
->username
)
6483 if (!job
->dest
|| !job
->username
)
6486 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6487 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6489 if ((job
->dtype
& dmask
) != dtype
&&
6490 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6493 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6494 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6495 (job_comparison
> 0 && job
->state_value
< job_state
))
6498 if (job
->id
< first_job_id
)
6502 if (current_index
< first_index
)
6505 if (need_load_job
&& !job
->attrs
)
6511 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6516 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6520 ippAddSeparator(con
->response
);
6524 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6525 job
->printer
->op_policy_ptr
:
6526 policy
, con
, job
->printer
,
6529 copy_job_attrs(con
, job
, ra
, exclude
);
6532 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6535 cupsArrayDelete(ra
);
6538 cupsArrayDelete(list
);
6540 con
->response
->request
.status
.status_code
= IPP_OK
;
6545 * 'get_notifications()' - Get events for a subscription.
6549 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6551 int i
, j
; /* Looping vars */
6552 http_status_t status
; /* Policy status */
6553 cupsd_subscription_t
*sub
; /* Subscription */
6554 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6555 *sequences
; /* notify-sequence-numbers */
6556 int min_seq
; /* Minimum sequence number */
6557 int interval
; /* Poll interval */
6560 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6564 * Get subscription attributes...
6567 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6569 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6574 send_ipp_status(con
, IPP_BAD_REQUEST
,
6575 _("Missing notify-subscription-ids attribute."));
6580 * Are the subscription IDs valid?
6583 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6585 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6588 * Bad subscription ID...
6591 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6592 ids
->values
[i
].integer
);
6600 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6602 con
, sub
->owner
)) != HTTP_OK
)
6604 send_http_error(con
, status
, sub
->dest
);
6609 * Check the subscription type and update the interval accordingly.
6612 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6615 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6617 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6623 * Tell the client to poll again in N seconds...
6627 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6628 "notify-get-interval", interval
);
6630 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6631 "printer-up-time", time(NULL
));
6634 * Copy the subscription event attributes to the response.
6637 con
->response
->request
.status
.status_code
=
6638 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6640 for (i
= 0; i
< ids
->num_values
; i
++)
6643 * Get the subscription and sequence number...
6646 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6648 if (sequences
&& i
< sequences
->num_values
)
6649 min_seq
= sequences
->values
[i
].integer
;
6654 * If we don't have any new events, nothing to do here...
6657 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6661 * Otherwise copy all of the new events...
6664 if (sub
->first_event_id
> min_seq
)
6667 j
= min_seq
- sub
->first_event_id
;
6669 for (; j
< cupsArrayCount(sub
->events
); j
++)
6671 ippAddSeparator(con
->response
);
6673 copy_attrs(con
->response
,
6674 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6675 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6682 * 'get_ppd()' - Get a named PPD from the local system.
6686 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6687 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6689 http_status_t status
; /* Policy status */
6690 cupsd_printer_t
*dest
; /* Destination */
6691 cups_ptype_t dtype
; /* Destination type */
6694 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6695 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6697 if (!strcmp(uri
->name
, "ppd-name"))
6700 * Return a PPD file from cups-driverd...
6703 char command
[1024], /* cups-driverd command */
6704 options
[1024], /* Options to pass to command */
6705 ppd_name
[1024]; /* ppd-name */
6712 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6714 send_http_error(con
, status
, NULL
);
6719 * Run cups-driverd command with the given options...
6722 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6723 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6724 snprintf(options
, sizeof(options
), "get+%d+%s",
6725 con
->request
->request
.op
.request_id
, ppd_name
);
6727 if (cupsdSendCommand(con
, command
, options
, 0))
6730 * Command started successfully, don't send an IPP response here...
6733 ippDelete(con
->response
);
6734 con
->response
= NULL
;
6739 * Command failed, return "internal error" so the user knows something
6743 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6744 _("cups-driverd failed to execute."));
6747 else if (!strcmp(uri
->name
, "printer-uri") &&
6748 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6750 int i
; /* Looping var */
6751 char filename
[1024]; /* PPD filename */
6758 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6760 send_http_error(con
, status
, dest
);
6765 * See if we need the PPD for a class or remote printer...
6768 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6771 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6773 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6774 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6775 "printer-uri", NULL
, dest
->uri
);
6778 else if (dtype
& CUPS_PRINTER_CLASS
)
6780 for (i
= 0; i
< dest
->num_printers
; i
++)
6781 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6783 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6784 dest
->printers
[i
]->name
);
6786 if (!access(filename
, 0))
6790 if (i
< dest
->num_printers
)
6791 dest
= dest
->printers
[i
];
6794 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6795 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6796 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6802 * Found the printer with the PPD file, now see if there is one...
6805 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6807 send_ipp_status(con
, IPP_NOT_FOUND
,
6808 _("The PPD file \"%s\" could not be opened: %s"),
6809 uri
->values
[0].string
.text
, strerror(errno
));
6813 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6817 con
->response
->request
.status
.status_code
= IPP_OK
;
6820 send_ipp_status(con
, IPP_NOT_FOUND
,
6821 _("The PPD file \"%s\" could not be found."),
6822 uri
->values
[0].string
.text
);
6827 * 'get_ppds()' - Get the list of PPD files on the local system.
6831 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6833 http_status_t status
; /* Policy status */
6834 ipp_attribute_t
*limit
, /* Limit attribute */
6835 *device
, /* ppd-device-id attribute */
6836 *language
, /* ppd-natural-language attribute */
6837 *make
, /* ppd-make attribute */
6838 *model
, /* ppd-make-and-model attribute */
6839 *model_number
, /* ppd-model-number attribute */
6840 *product
, /* ppd-product attribute */
6841 *psversion
, /* ppd-psverion attribute */
6842 *type
, /* ppd-type attribute */
6843 *requested
, /* requested-attributes attribute */
6844 *exclude
, /* exclude-schemes attribute */
6845 *include
; /* include-schemes attribute */
6846 char command
[1024], /* cups-driverd command */
6847 options
[4096], /* Options to pass to command */
6848 device_str
[256],/* Escaped ppd-device-id string */
6850 /* Escaped ppd-natural-language */
6851 make_str
[256], /* Escaped ppd-make string */
6852 model_str
[256], /* Escaped ppd-make-and-model string */
6853 model_number_str
[256],
6854 /* ppd-model-number string */
6856 /* Escaped ppd-product string */
6858 /* Escaped ppd-psversion string */
6859 type_str
[256], /* Escaped ppd-type string */
6861 /* String for requested attributes */
6863 /* String for excluded schemes */
6865 /* String for included schemes */
6868 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
6874 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6876 send_http_error(con
, status
, NULL
);
6881 * Run cups-driverd command with the given options...
6884 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6885 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6886 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6888 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6889 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6891 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6893 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6894 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6895 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6896 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6898 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6900 include
= ippFindAttribute(con
->request
, "include-schemes",
6904 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6906 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6909 url_encode_attr(device
, device_str
, sizeof(device_str
));
6911 device_str
[0] = '\0';
6914 url_encode_attr(language
, language_str
, sizeof(language_str
));
6916 language_str
[0] = '\0';
6919 url_encode_attr(make
, make_str
, sizeof(make_str
));
6924 url_encode_attr(model
, model_str
, sizeof(model_str
));
6926 model_str
[0] = '\0';
6929 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
6930 model_number
->values
[0].integer
);
6932 model_number_str
[0] = '\0';
6935 url_encode_attr(product
, product_str
, sizeof(product_str
));
6937 product_str
[0] = '\0';
6940 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
6942 psversion_str
[0] = '\0';
6945 url_encode_attr(type
, type_str
, sizeof(type_str
));
6950 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6952 exclude_str
[0] = '\0';
6955 url_encode_attr(include
, include_str
, sizeof(include_str
));
6957 include_str
[0] = '\0';
6959 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6960 snprintf(options
, sizeof(options
),
6961 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
6962 con
->request
->request
.op
.request_id
,
6963 limit
? limit
->values
[0].integer
: 0,
6965 device
? "%20" : "", device_str
,
6966 language
? "%20" : "", language_str
,
6967 make
? "%20" : "", make_str
,
6968 model
? "%20" : "", model_str
,
6969 model_number
? "%20" : "", model_number_str
,
6970 product
? "%20" : "", product_str
,
6971 psversion
? "%20" : "", psversion_str
,
6972 type
? "%20" : "", type_str
,
6973 exclude_str
[0] ? "%20" : "", exclude_str
,
6974 include_str
[0] ? "%20" : "", include_str
);
6976 if (cupsdSendCommand(con
, command
, options
, 0))
6979 * Command started successfully, don't send an IPP response here...
6982 ippDelete(con
->response
);
6983 con
->response
= NULL
;
6988 * Command failed, return "internal error" so the user knows something
6992 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6993 _("cups-driverd failed to execute."));
6999 * 'get_printer_attrs()' - Get printer attributes.
7003 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7004 ipp_attribute_t
*uri
) /* I - Printer URI */
7006 http_status_t status
; /* Policy status */
7007 cups_ptype_t dtype
; /* Destination type (printer/class) */
7008 cupsd_printer_t
*printer
; /* Printer/class */
7009 cups_array_t
*ra
; /* Requested attributes array */
7012 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7013 con
->number
, uri
->values
[0].string
.text
);
7016 * Is the destination valid?
7019 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7025 send_ipp_status(con
, IPP_NOT_FOUND
,
7026 _("The printer or class does not exist."));
7034 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7036 send_http_error(con
, status
, printer
);
7041 * Send the attributes...
7044 ra
= create_requested_array(con
->request
);
7046 copy_printer_attrs(con
, printer
, ra
);
7048 cupsArrayDelete(ra
);
7050 con
->response
->request
.status
.status_code
= IPP_OK
;
7055 * 'get_printer_supported()' - Get printer supported values.
7059 get_printer_supported(
7060 cupsd_client_t
*con
, /* I - Client connection */
7061 ipp_attribute_t
*uri
) /* I - Printer URI */
7063 http_status_t status
; /* Policy status */
7064 cups_ptype_t dtype
; /* Destination type (printer/class) */
7065 cupsd_printer_t
*printer
; /* Printer/class */
7068 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7069 con
->number
, uri
->values
[0].string
.text
);
7072 * Is the destination valid?
7075 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7081 send_ipp_status(con
, IPP_NOT_FOUND
,
7082 _("The printer or class does not exist."));
7090 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7092 send_http_error(con
, status
, printer
);
7097 * Return a list of attributes that can be set via Set-Printer-Attributes.
7100 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7102 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7103 "printer-location", 0);
7105 con
->response
->request
.status
.status_code
= IPP_OK
;
7110 * 'get_printers()' - Get a list of printers or classes.
7114 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7115 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7117 http_status_t status
; /* Policy status */
7118 ipp_attribute_t
*attr
; /* Current attribute */
7119 int limit
; /* Max number of printers to return */
7120 int count
; /* Number of printers that match */
7121 cupsd_printer_t
*printer
; /* Current printer pointer */
7122 cups_ptype_t printer_type
, /* printer-type attribute */
7123 printer_mask
; /* printer-type-mask attribute */
7124 char *location
; /* Location string */
7125 const char *username
; /* Current user */
7126 char *first_printer_name
; /* first-printer-name attribute */
7127 cups_array_t
*ra
; /* Requested attributes array */
7128 int local
; /* Local connection? */
7131 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7138 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7140 send_http_error(con
, status
, NULL
);
7145 * Check for printers...
7148 if (!Printers
|| !cupsArrayCount(Printers
))
7150 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7155 * See if they want to limit the number of printers reported...
7158 if ((attr
= ippFindAttribute(con
->request
, "limit",
7159 IPP_TAG_INTEGER
)) != NULL
)
7160 limit
= attr
->values
[0].integer
;
7164 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7165 IPP_TAG_NAME
)) != NULL
)
7166 first_printer_name
= attr
->values
[0].string
.text
;
7168 first_printer_name
= NULL
;
7171 * Support filtering...
7174 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7175 IPP_TAG_ENUM
)) != NULL
)
7176 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7178 printer_type
= (cups_ptype_t
)0;
7180 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7181 IPP_TAG_ENUM
)) != NULL
)
7182 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7184 printer_mask
= (cups_ptype_t
)0;
7186 local
= httpAddrLocalhost(&(con
->clientaddr
));
7188 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7189 IPP_TAG_TEXT
)) != NULL
)
7190 location
= attr
->values
[0].string
.text
;
7194 if (con
->username
[0])
7195 username
= con
->username
;
7196 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7197 IPP_TAG_NAME
)) != NULL
)
7198 username
= attr
->values
[0].string
.text
;
7202 ra
= create_requested_array(con
->request
);
7205 * OK, build a list of printers for this printer...
7208 if (first_printer_name
)
7210 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7211 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7214 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7217 count
< limit
&& printer
;
7218 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7220 if (!local
&& !printer
->shared
)
7223 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7224 (printer
->type
& printer_mask
) == printer_type
&&
7226 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7229 * If a username is specified, see if it is allowed or denied
7233 if (cupsArrayCount(printer
->users
) && username
&&
7234 !user_allowed(printer
, username
))
7238 * Add the group separator as needed...
7242 ippAddSeparator(con
->response
);
7247 * Send the attributes...
7250 copy_printer_attrs(con
, printer
, ra
);
7254 cupsArrayDelete(ra
);
7256 con
->response
->request
.status
.status_code
= IPP_OK
;
7261 * 'get_subscription_attrs()' - Get subscription attributes.
7265 get_subscription_attrs(
7266 cupsd_client_t
*con
, /* I - Client connection */
7267 int sub_id
) /* I - Subscription ID */
7269 http_status_t status
; /* Policy status */
7270 cupsd_subscription_t
*sub
; /* Subscription */
7271 cupsd_policy_t
*policy
; /* Current security policy */
7272 cups_array_t
*ra
, /* Requested attributes array */
7273 *exclude
; /* Private attributes array */
7276 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7277 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7278 con
, con
->number
, sub_id
);
7281 * Is the subscription ID valid?
7284 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7287 * Bad subscription ID...
7290 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7300 policy
= sub
->dest
->op_policy_ptr
;
7302 policy
= DefaultPolicyPtr
;
7304 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7306 send_http_error(con
, status
, sub
->dest
);
7310 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7313 * Copy the subscription attributes to the response using the
7314 * requested-attributes attribute that may be provided by the client.
7317 ra
= create_requested_array(con
->request
);
7319 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7321 cupsArrayDelete(ra
);
7323 con
->response
->request
.status
.status_code
= IPP_OK
;
7328 * 'get_subscriptions()' - Get subscriptions.
7332 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7333 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7335 http_status_t status
; /* Policy status */
7336 int count
; /* Number of subscriptions */
7337 int limit
; /* Limit */
7338 cupsd_subscription_t
*sub
; /* Subscription */
7339 cups_array_t
*ra
; /* Requested attributes array */
7340 ipp_attribute_t
*attr
; /* Attribute */
7341 cups_ptype_t dtype
; /* Destination type (printer/class) */
7342 char scheme
[HTTP_MAX_URI
],
7343 /* Scheme portion of URI */
7344 username
[HTTP_MAX_URI
],
7345 /* Username portion of URI */
7347 /* Host portion of URI */
7348 resource
[HTTP_MAX_URI
];
7349 /* Resource portion of URI */
7350 int port
; /* Port portion of URI */
7351 cupsd_job_t
*job
; /* Job pointer */
7352 cupsd_printer_t
*printer
; /* Printer */
7353 cupsd_policy_t
*policy
; /* Policy */
7354 cups_array_t
*exclude
; /* Private attributes array */
7357 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7358 "get_subscriptions(con=%p[%d], uri=%s)",
7359 con
, con
->number
, uri
->values
[0].string
.text
);
7362 * Is the destination valid?
7365 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7366 sizeof(scheme
), username
, sizeof(username
), host
,
7367 sizeof(host
), &port
, resource
, sizeof(resource
));
7369 if (!strcmp(resource
, "/") ||
7370 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7371 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7372 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7377 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7380 job
= cupsdFindJob(atoi(resource
+ 6));
7384 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7385 atoi(resource
+ 6));
7389 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7395 send_ipp_status(con
, IPP_NOT_FOUND
,
7396 _("The printer or class does not exist."));
7399 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7400 IPP_TAG_INTEGER
)) != NULL
)
7402 job
= cupsdFindJob(attr
->values
[0].integer
);
7406 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7407 attr
->values
[0].integer
);
7419 policy
= printer
->op_policy_ptr
;
7421 policy
= DefaultPolicyPtr
;
7423 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7425 send_http_error(con
, status
, printer
);
7430 * Copy the subscription attributes to the response using the
7431 * requested-attributes attribute that may be provided by the client.
7434 ra
= create_requested_array(con
->request
);
7436 if ((attr
= ippFindAttribute(con
->request
, "limit",
7437 IPP_TAG_INTEGER
)) != NULL
)
7438 limit
= attr
->values
[0].integer
;
7443 * See if we only want to see subscriptions for a specific user...
7446 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7447 IPP_TAG_BOOLEAN
)) != NULL
&&
7448 attr
->values
[0].boolean
)
7449 strlcpy(username
, get_username(con
), sizeof(username
));
7453 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7455 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7456 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7457 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7459 ippAddSeparator(con
->response
);
7461 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7462 policy
, con
, sub
->dest
,
7465 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7468 if (limit
&& count
>= limit
)
7472 cupsArrayDelete(ra
);
7475 con
->response
->request
.status
.status_code
= IPP_OK
;
7477 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7482 * 'get_username()' - Get the username associated with a request.
7485 static const char * /* O - Username */
7486 get_username(cupsd_client_t
*con
) /* I - Connection */
7488 ipp_attribute_t
*attr
; /* Attribute */
7491 if (con
->username
[0])
7492 return (con
->username
);
7493 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7494 IPP_TAG_NAME
)) != NULL
)
7495 return (attr
->values
[0].string
.text
);
7497 return ("anonymous");
7502 * 'hold_job()' - Hold a print job.
7506 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7507 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7509 ipp_attribute_t
*attr
; /* Current job-hold-until */
7510 const char *when
; /* New value */
7511 int jobid
; /* Job ID */
7512 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7513 username
[HTTP_MAX_URI
], /* Username portion of URI */
7514 host
[HTTP_MAX_URI
], /* Host portion of URI */
7515 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7516 int port
; /* Port portion of URI */
7517 cupsd_job_t
*job
; /* Job information */
7520 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7521 uri
->values
[0].string
.text
);
7524 * See if we have a job URI or a printer URI...
7527 if (!strcmp(uri
->name
, "printer-uri"))
7530 * Got a printer URI; see if we also have a job-id attribute...
7533 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7534 IPP_TAG_INTEGER
)) == NULL
)
7536 send_ipp_status(con
, IPP_BAD_REQUEST
,
7537 _("Got a printer-uri attribute but no job-id."));
7541 jobid
= attr
->values
[0].integer
;
7546 * Got a job URI; parse it to get the job ID...
7549 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7550 sizeof(scheme
), username
, sizeof(username
), host
,
7551 sizeof(host
), &port
, resource
, sizeof(resource
));
7553 if (strncmp(resource
, "/jobs/", 6))
7559 send_ipp_status(con
, IPP_BAD_REQUEST
,
7560 _("Bad job-uri \"%s\"."),
7561 uri
->values
[0].string
.text
);
7565 jobid
= atoi(resource
+ 6);
7569 * See if the job exists...
7572 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7575 * Nope - return a "not found" error...
7578 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7583 * See if the job is owned by the requesting user...
7586 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7588 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7589 cupsdFindDest(job
->dest
));
7594 * See if the job is in a state that allows holding...
7597 if (job
->state_value
> IPP_JOB_STOPPED
)
7600 * Return a "not-possible" error...
7603 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7604 _("Job #%d is finished and cannot be altered."),
7610 * Hold the job and return...
7613 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7614 IPP_TAG_KEYWORD
)) == NULL
)
7615 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7619 when
= attr
->values
[0].string
.text
;
7621 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7622 "Job job-hold-until value changed by user.");
7625 when
= "indefinite";
7627 cupsdSetJobHoldUntil(job
, when
, 1);
7628 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7631 con
->response
->request
.status
.status_code
= IPP_OK
;
7636 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7640 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7641 ipp_attribute_t
*uri
) /* I - Printer URI */
7643 http_status_t status
; /* Policy status */
7644 cups_ptype_t dtype
; /* Destination type (printer/class) */
7645 cupsd_printer_t
*printer
; /* Printer data */
7648 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7649 con
->number
, uri
->values
[0].string
.text
);
7652 * Is the destination valid?
7655 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7661 send_ipp_status(con
, IPP_NOT_FOUND
,
7662 _("The printer or class does not exist."));
7670 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7672 send_http_error(con
, status
, printer
);
7677 * Hold pending/new jobs sent to the printer...
7680 printer
->holding_new_jobs
= 1;
7682 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7684 if (dtype
& CUPS_PRINTER_CLASS
)
7685 cupsdLogMessage(CUPSD_LOG_INFO
,
7686 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7687 printer
->name
, get_username(con
));
7689 cupsdLogMessage(CUPSD_LOG_INFO
,
7690 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7691 printer
->name
, get_username(con
));
7694 * Everything was ok, so return OK status...
7697 con
->response
->request
.status
.status_code
= IPP_OK
;
7702 * 'move_job()' - Move a job to a new destination.
7706 move_job(cupsd_client_t
*con
, /* I - Client connection */
7707 ipp_attribute_t
*uri
) /* I - Job URI */
7709 http_status_t status
; /* Policy status */
7710 ipp_attribute_t
*attr
; /* Current attribute */
7711 int jobid
; /* Job ID */
7712 cupsd_job_t
*job
; /* Current job */
7713 const char *src
; /* Source printer/class */
7714 cups_ptype_t stype
, /* Source type (printer or class) */
7715 dtype
; /* Destination type (printer/class) */
7716 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7717 username
[HTTP_MAX_URI
], /* Username portion of URI */
7718 host
[HTTP_MAX_URI
], /* Host portion of URI */
7719 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7720 int port
; /* Port portion of URI */
7721 cupsd_printer_t
*sprinter
, /* Source printer */
7722 *dprinter
; /* Destination printer */
7725 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
7726 uri
->values
[0].string
.text
);
7729 * Get the new printer or class...
7732 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7733 IPP_TAG_URI
)) == NULL
)
7736 * Need job-printer-uri...
7739 send_ipp_status(con
, IPP_BAD_REQUEST
,
7740 _("job-printer-uri attribute missing."));
7744 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7750 send_ipp_status(con
, IPP_NOT_FOUND
,
7751 _("The printer or class does not exist."));
7756 * See if we have a job URI or a printer URI...
7759 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7760 sizeof(scheme
), username
, sizeof(username
), host
,
7761 sizeof(host
), &port
, resource
, sizeof(resource
));
7763 if (!strcmp(uri
->name
, "printer-uri"))
7766 * Got a printer URI; see if we also have a job-id attribute...
7769 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7770 IPP_TAG_INTEGER
)) == NULL
)
7776 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7777 &sprinter
)) == NULL
)
7783 send_ipp_status(con
, IPP_NOT_FOUND
,
7784 _("The printer or class does not exist."));
7793 * Otherwise, just move a single job...
7796 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7799 * Nope - return a "not found" error...
7802 send_ipp_status(con
, IPP_NOT_FOUND
,
7803 _("Job #%d does not exist."), attr
->values
[0].integer
);
7809 * Job found, initialize source pointers...
7820 * Got a job URI; parse it to get the job ID...
7823 if (strncmp(resource
, "/jobs/", 6))
7829 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7830 uri
->values
[0].string
.text
);
7835 * See if the job exists...
7838 jobid
= atoi(resource
+ 6);
7840 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7843 * Nope - return a "not found" error...
7846 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7852 * Job found, initialize source pointers...
7861 * Check the policy of the destination printer...
7864 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7865 job
? job
->username
: NULL
)) != HTTP_OK
)
7867 send_http_error(con
, status
, dprinter
);
7872 * Now move the job or jobs...
7878 * See if the job has been completed...
7881 if (job
->state_value
> IPP_JOB_STOPPED
)
7884 * Return a "not-possible" error...
7887 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7888 _("Job #%d is finished and cannot be altered."),
7894 * See if the job is owned by the requesting user...
7897 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7899 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7900 cupsdFindDest(job
->dest
));
7905 * Move the job to a different printer or class...
7908 cupsdMoveJob(job
, dprinter
);
7913 * Got the source printer, now look through the jobs...
7916 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7918 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7921 * See if the job is pointing at the source printer or has not been
7925 if (_cups_strcasecmp(job
->dest
, src
) ||
7926 job
->state_value
> IPP_JOB_STOPPED
)
7930 * See if the job can be moved by the requesting user...
7933 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7937 * Move the job to a different printer or class...
7940 cupsdMoveJob(job
, dprinter
);
7945 * Start jobs if possible...
7951 * Return with "everything is OK" status...
7954 con
->response
->request
.status
.status_code
= IPP_OK
;
7959 * 'ppd_parse_line()' - Parse a PPD default line.
7962 static int /* O - 0 on success, -1 on failure */
7963 ppd_parse_line(const char *line
, /* I - Line */
7964 char *option
, /* O - Option name */
7965 int olen
, /* I - Size of option name */
7966 char *choice
, /* O - Choice name */
7967 int clen
) /* I - Size of choice name */
7970 * Verify this is a default option line...
7973 if (strncmp(line
, "*Default", 8))
7977 * Read the option name...
7980 for (line
+= 8, olen
--;
7981 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7992 * Skip everything else up to the colon (:)...
7995 while (*line
&& *line
!= ':')
8004 * Now grab the option choice, skipping leading whitespace...
8007 while (isspace(*line
& 255))
8011 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8022 * Return with no errors...
8030 * 'print_job()' - Print a file to a printer or class.
8034 print_job(cupsd_client_t
*con
, /* I - Client connection */
8035 ipp_attribute_t
*uri
) /* I - Printer URI */
8037 ipp_attribute_t
*attr
; /* Current attribute */
8038 ipp_attribute_t
*format
; /* Document-format attribute */
8039 const char *default_format
; /* document-format-default value */
8040 cupsd_job_t
*job
; /* New job */
8041 char filename
[1024]; /* Job filename */
8042 mime_type_t
*filetype
; /* Type of file */
8043 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8044 type
[MIME_MAX_TYPE
], /* Subtype of file */
8045 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8046 /* Textual name of mime type */
8047 cupsd_printer_t
*printer
; /* Printer data */
8048 struct stat fileinfo
; /* File information */
8049 int kbytes
; /* Size of file */
8050 int compression
; /* Document compression */
8053 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8054 uri
->values
[0].string
.text
);
8057 * Validate print file attributes, for now just document-format and
8058 * compression (CUPS only supports "none" and "gzip")...
8061 compression
= CUPS_FILE_NONE
;
8063 if ((attr
= ippFindAttribute(con
->request
, "compression",
8064 IPP_TAG_KEYWORD
)) != NULL
)
8066 if (strcmp(attr
->values
[0].string
.text
, "none")
8068 && strcmp(attr
->values
[0].string
.text
, "gzip")
8069 #endif /* HAVE_LIBZ */
8072 send_ipp_status(con
, IPP_ATTRIBUTES
,
8073 _("Unsupported compression \"%s\"."),
8074 attr
->values
[0].string
.text
);
8075 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8076 "compression", NULL
, attr
->values
[0].string
.text
);
8081 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8082 compression
= CUPS_FILE_GZIP
;
8083 #endif /* HAVE_LIBZ */
8087 * Do we have a file to print?
8092 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8097 * Is the destination valid?
8100 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8106 send_ipp_status(con
, IPP_NOT_FOUND
,
8107 _("The printer or class does not exist."));
8112 * Is it a format we support?
8115 if ((format
= ippFindAttribute(con
->request
, "document-format",
8116 IPP_TAG_MIMETYPE
)) != NULL
)
8119 * Grab format from client...
8122 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8125 send_ipp_status(con
, IPP_BAD_REQUEST
,
8126 _("Bad document-format \"%s\"."),
8127 format
->values
[0].string
.text
);
8131 else if ((default_format
= cupsGetOption("document-format",
8132 printer
->num_options
,
8133 printer
->options
)) != NULL
)
8136 * Use default document format...
8139 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8141 send_ipp_status(con
, IPP_BAD_REQUEST
,
8142 _("Bad document-format \"%s\"."),
8153 strlcpy(super
, "application", sizeof(super
));
8154 strlcpy(type
, "octet-stream", sizeof(type
));
8157 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8160 * Auto-type the file...
8163 ipp_attribute_t
*doc_name
; /* document-name attribute */
8166 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8168 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8169 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8170 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8174 filetype
= mimeType(MimeDatabase
, super
, type
);
8176 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8177 filetype
->super
, filetype
->type
);
8180 filetype
= mimeType(MimeDatabase
, super
, type
);
8184 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8187 * Replace the document-format attribute value with the auto-typed or
8191 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8196 _cupsStrFree(format
->values
[0].string
.text
);
8198 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8201 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8202 "document-format", NULL
, mimetype
);
8206 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8207 _("Unsupported document-format \"%s\"."),
8208 format
? format
->values
[0].string
.text
:
8209 "application/octet-stream");
8210 cupsdLogMessage(CUPSD_LOG_INFO
,
8211 "Hint: Do you have the raw file printing rules enabled?");
8214 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8215 "document-format", NULL
, format
->values
[0].string
.text
);
8221 * Read any embedded job ticket info from PS files...
8224 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8225 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8226 !_cups_strcasecmp(filetype
->type
, "pdf")))
8227 read_job_ticket(con
);
8230 * Create the job object...
8233 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8237 * Update quota data...
8240 if (stat(con
->filename
, &fileinfo
))
8243 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8245 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8247 job
->koctets
+= kbytes
;
8249 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8250 attr
->values
[0].integer
+= kbytes
;
8253 * Add the job file...
8256 if (add_file(con
, job
, filetype
, compression
))
8259 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8261 rename(con
->filename
, filename
);
8262 cupsdClearString(&con
->filename
);
8265 * See if we need to add the ending sheet...
8268 if (cupsdTimeoutJob(job
))
8272 * Log and save the job...
8275 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8276 "File of type %s/%s queued by \"%s\".",
8277 filetype
->super
, filetype
->type
, job
->username
);
8278 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8279 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8280 job
->dest
, job
->username
);
8283 * Start the job if possible...
8291 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8293 * This function only gets called when printing a single PDF or PostScript
8294 * file using the Print-Job operation. It doesn't work for Create-Job +
8295 * Send-File, since the job attributes need to be set at job creation
8296 * time for banners to work. The embedded job ticket stuff is here
8297 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8298 * options and IPP attributes which otherwise would be lost.
8300 * The format of a job ticket is simple:
8302 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8304 * %cupsJobTicket: attr1=value1
8305 * %cupsJobTicket: attr2=value2
8307 * %cupsJobTicket: attrN=valueN
8309 * Job ticket lines must appear immediately after the first line that
8310 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8311 * stops looking for job ticket info when it finds a line that does not begin
8312 * with "%cupsJobTicket:".
8314 * The maximum length of a job ticket line, including the prefix, is
8315 * 255 characters to conform with the Adobe DSC.
8317 * Read-only attributes are rejected with a notice to the error log in
8318 * case a malicious user tries anything. Since the job ticket is read
8319 * prior to attribute validation in print_job(), job ticket attributes
8320 * will go through the same validation as IPP attributes...
8324 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8326 cups_file_t
*fp
; /* File to read from */
8327 char line
[256]; /* Line data */
8328 int num_options
; /* Number of options */
8329 cups_option_t
*options
; /* Options */
8330 ipp_t
*ticket
; /* New attributes */
8331 ipp_attribute_t
*attr
, /* Current attribute */
8332 *attr2
, /* Job attribute */
8333 *prev2
; /* Previous job attribute */
8337 * First open the print file...
8340 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8342 cupsdLogMessage(CUPSD_LOG_ERROR
,
8343 "Unable to open print file for job ticket - %s",
8349 * Skip the first line...
8352 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8354 cupsdLogMessage(CUPSD_LOG_ERROR
,
8355 "Unable to read from print file for job ticket - %s",
8361 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8364 * Not a DSC-compliant file, so no job ticket info will be available...
8372 * Read job ticket info from the file...
8378 while (cupsFileGets(fp
, line
, sizeof(line
)))
8381 * Stop at the first non-ticket line...
8384 if (strncmp(line
, "%cupsJobTicket:", 15))
8388 * Add the options to the option array...
8391 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8395 * Done with the file; see if we have any options...
8400 if (num_options
== 0)
8404 * OK, convert the options to an attribute list, and apply them to
8409 cupsEncodeOptions(ticket
, num_options
, options
);
8412 * See what the user wants to change.
8415 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8417 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8420 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8421 !strcmp(attr
->name
, "job-originating-user-name") ||
8422 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8423 !strcmp(attr
->name
, "job-k-octets") ||
8424 !strcmp(attr
->name
, "job-id") ||
8425 !strncmp(attr
->name
, "job-state", 9) ||
8426 !strncmp(attr
->name
, "time-at-", 8))
8427 continue; /* Read-only attrs */
8429 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8430 IPP_TAG_ZERO
)) != NULL
)
8433 * Some other value; first free the old value...
8436 if (con
->request
->attrs
== attr2
)
8438 con
->request
->attrs
= attr2
->next
;
8443 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8444 if (prev2
->next
== attr2
)
8446 prev2
->next
= attr2
->next
;
8451 if (con
->request
->last
== attr2
)
8452 con
->request
->last
= prev2
;
8454 ippDeleteAttribute(NULL
, attr2
);
8458 * Add new option by copying it...
8461 ippCopyAttribute(con
->request
, attr
, 0);
8465 * Then free the attribute list and option array...
8469 cupsFreeOptions(num_options
, options
);
8474 * 'reject_jobs()' - Reject print jobs to a printer.
8478 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8479 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8481 http_status_t status
; /* Policy status */
8482 cups_ptype_t dtype
; /* Destination type (printer/class) */
8483 cupsd_printer_t
*printer
; /* Printer data */
8484 ipp_attribute_t
*attr
; /* printer-state-message text */
8487 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8488 con
->number
, uri
->values
[0].string
.text
);
8491 * Is the destination valid?
8494 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8500 send_ipp_status(con
, IPP_NOT_FOUND
,
8501 _("The printer or class does not exist."));
8509 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8511 send_http_error(con
, status
, printer
);
8516 * Reject jobs sent to the printer...
8519 printer
->accepting
= 0;
8521 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8522 IPP_TAG_TEXT
)) == NULL
)
8523 strlcpy(printer
->state_message
, "Rejecting Jobs",
8524 sizeof(printer
->state_message
));
8526 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8527 sizeof(printer
->state_message
));
8529 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8530 "No longer accepting jobs.");
8532 if (dtype
& CUPS_PRINTER_CLASS
)
8534 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8536 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8537 printer
->name
, get_username(con
));
8541 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8543 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8544 printer
->name
, get_username(con
));
8548 * Everything was ok, so return OK status...
8551 con
->response
->request
.status
.status_code
= IPP_OK
;
8556 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8560 release_held_new_jobs(
8561 cupsd_client_t
*con
, /* I - Connection */
8562 ipp_attribute_t
*uri
) /* I - Printer URI */
8564 http_status_t status
; /* Policy status */
8565 cups_ptype_t dtype
; /* Destination type (printer/class) */
8566 cupsd_printer_t
*printer
; /* Printer data */
8569 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8570 con
->number
, uri
->values
[0].string
.text
);
8573 * Is the destination valid?
8576 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8582 send_ipp_status(con
, IPP_NOT_FOUND
,
8583 _("The printer or class does not exist."));
8591 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8593 send_http_error(con
, status
, printer
);
8598 * Hold pending/new jobs sent to the printer...
8601 printer
->holding_new_jobs
= 0;
8603 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8605 if (dtype
& CUPS_PRINTER_CLASS
)
8606 cupsdLogMessage(CUPSD_LOG_INFO
,
8607 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8608 printer
->name
, get_username(con
));
8610 cupsdLogMessage(CUPSD_LOG_INFO
,
8611 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8612 printer
->name
, get_username(con
));
8615 * Everything was ok, so return OK status...
8618 con
->response
->request
.status
.status_code
= IPP_OK
;
8623 * 'release_job()' - Release a held print job.
8627 release_job(cupsd_client_t
*con
, /* I - Client connection */
8628 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8630 ipp_attribute_t
*attr
; /* Current attribute */
8631 int jobid
; /* Job ID */
8632 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8633 username
[HTTP_MAX_URI
], /* Username portion of URI */
8634 host
[HTTP_MAX_URI
], /* Host portion of URI */
8635 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8636 int port
; /* Port portion of URI */
8637 cupsd_job_t
*job
; /* Job information */
8640 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8641 con
->number
, uri
->values
[0].string
.text
);
8644 * See if we have a job URI or a printer URI...
8647 if (!strcmp(uri
->name
, "printer-uri"))
8650 * Got a printer URI; see if we also have a job-id attribute...
8653 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8654 IPP_TAG_INTEGER
)) == NULL
)
8656 send_ipp_status(con
, IPP_BAD_REQUEST
,
8657 _("Got a printer-uri attribute but no job-id."));
8661 jobid
= attr
->values
[0].integer
;
8666 * Got a job URI; parse it to get the job ID...
8669 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8670 sizeof(scheme
), username
, sizeof(username
), host
,
8671 sizeof(host
), &port
, resource
, sizeof(resource
));
8673 if (strncmp(resource
, "/jobs/", 6))
8679 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8680 uri
->values
[0].string
.text
);
8684 jobid
= atoi(resource
+ 6);
8688 * See if the job exists...
8691 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8694 * Nope - return a "not found" error...
8697 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8702 * See if job is "held"...
8705 if (job
->state_value
!= IPP_JOB_HELD
)
8708 * Nope - return a "not possible" error...
8711 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8716 * See if the job is owned by the requesting user...
8719 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8721 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8722 cupsdFindDest(job
->dest
));
8727 * Reset the job-hold-until value to "no-hold"...
8730 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8731 IPP_TAG_KEYWORD
)) == NULL
)
8732 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8736 _cupsStrFree(attr
->values
[0].string
.text
);
8738 attr
->value_tag
= IPP_TAG_KEYWORD
;
8739 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8741 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8742 "Job job-hold-until value changed by user.");
8743 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8747 * Release the job and return...
8750 cupsdReleaseJob(job
);
8752 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8753 "Job released by user.");
8755 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8757 con
->response
->request
.status
.status_code
= IPP_OK
;
8764 * 'renew_subscription()' - Renew an existing subscription...
8769 cupsd_client_t
*con
, /* I - Client connection */
8770 int sub_id
) /* I - Subscription ID */
8772 http_status_t status
; /* Policy status */
8773 cupsd_subscription_t
*sub
; /* Subscription */
8774 ipp_attribute_t
*lease
; /* notify-lease-duration */
8777 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8778 "renew_subscription(con=%p[%d], sub_id=%d)",
8779 con
, con
->number
, sub_id
);
8782 * Is the subscription ID valid?
8785 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8788 * Bad subscription ID...
8791 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8799 * Job subscriptions cannot be renewed...
8802 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8803 _("Job subscriptions cannot be renewed."));
8811 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8813 con
, sub
->owner
)) != HTTP_OK
)
8815 send_http_error(con
, status
, sub
->dest
);
8820 * Renew the subscription...
8823 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8826 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8828 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8830 cupsdLogMessage(CUPSD_LOG_INFO
,
8831 "renew_subscription: Limiting notify-lease-duration to "
8834 sub
->lease
= MaxLeaseDuration
;
8837 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8839 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8841 con
->response
->request
.status
.status_code
= IPP_OK
;
8843 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8844 "notify-lease-duration", sub
->lease
);
8849 * 'restart_job()' - Restart an old print job.
8853 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8854 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8856 ipp_attribute_t
*attr
; /* Current attribute */
8857 int jobid
; /* Job ID */
8858 cupsd_job_t
*job
; /* Job information */
8859 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8860 username
[HTTP_MAX_URI
], /* Username portion of URI */
8861 host
[HTTP_MAX_URI
], /* Host portion of URI */
8862 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8863 int port
; /* Port portion of URI */
8866 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8867 con
->number
, uri
->values
[0].string
.text
);
8870 * See if we have a job URI or a printer URI...
8873 if (!strcmp(uri
->name
, "printer-uri"))
8876 * Got a printer URI; see if we also have a job-id attribute...
8879 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8880 IPP_TAG_INTEGER
)) == NULL
)
8882 send_ipp_status(con
, IPP_BAD_REQUEST
,
8883 _("Got a printer-uri attribute but no job-id."));
8887 jobid
= attr
->values
[0].integer
;
8892 * Got a job URI; parse it to get the job ID...
8895 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8896 sizeof(scheme
), username
, sizeof(username
), host
,
8897 sizeof(host
), &port
, resource
, sizeof(resource
));
8899 if (strncmp(resource
, "/jobs/", 6))
8905 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8906 uri
->values
[0].string
.text
);
8910 jobid
= atoi(resource
+ 6);
8914 * See if the job exists...
8917 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8920 * Nope - return a "not found" error...
8923 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8928 * See if job is in any of the "completed" states...
8931 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8934 * Nope - return a "not possible" error...
8937 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
8943 * See if we have retained the job files...
8948 if (!job
->attrs
|| job
->num_files
== 0)
8951 * Nope - return a "not possible" error...
8954 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8955 _("Job #%d cannot be restarted - no files."), jobid
);
8960 * See if the job is owned by the requesting user...
8963 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8965 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8966 cupsdFindDest(job
->dest
));
8971 * See if the job-hold-until attribute is specified...
8974 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8975 IPP_TAG_KEYWORD
)) == NULL
)
8976 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8978 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
8981 * Return the job to a held state...
8984 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
8985 "Restarted by \"%s\" with job-hold-until=%s.",
8986 username
, attr
->values
[0].string
.text
);
8987 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
8989 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
8990 NULL
, job
, "Job restarted by user with job-hold-until=%s",
8991 attr
->values
[0].string
.text
);
8996 * Restart the job...
8999 cupsdRestartJob(job
);
9003 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9005 con
->response
->request
.status
.status_code
= IPP_OK
;
9010 * 'save_auth_info()' - Save authentication information for a job.
9015 cupsd_client_t
*con
, /* I - Client connection */
9016 cupsd_job_t
*job
, /* I - Job */
9017 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9019 int i
; /* Looping var */
9020 char filename
[1024]; /* Job authentication filename */
9021 cups_file_t
*fp
; /* Job authentication file */
9022 char line
[65536]; /* Line for file */
9023 cupsd_printer_t
*dest
; /* Destination printer/class */
9027 * This function saves the in-memory authentication information for
9028 * a job so that it can be used to authenticate with a remote host.
9029 * The information is stored in a file that is readable only by the
9030 * root user. The fields are Base-64 encoded, each on a separate line,
9031 * followed by random number (up to 1024) of newlines to limit the
9032 * amount of information that is exposed.
9034 * Because of the potential for exposing of authentication information,
9035 * this functionality is only enabled when running cupsd as root.
9037 * This caching only works for the Basic and BasicDigest authentication
9038 * types. Digest authentication cannot be cached this way, and in
9039 * the future Kerberos authentication may make all of this obsolete.
9041 * Authentication information is saved whenever an authenticated
9042 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9045 * This information is deleted after a job is completed or canceled,
9046 * so reprints may require subsequent re-authentication.
9052 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9056 * Create the authentication file and change permissions...
9059 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9060 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9062 cupsdLogMessage(CUPSD_LOG_ERROR
,
9063 "Unable to save authentication info to \"%s\" - %s",
9064 filename
, strerror(errno
));
9068 fchown(cupsFileNumber(fp
), 0, 0);
9069 fchmod(cupsFileNumber(fp
), 0400);
9071 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9074 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9076 cupsdClearString(job
->auth_env
+ i
);
9078 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9081 * Write 1 to 3 auth values...
9085 i
< auth_info
->num_values
&&
9086 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9089 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9091 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9092 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9095 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9096 auth_info
->values
[i
].string
.text
);
9098 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9099 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9100 auth_info
->values
[i
].string
.text
);
9101 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9102 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9103 auth_info
->values
[i
].string
.text
);
9104 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9105 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9106 auth_info
->values
[i
].string
.text
);
9107 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9108 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9109 auth_info
->values
[i
].string
.text
);
9114 else if (auth_info
&& auth_info
->num_values
== 2 &&
9115 dest
->num_auth_info_required
== 1 &&
9116 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9119 * Allow fallback to username+password for Kerberized queues...
9122 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9123 cupsFilePutConf(fp
, "username", line
);
9125 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9126 auth_info
->values
[0].string
.text
);
9128 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9129 cupsFilePutConf(fp
, "password", line
);
9131 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9132 auth_info
->values
[1].string
.text
);
9134 else if (con
->username
[0])
9137 * Write the authenticated username...
9140 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9141 cupsFilePutConf(fp
, "username", line
);
9143 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9146 * Write the authenticated password...
9149 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9150 cupsFilePutConf(fp
, "password", line
);
9152 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9156 if (con
->gss_uid
> 0)
9158 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9159 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9161 #endif /* HAVE_GSSAPI */
9164 * Write a random number of newlines to the end of the file...
9167 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9168 cupsFilePutChar(fp
, '\n');
9171 * Close the file and return...
9179 * 'send_document()' - Send a file to a printer or class.
9183 send_document(cupsd_client_t
*con
, /* I - Client connection */
9184 ipp_attribute_t
*uri
) /* I - Printer URI */
9186 ipp_attribute_t
*attr
; /* Current attribute */
9187 ipp_attribute_t
*format
; /* Request's document-format attribute */
9188 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9189 const char *default_format
;/* document-format-default value */
9190 int jobid
; /* Job ID number */
9191 cupsd_job_t
*job
; /* Current job */
9192 char job_uri
[HTTP_MAX_URI
],
9194 scheme
[HTTP_MAX_URI
],
9195 /* Method portion of URI */
9196 username
[HTTP_MAX_URI
],
9197 /* Username portion of URI */
9199 /* Host portion of URI */
9200 resource
[HTTP_MAX_URI
];
9201 /* Resource portion of URI */
9202 int port
; /* Port portion of URI */
9203 mime_type_t
*filetype
; /* Type of file */
9204 char super
[MIME_MAX_SUPER
],
9205 /* Supertype of file */
9206 type
[MIME_MAX_TYPE
],
9207 /* Subtype of file */
9208 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9209 /* Textual name of mime type */
9210 char filename
[1024]; /* Job filename */
9211 cupsd_printer_t
*printer
; /* Current printer */
9212 struct stat fileinfo
; /* File information */
9213 int kbytes
; /* Size of file */
9214 int compression
; /* Type of compression */
9215 int start_job
; /* Start the job? */
9218 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9219 con
->number
, uri
->values
[0].string
.text
);
9222 * See if we have a job URI or a printer URI...
9225 if (!strcmp(uri
->name
, "printer-uri"))
9228 * Got a printer URI; see if we also have a job-id attribute...
9231 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9232 IPP_TAG_INTEGER
)) == NULL
)
9234 send_ipp_status(con
, IPP_BAD_REQUEST
,
9235 _("Got a printer-uri attribute but no job-id."));
9239 jobid
= attr
->values
[0].integer
;
9244 * Got a job URI; parse it to get the job ID...
9247 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9248 sizeof(scheme
), username
, sizeof(username
), host
,
9249 sizeof(host
), &port
, resource
, sizeof(resource
));
9251 if (strncmp(resource
, "/jobs/", 6))
9257 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9258 uri
->values
[0].string
.text
);
9262 jobid
= atoi(resource
+ 6);
9266 * See if the job exists...
9269 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9272 * Nope - return a "not found" error...
9275 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9279 printer
= cupsdFindDest(job
->dest
);
9282 * See if the job is owned by the requesting user...
9285 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9287 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9288 cupsdFindDest(job
->dest
));
9293 * OK, see if the client is sending the document compressed - CUPS
9294 * only supports "none" and "gzip".
9297 compression
= CUPS_FILE_NONE
;
9299 if ((attr
= ippFindAttribute(con
->request
, "compression",
9300 IPP_TAG_KEYWORD
)) != NULL
)
9302 if (strcmp(attr
->values
[0].string
.text
, "none")
9304 && strcmp(attr
->values
[0].string
.text
, "gzip")
9305 #endif /* HAVE_LIBZ */
9308 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9309 attr
->values
[0].string
.text
);
9310 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9311 "compression", NULL
, attr
->values
[0].string
.text
);
9316 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9317 compression
= CUPS_FILE_GZIP
;
9318 #endif /* HAVE_LIBZ */
9322 * Do we have a file to print?
9325 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9326 IPP_TAG_BOOLEAN
)) == NULL
)
9328 send_ipp_status(con
, IPP_BAD_REQUEST
,
9329 _("Missing last-document attribute in request."));
9336 * Check for an empty request with "last-document" set to true, which is
9337 * used to close an "open" job by RFC 2911, section 3.3.2.
9340 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9343 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9348 * Is it a format we support?
9351 if ((format
= ippFindAttribute(con
->request
, "document-format",
9352 IPP_TAG_MIMETYPE
)) != NULL
)
9355 * Grab format from client...
9358 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9361 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9362 format
->values
[0].string
.text
);
9366 else if ((default_format
= cupsGetOption("document-format",
9367 printer
->num_options
,
9368 printer
->options
)) != NULL
)
9371 * Use default document format...
9374 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9376 send_ipp_status(con
, IPP_BAD_REQUEST
,
9377 _("Bad document-format-default \"%s\"."), default_format
);
9384 * No document format attribute? Auto-type it!
9387 strlcpy(super
, "application", sizeof(super
));
9388 strlcpy(type
, "octet-stream", sizeof(type
));
9391 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9394 * Auto-type the file...
9397 ipp_attribute_t
*doc_name
; /* document-name attribute */
9400 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9402 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9403 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9404 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9408 filetype
= mimeType(MimeDatabase
, super
, type
);
9411 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9412 filetype
->super
, filetype
->type
);
9415 filetype
= mimeType(MimeDatabase
, super
, type
);
9420 * Replace the document-format attribute value with the auto-typed or
9424 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9427 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9428 IPP_TAG_MIMETYPE
)) != NULL
)
9430 _cupsStrFree(jformat
->values
[0].string
.text
);
9432 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9435 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9436 "document-format", NULL
, mimetype
);
9440 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9441 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9442 cupsdLogMessage(CUPSD_LOG_INFO
,
9443 "Hint: Do you have the raw file printing rules enabled?");
9446 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9447 "document-format", NULL
, format
->values
[0].string
.text
);
9452 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9454 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9457 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9458 _("Unsupported document-format \"%s\"."), mimetype
);
9460 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9461 "document-format", NULL
, mimetype
);
9467 * Add the file to the job...
9472 if (add_file(con
, job
, filetype
, compression
))
9475 if (stat(con
->filename
, &fileinfo
))
9478 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9480 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9482 job
->koctets
+= kbytes
;
9484 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9485 attr
->values
[0].integer
+= kbytes
;
9487 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9489 rename(con
->filename
, filename
);
9491 cupsdClearString(&con
->filename
);
9493 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9494 filetype
->super
, filetype
->type
, job
->username
);
9497 * Start the job if this is the last document...
9502 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9503 IPP_TAG_BOOLEAN
)) != NULL
&&
9504 attr
->values
[0].boolean
)
9507 * See if we need to add the ending sheet...
9510 if (cupsdTimeoutJob(job
))
9513 if (job
->state_value
== IPP_JOB_STOPPED
)
9515 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9516 job
->state_value
= IPP_JOB_PENDING
;
9518 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9520 else if (job
->state_value
== IPP_JOB_HELD
)
9522 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9523 IPP_TAG_KEYWORD
)) == NULL
)
9524 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9526 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9528 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9529 job
->state_value
= IPP_JOB_PENDING
;
9531 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9534 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9538 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9544 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9545 IPP_TAG_KEYWORD
)) == NULL
)
9546 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9548 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9550 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9551 job
->state_value
= IPP_JOB_HELD
;
9552 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9554 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9557 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9564 * Fill in the response info...
9567 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9568 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9569 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9572 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9574 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9576 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9577 NULL
, job
->reasons
->values
[0].string
.text
);
9579 con
->response
->request
.status
.status_code
= IPP_OK
;
9582 * Start the job if necessary...
9591 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9596 cupsd_client_t
*con
, /* I - Client connection */
9597 http_status_t status
, /* I - HTTP status code */
9598 cupsd_printer_t
*printer
) /* I - Printer, if any */
9600 ipp_attribute_t
*uri
; /* Request URI, if any */
9603 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9604 IPP_TAG_URI
)) == NULL
)
9605 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9607 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9608 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9609 con
->number
, httpStatus(status
),
9611 ippOpString(con
->request
->request
.op
.operation_id
) :
9613 uri
? uri
->values
[0].string
.text
: "no URI",
9614 con
->http
->hostname
);
9618 int auth_type
; /* Type of authentication required */
9621 auth_type
= CUPSD_AUTH_NONE
;
9623 if (status
== HTTP_UNAUTHORIZED
&&
9624 printer
->num_auth_info_required
> 0 &&
9625 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9627 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9628 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9629 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9632 * Creating and authenticating jobs requires Kerberos...
9635 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9640 * Use policy/location-defined authentication requirements...
9643 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9644 cupsd_location_t
*auth
; /* Pointer to authentication element */
9647 if (printer
->type
& CUPS_PRINTER_CLASS
)
9648 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9650 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9652 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9653 auth
->type
== CUPSD_AUTH_NONE
)
9654 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9656 con
->request
->request
.op
.operation_id
:
9661 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9662 auth_type
= cupsdDefaultAuthType();
9664 auth_type
= auth
->type
;
9668 cupsdSendError(con
, status
, auth_type
);
9671 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9673 ippDelete(con
->response
);
9674 con
->response
= NULL
;
9681 * 'send_ipp_status()' - Send a status back to the IPP client.
9685 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9686 ipp_status_t status
, /* I - IPP status code */
9687 const char *message
,/* I - Status message */
9688 ...) /* I - Additional args as needed */
9690 va_list ap
; /* Pointer to additional args */
9691 char formatted
[1024]; /* Formatted errror message */
9694 va_start(ap
, message
);
9695 vsnprintf(formatted
, sizeof(formatted
),
9696 _cupsLangString(con
->language
, message
), ap
);
9699 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9700 ippOpString(con
->request
->request
.op
.operation_id
),
9701 ippErrorString(status
), formatted
);
9703 con
->response
->request
.status
.status_code
= status
;
9705 if (ippFindAttribute(con
->response
, "attributes-charset",
9706 IPP_TAG_ZERO
) == NULL
)
9707 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9708 "attributes-charset", NULL
, "utf-8");
9710 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9711 IPP_TAG_ZERO
) == NULL
)
9712 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9713 "attributes-natural-language", NULL
, DefaultLanguage
);
9715 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9716 "status-message", NULL
, formatted
);
9721 * 'set_default()' - Set the default destination...
9725 set_default(cupsd_client_t
*con
, /* I - Client connection */
9726 ipp_attribute_t
*uri
) /* I - Printer URI */
9728 http_status_t status
; /* Policy status */
9729 cups_ptype_t dtype
; /* Destination type (printer/class) */
9730 cupsd_printer_t
*printer
, /* Printer */
9731 *oldprinter
; /* Old default printer */
9734 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9735 con
->number
, uri
->values
[0].string
.text
);
9738 * Is the destination valid?
9741 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9747 send_ipp_status(con
, IPP_NOT_FOUND
,
9748 _("The printer or class does not exist."));
9756 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9758 send_http_error(con
, status
, NULL
);
9763 * Set it as the default...
9766 oldprinter
= DefaultPrinter
;
9767 DefaultPrinter
= printer
;
9770 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9771 "%s is no longer the default printer.", oldprinter
->name
);
9773 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9774 "%s is now the default printer.", printer
->name
);
9776 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9777 CUPSD_DIRTY_PRINTCAP
);
9779 cupsdLogMessage(CUPSD_LOG_INFO
,
9780 "Default destination set to \"%s\" by \"%s\".",
9781 printer
->name
, get_username(con
));
9784 * Everything was ok, so return OK status...
9787 con
->response
->request
.status
.status_code
= IPP_OK
;
9792 * 'set_job_attrs()' - Set job attributes.
9796 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9797 ipp_attribute_t
*uri
) /* I - Job URI */
9799 ipp_attribute_t
*attr
, /* Current attribute */
9800 *attr2
; /* Job attribute */
9801 int jobid
; /* Job ID */
9802 cupsd_job_t
*job
; /* Current job */
9803 char scheme
[HTTP_MAX_URI
],
9804 /* Method portion of URI */
9805 username
[HTTP_MAX_URI
],
9806 /* Username portion of URI */
9808 /* Host portion of URI */
9809 resource
[HTTP_MAX_URI
];
9810 /* Resource portion of URI */
9811 int port
; /* Port portion of URI */
9812 int event
; /* Events? */
9813 int check_jobs
; /* Check jobs? */
9816 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9817 con
->number
, uri
->values
[0].string
.text
);
9820 * Start with "everything is OK" status...
9823 con
->response
->request
.status
.status_code
= IPP_OK
;
9826 * See if we have a job URI or a printer URI...
9829 if (!strcmp(uri
->name
, "printer-uri"))
9832 * Got a printer URI; see if we also have a job-id attribute...
9835 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9836 IPP_TAG_INTEGER
)) == NULL
)
9838 send_ipp_status(con
, IPP_BAD_REQUEST
,
9839 _("Got a printer-uri attribute but no job-id."));
9843 jobid
= attr
->values
[0].integer
;
9848 * Got a job URI; parse it to get the job ID...
9851 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9852 sizeof(scheme
), username
, sizeof(username
), host
,
9853 sizeof(host
), &port
, resource
, sizeof(resource
));
9855 if (strncmp(resource
, "/jobs/", 6))
9861 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9862 uri
->values
[0].string
.text
);
9866 jobid
= atoi(resource
+ 6);
9870 * See if the job exists...
9873 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9876 * Nope - return a "not found" error...
9879 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9884 * See if the job has been completed...
9887 if (job
->state_value
> IPP_JOB_STOPPED
)
9890 * Return a "not-possible" error...
9893 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9894 _("Job #%d is finished and cannot be altered."), jobid
);
9899 * See if the job is owned by the requesting user...
9902 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9904 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9905 cupsdFindDest(job
->dest
));
9910 * See what the user wants to change.
9918 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9920 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9923 if (!strcmp(attr
->name
, "attributes-charset") ||
9924 !strcmp(attr
->name
, "attributes-natural-language") ||
9925 !strcmp(attr
->name
, "document-compression") ||
9926 !strcmp(attr
->name
, "document-format") ||
9927 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9928 !strcmp(attr
->name
, "job-document-access-errors") ||
9929 !strcmp(attr
->name
, "job-id") ||
9930 !strcmp(attr
->name
, "job-impressions-completed") ||
9931 !strcmp(attr
->name
, "job-k-octets") ||
9932 !strcmp(attr
->name
, "job-originating-host-name") ||
9933 !strcmp(attr
->name
, "job-originating-user-name") ||
9934 !strcmp(attr
->name
, "job-printer-up-time") ||
9935 !strcmp(attr
->name
, "job-printer-uri") ||
9936 !strcmp(attr
->name
, "job-sheets") ||
9937 !strcmp(attr
->name
, "job-state-message") ||
9938 !strcmp(attr
->name
, "job-state-reasons") ||
9939 !strcmp(attr
->name
, "job-uri") ||
9940 !strcmp(attr
->name
, "number-of-documents") ||
9941 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9942 !strcmp(attr
->name
, "output-device-assigned") ||
9943 !strncmp(attr
->name
, "date-time-at-", 13) ||
9944 !strncmp(attr
->name
, "job-k-octets", 12) ||
9945 !strncmp(attr
->name
, "job-media-sheets", 16) ||
9946 !strncmp(attr
->name
, "time-at-", 8))
9952 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
9953 _("%s cannot be changed."), attr
->name
);
9955 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9956 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9960 if (!strcmp(attr
->name
, "job-priority"))
9963 * Change the job priority...
9966 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
9968 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
9970 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9971 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9973 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
9975 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9976 _("Job is completed and cannot be changed."));
9979 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9981 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
9982 attr
->values
[0].integer
);
9983 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
9986 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
9987 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
9990 else if (!strcmp(attr
->name
, "job-state"))
9993 * Change the job state...
9996 if (attr
->value_tag
!= IPP_TAG_ENUM
)
9998 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10000 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10001 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10005 switch (attr
->values
[0].integer
)
10007 case IPP_JOB_PENDING
:
10008 case IPP_JOB_HELD
:
10009 if (job
->state_value
> IPP_JOB_HELD
)
10011 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10012 _("Job state cannot be changed."));
10015 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10017 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10018 attr
->values
[0].integer
);
10019 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10024 case IPP_JOB_PROCESSING
:
10025 case IPP_JOB_STOPPED
:
10026 if (job
->state_value
!= attr
->values
[0].integer
)
10028 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10029 _("Job state cannot be changed."));
10034 case IPP_JOB_CANCELED
:
10035 case IPP_JOB_ABORTED
:
10036 case IPP_JOB_COMPLETED
:
10037 if (job
->state_value
> IPP_JOB_PROCESSING
)
10039 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10040 _("Job state cannot be changed."));
10043 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10045 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10046 attr
->values
[0].integer
);
10047 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10049 "Job state changed by \"%s\"", username
);
10056 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10058 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10059 IPP_TAG_ZERO
)) != NULL
)
10062 * Some other value; first free the old value...
10065 if (job
->attrs
->prev
)
10066 job
->attrs
->prev
->next
= attr2
->next
;
10068 job
->attrs
->attrs
= attr2
->next
;
10070 if (job
->attrs
->last
== attr2
)
10071 job
->attrs
->last
= job
->attrs
->prev
;
10073 ippDeleteAttribute(NULL
, attr2
);
10076 * Then copy the attribute...
10079 ippCopyAttribute(job
->attrs
, attr
, 0);
10082 * See if the job-name or job-hold-until is being changed.
10085 if (!strcmp(attr
->name
, "job-hold-until"))
10087 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10088 attr
->values
[0].string
.text
);
10089 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10091 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10093 cupsdReleaseJob(job
);
10097 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10098 "Job held by \"%s\".", username
);
10100 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10103 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10106 * Delete the attribute...
10109 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10110 IPP_TAG_ZERO
)) != NULL
)
10112 if (job
->attrs
->prev
)
10113 job
->attrs
->prev
->next
= attr2
->next
;
10115 job
->attrs
->attrs
= attr2
->next
;
10117 if (attr2
== job
->attrs
->last
)
10118 job
->attrs
->last
= job
->attrs
->prev
;
10120 ippDeleteAttribute(NULL
, attr2
);
10122 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10128 * Add new option by copying it...
10131 ippCopyAttribute(job
->attrs
, attr
, 0);
10133 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10142 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10145 * Send events as needed...
10148 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10149 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10150 cupsdFindDest(job
->dest
), job
,
10151 "Job priority changed by user.");
10153 if (event
& CUPSD_EVENT_JOB_STATE
)
10154 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10155 job
->state_value
== IPP_JOB_HELD
?
10156 "Job held by user." : "Job restarted by user.");
10158 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10159 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10160 "Job options changed by user.");
10163 * Start jobs if possible...
10172 * 'set_printer_attrs()' - Set printer attributes.
10176 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10177 ipp_attribute_t
*uri
) /* I - Printer */
10179 http_status_t status
; /* Policy status */
10180 cups_ptype_t dtype
; /* Destination type (printer/class) */
10181 cupsd_printer_t
*printer
; /* Printer/class */
10182 ipp_attribute_t
*attr
; /* Printer attribute */
10183 int changed
= 0; /* Was anything changed? */
10186 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10187 con
->number
, uri
->values
[0].string
.text
);
10190 * Is the destination valid?
10193 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10199 send_ipp_status(con
, IPP_NOT_FOUND
,
10200 _("The printer or class does not exist."));
10208 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10210 send_http_error(con
, status
, printer
);
10215 * Return a list of attributes that can be set via Set-Printer-Attributes.
10218 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10219 IPP_TAG_TEXT
)) != NULL
)
10221 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10225 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10226 IPP_TAG_TEXT
)) != NULL
)
10228 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10233 * Update the printer attributes and return...
10238 cupsdSetPrinterAttrs(printer
);
10239 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10241 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10242 "Printer \"%s\" description or location changed by \"%s\".",
10243 printer
->name
, get_username(con
));
10245 cupsdLogMessage(CUPSD_LOG_INFO
,
10246 "Printer \"%s\" description or location changed by \"%s\".",
10247 printer
->name
, get_username(con
));
10250 con
->response
->request
.status
.status_code
= IPP_OK
;
10255 * 'set_printer_defaults()' - Set printer default options from a request.
10259 set_printer_defaults(
10260 cupsd_client_t
*con
, /* I - Client connection */
10261 cupsd_printer_t
*printer
) /* I - Printer */
10263 int i
; /* Looping var */
10264 ipp_attribute_t
*attr
; /* Current attribute */
10265 size_t namelen
; /* Length of attribute name */
10266 char name
[256], /* New attribute name */
10267 value
[256]; /* String version of integer attrs */
10270 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10273 * Skip non-printer attributes...
10276 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10279 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10281 if (!strcmp(attr
->name
, "job-sheets-default"))
10284 * Only allow keywords and names...
10287 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10291 * Only allow job-sheets-default to be set when running without a
10292 * system high classification level...
10295 if (Classification
)
10298 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10300 if (attr
->num_values
> 1)
10301 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10303 cupsdSetString(&printer
->job_sheets
[1], "none");
10305 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10307 cupsdFreeStrings(&(printer
->users
));
10309 printer
->deny_users
= 0;
10311 if (attr
->value_tag
== IPP_TAG_NAME
&&
10312 (attr
->num_values
> 1 ||
10313 strcmp(attr
->values
[0].string
.text
, "all")))
10315 for (i
= 0; i
< attr
->num_values
; i
++)
10316 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10319 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10321 cupsdFreeStrings(&(printer
->users
));
10323 printer
->deny_users
= 1;
10325 if (attr
->value_tag
== IPP_TAG_NAME
&&
10326 (attr
->num_values
> 1 ||
10327 strcmp(attr
->values
[0].string
.text
, "none")))
10329 for (i
= 0; i
< attr
->num_values
; i
++)
10330 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10333 else if (!strcmp(attr
->name
, "job-quota-period"))
10335 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10338 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10339 attr
->values
[0].integer
);
10340 cupsdFreeQuotas(printer
);
10342 printer
->quota_period
= attr
->values
[0].integer
;
10344 else if (!strcmp(attr
->name
, "job-k-limit"))
10346 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10349 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10350 attr
->values
[0].integer
);
10351 cupsdFreeQuotas(printer
);
10353 printer
->k_limit
= attr
->values
[0].integer
;
10355 else if (!strcmp(attr
->name
, "job-page-limit"))
10357 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10360 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10361 attr
->values
[0].integer
);
10362 cupsdFreeQuotas(printer
);
10364 printer
->page_limit
= attr
->values
[0].integer
;
10366 else if (!strcmp(attr
->name
, "printer-op-policy"))
10368 cupsd_policy_t
*p
; /* Policy */
10371 if (attr
->value_tag
!= IPP_TAG_NAME
)
10374 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10376 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10377 "Setting printer-op-policy to \"%s\"...",
10378 attr
->values
[0].string
.text
);
10379 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10380 printer
->op_policy_ptr
= p
;
10384 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10385 _("Unknown printer-op-policy \"%s\"."),
10386 attr
->values
[0].string
.text
);
10390 else if (!strcmp(attr
->name
, "printer-error-policy"))
10392 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10395 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10396 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10397 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10398 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10399 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10401 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10402 _("Unknown printer-error-policy \"%s\"."),
10403 attr
->values
[0].string
.text
);
10407 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10408 "Setting printer-error-policy to \"%s\"...",
10409 attr
->values
[0].string
.text
);
10410 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10414 * Skip any other non-default attributes...
10417 namelen
= strlen(attr
->name
);
10418 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10419 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10423 * OK, anything else must be a user-defined default...
10426 strlcpy(name
, attr
->name
, sizeof(name
));
10427 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10429 switch (attr
->value_tag
)
10431 case IPP_TAG_DELETEATTR
:
10432 printer
->num_options
= cupsRemoveOption(name
,
10433 printer
->num_options
,
10434 &(printer
->options
));
10435 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10436 "Deleting %s", attr
->name
);
10439 case IPP_TAG_NAME
:
10440 case IPP_TAG_TEXT
:
10441 case IPP_TAG_KEYWORD
:
10443 printer
->num_options
= cupsAddOption(name
,
10444 attr
->values
[0].string
.text
,
10445 printer
->num_options
,
10446 &(printer
->options
));
10447 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10448 "Setting %s to \"%s\"...", attr
->name
,
10449 attr
->values
[0].string
.text
);
10452 case IPP_TAG_BOOLEAN
:
10453 printer
->num_options
= cupsAddOption(name
,
10454 attr
->values
[0].boolean
?
10456 printer
->num_options
,
10457 &(printer
->options
));
10458 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10459 "Setting %s to %s...", attr
->name
,
10460 attr
->values
[0].boolean
? "true" : "false");
10463 case IPP_TAG_INTEGER
:
10464 case IPP_TAG_ENUM
:
10465 sprintf(value
, "%d", attr
->values
[0].integer
);
10466 printer
->num_options
= cupsAddOption(name
, value
,
10467 printer
->num_options
,
10468 &(printer
->options
));
10469 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10470 "Setting %s to %s...", attr
->name
, value
);
10473 case IPP_TAG_RANGE
:
10474 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10475 attr
->values
[0].range
.upper
);
10476 printer
->num_options
= cupsAddOption(name
, value
,
10477 printer
->num_options
,
10478 &(printer
->options
));
10479 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10480 "Setting %s to %s...", attr
->name
, value
);
10483 case IPP_TAG_RESOLUTION
:
10484 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10485 attr
->values
[0].resolution
.yres
,
10486 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10488 printer
->num_options
= cupsAddOption(name
, value
,
10489 printer
->num_options
,
10490 &(printer
->options
));
10491 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10492 "Setting %s to %s...", attr
->name
, value
);
10496 /* Do nothing for other values */
10504 * 'start_printer()' - Start a printer.
10508 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10509 ipp_attribute_t
*uri
) /* I - Printer URI */
10511 int i
; /* Temporary variable */
10512 http_status_t status
; /* Policy status */
10513 cups_ptype_t dtype
; /* Destination type (printer/class) */
10514 cupsd_printer_t
*printer
; /* Printer data */
10517 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10518 con
->number
, uri
->values
[0].string
.text
);
10521 * Is the destination valid?
10524 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10530 send_ipp_status(con
, IPP_NOT_FOUND
,
10531 _("The printer or class does not exist."));
10539 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10541 send_http_error(con
, status
, printer
);
10546 * Start the printer...
10549 printer
->state_message
[0] = '\0';
10551 cupsdStartPrinter(printer
, 1);
10553 if (dtype
& CUPS_PRINTER_CLASS
)
10554 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10555 printer
->name
, get_username(con
));
10557 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10558 printer
->name
, get_username(con
));
10566 if ((i
= check_quotas(con
, printer
)) < 0)
10568 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10573 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10578 * Everything was ok, so return OK status...
10581 con
->response
->request
.status
.status_code
= IPP_OK
;
10586 * 'stop_printer()' - Stop a printer.
10590 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10591 ipp_attribute_t
*uri
) /* I - Printer URI */
10593 http_status_t status
; /* Policy status */
10594 cups_ptype_t dtype
; /* Destination type (printer/class) */
10595 cupsd_printer_t
*printer
; /* Printer data */
10596 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10599 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10600 con
->number
, uri
->values
[0].string
.text
);
10603 * Is the destination valid?
10606 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10612 send_ipp_status(con
, IPP_NOT_FOUND
,
10613 _("The printer or class does not exist."));
10621 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10623 send_http_error(con
, status
, printer
);
10628 * Stop the printer...
10631 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10632 IPP_TAG_TEXT
)) == NULL
)
10633 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10636 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10637 sizeof(printer
->state_message
));
10640 cupsdStopPrinter(printer
, 1);
10642 if (dtype
& CUPS_PRINTER_CLASS
)
10643 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10644 printer
->name
, get_username(con
));
10646 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10647 printer
->name
, get_username(con
));
10650 * Everything was ok, so return OK status...
10653 con
->response
->request
.status
.status_code
= IPP_OK
;
10658 * 'url_encode_attr()' - URL-encode a string attribute.
10662 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10663 char *buffer
,/* I - String buffer */
10664 size_t bufsize
)/* I - Size of buffer */
10666 int i
; /* Looping var */
10667 char *bufptr
, /* Pointer into buffer */
10668 *bufend
; /* End of buffer */
10671 strlcpy(buffer
, attr
->name
, bufsize
);
10672 bufptr
= buffer
+ strlen(buffer
);
10673 bufend
= buffer
+ bufsize
- 1;
10675 for (i
= 0; i
< attr
->num_values
; i
++)
10677 if (bufptr
>= bufend
)
10685 if (bufptr
>= bufend
)
10690 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
10692 if (bufptr
>= bufend
)
10703 * 'url_encode_string()' - URL-encode a string.
10706 static char * /* O - End of string */
10707 url_encode_string(const char *s
, /* I - String */
10708 char *buffer
, /* I - String buffer */
10709 size_t bufsize
) /* I - Size of buffer */
10711 char *bufptr
, /* Pointer into buffer */
10712 *bufend
; /* End of buffer */
10713 static const char *hex
= "0123456789ABCDEF";
10718 bufend
= buffer
+ bufsize
- 1;
10720 while (*s
&& bufptr
< bufend
)
10722 if (*s
== ' ' || *s
== '%' || *s
== '+')
10724 if (bufptr
>= (bufend
- 2))
10728 *bufptr
++ = hex
[(*s
>> 4) & 15];
10729 *bufptr
++ = hex
[*s
& 15];
10733 else if (*s
== '\'' || *s
== '\\')
10735 if (bufptr
>= (bufend
- 1))
10752 * 'user_allowed()' - See if a user is allowed to print to a queue.
10755 static int /* O - 0 if not allowed, 1 if allowed */
10756 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10757 const char *username
) /* I - Username */
10759 struct passwd
*pw
; /* User password data */
10760 char baseuser
[256], /* Base username */
10761 *baseptr
, /* Pointer to "@" in base username */
10762 *name
; /* Current user name */
10765 if (cupsArrayCount(p
->users
) == 0)
10768 if (!strcmp(username
, "root"))
10771 if (strchr(username
, '@'))
10774 * Strip @REALM for username check...
10777 strlcpy(baseuser
, username
, sizeof(baseuser
));
10779 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10782 username
= baseuser
;
10785 pw
= getpwnam(username
);
10788 for (name
= (char *)cupsArrayFirst(p
->users
);
10790 name
= (char *)cupsArrayNext(p
->users
))
10792 if (name
[0] == '@')
10795 * Check group membership...
10798 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10801 else if (name
[0] == '#')
10807 if (cupsdCheckGroup(username
, pw
, name
))
10810 else if (!_cups_strcasecmp(username
, name
))
10814 return ((name
!= NULL
) != p
->deny_users
);
10819 * 'validate_job()' - Validate printer options and destination.
10823 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10824 ipp_attribute_t
*uri
) /* I - Printer URI */
10826 http_status_t status
; /* Policy status */
10827 ipp_attribute_t
*attr
, /* Current attribute */
10828 *auth_info
; /* auth-info attribute */
10829 ipp_attribute_t
*format
, /* Document-format attribute */
10830 *name
; /* Job-name attribute */
10831 cups_ptype_t dtype
; /* Destination type (printer/class) */
10832 char super
[MIME_MAX_SUPER
],
10833 /* Supertype of file */
10834 type
[MIME_MAX_TYPE
];
10835 /* Subtype of file */
10836 cupsd_printer_t
*printer
; /* Printer */
10839 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10840 con
->number
, uri
->values
[0].string
.text
);
10843 * OK, see if the client is sending the document compressed - CUPS
10844 * doesn't support compression yet...
10847 if ((attr
= ippFindAttribute(con
->request
, "compression",
10848 IPP_TAG_KEYWORD
)) != NULL
)
10850 if (strcmp(attr
->values
[0].string
.text
, "none")
10852 && strcmp(attr
->values
[0].string
.text
, "gzip")
10853 #endif /* HAVE_LIBZ */
10856 send_ipp_status(con
, IPP_ATTRIBUTES
,
10857 _("Unsupported 'compression' value \"%s\"."),
10858 attr
->values
[0].string
.text
);
10859 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10860 "compression", NULL
, attr
->values
[0].string
.text
);
10866 * Is it a format we support?
10869 if ((format
= ippFindAttribute(con
->request
, "document-format",
10870 IPP_TAG_MIMETYPE
)) != NULL
)
10872 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
10875 send_ipp_status(con
, IPP_BAD_REQUEST
,
10876 _("Bad 'document-format' value \"%s\"."),
10877 format
->values
[0].string
.text
);
10881 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10882 !mimeType(MimeDatabase
, super
, type
))
10884 cupsdLogMessage(CUPSD_LOG_INFO
,
10885 "Hint: Do you have the raw file printing rules enabled?");
10886 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10887 _("Unsupported 'document-format' value \"%s\"."),
10888 format
->values
[0].string
.text
);
10889 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10890 "document-format", NULL
, format
->values
[0].string
.text
);
10896 * Is the job-name valid?
10899 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
10901 int bad_name
= 0; /* Is the job-name value bad? */
10903 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
10904 name
->num_values
!= 1)
10911 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
10912 * IPP Everywhere requirements for "name" values...
10915 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
10917 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
10921 if (*nameptr
< ' ' && *nameptr
!= '\t')
10923 else if (*nameptr
== 0x7f)
10925 else if ((*nameptr
& 0xe0) == 0xc0)
10927 if ((nameptr
[1] & 0xc0) != 0x80)
10932 else if ((*nameptr
& 0xf0) == 0xe0)
10934 if ((nameptr
[1] & 0xc0) != 0x80 ||
10935 (nameptr
[2] & 0xc0) != 0x80)
10940 else if ((*nameptr
& 0xf8) == 0xf0)
10942 if ((nameptr
[1] & 0xc0) != 0x80 ||
10943 (nameptr
[2] & 0xc0) != 0x80 ||
10944 (nameptr
[3] & 0xc0) != 0x80)
10949 else if (*nameptr
& 0x80)
10959 if (StrictConformance
)
10961 send_ipp_status(con
, IPP_ATTRIBUTES
,
10962 _("Unsupported 'job-name' value."));
10963 ippCopyAttribute(con
->response
, name
, 0);
10968 cupsdLogMessage(CUPSD_LOG_WARN
,
10969 "Unsupported 'job-name' value, deleting from request.");
10970 ippDeleteAttribute(con
->request
, name
);
10976 * Is the destination valid?
10979 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10985 send_ipp_status(con
, IPP_NOT_FOUND
,
10986 _("The printer or class does not exist."));
10994 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
10996 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10998 send_http_error(con
, status
, printer
);
11001 else if (printer
->num_auth_info_required
== 1 &&
11002 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11005 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11009 else if (auth_info
&& !con
->http
->tls
&&
11010 !httpAddrLocalhost(con
->http
->hostaddr
))
11013 * Require encryption of auth-info over non-local connections...
11016 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11019 #endif /* HAVE_SSL */
11022 * Everything was ok, so return OK status...
11025 con
->response
->request
.status
.status_code
= IPP_OK
;
11030 * 'validate_name()' - Make sure the printer name only contains valid chars.
11033 static int /* O - 0 if name is no good, 1 if good */
11034 validate_name(const char *name
) /* I - Name to check */
11036 const char *ptr
; /* Pointer into name */
11040 * Scan the whole name...
11043 for (ptr
= name
; *ptr
; ptr
++)
11044 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11048 * All the characters are good; validate the length, too...
11051 return ((ptr
- name
) < 128);
11056 * 'validate_user()' - Validate the user for the request.
11059 static int /* O - 1 if permitted, 0 otherwise */
11060 validate_user(cupsd_job_t
*job
, /* I - Job */
11061 cupsd_client_t
*con
, /* I - Client connection */
11062 const char *owner
, /* I - Owner of job/resource */
11063 char *username
, /* O - Authenticated username */
11064 size_t userlen
) /* I - Length of username */
11066 cupsd_printer_t
*printer
; /* Printer for job */
11069 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, userlen=" CUPS_LLFMT
")", job
->id
, con
? con
->number
: 0, owner
? owner
: "(null)", username
, CUPS_LLCAST userlen
);
11072 * Validate input...
11075 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11079 * Get the best authenticated username that is available.
11082 strlcpy(username
, get_username(con
), userlen
);
11085 * Check the username against the owner...
11088 printer
= cupsdFindDest(job
->dest
);
11090 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11091 con
, owner
) == HTTP_OK
);
11096 * End of "$Id: ipp.c 12067 2014-07-31 00:02:30Z msweet $".