2 * "$Id: ipp.c 11734 2014-03-25 18:01:47Z 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
,
134 static char *url_encode_string(const char *s
, char *buffer
, int bufsize
);
135 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
136 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
137 static int validate_name(const char *name
);
138 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
139 const char *owner
, char *username
,
144 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
147 int /* O - 1 on success, 0 on failure */
148 cupsdProcessIPPRequest(
149 cupsd_client_t
*con
) /* I - Client connection */
151 ipp_tag_t group
; /* Current group tag */
152 ipp_attribute_t
*attr
; /* Current attribute */
153 ipp_attribute_t
*charset
; /* Character set attribute */
154 ipp_attribute_t
*language
; /* Language attribute */
155 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
156 ipp_attribute_t
*username
; /* requesting-user-name attr */
157 int sub_id
; /* Subscription ID */
160 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
161 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
162 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
165 * First build an empty response message for this request...
168 con
->response
= ippNew();
170 con
->response
->request
.status
.version
[0] =
171 con
->request
->request
.op
.version
[0];
172 con
->response
->request
.status
.version
[1] =
173 con
->request
->request
.op
.version
[1];
174 con
->response
->request
.status
.request_id
=
175 con
->request
->request
.op
.request_id
;
178 * Then validate the request header and required attributes...
181 if (con
->request
->request
.any
.version
[0] != 1 &&
182 con
->request
->request
.any
.version
[0] != 2)
185 * Return an error, since we only support IPP 1.x and 2.x.
188 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
189 "%04X %s Bad request version number %d.%d",
190 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
191 con
->request
->request
.any
.version
[0],
192 con
->request
->request
.any
.version
[1]);
194 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
195 _("Bad request version number %d.%d."),
196 con
->request
->request
.any
.version
[0],
197 con
->request
->request
.any
.version
[1]);
199 else if (con
->request
->request
.any
.request_id
< 1)
202 * Return an error, since request IDs must be between 1 and 2^31-1
205 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
206 "%04X %s Bad request ID %d",
207 IPP_BAD_REQUEST
, con
->http
.hostname
,
208 con
->request
->request
.any
.request_id
);
210 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
211 con
->request
->request
.any
.request_id
);
213 else if (!con
->request
->attrs
)
215 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
216 "%04X %s No attributes in request",
217 IPP_BAD_REQUEST
, con
->http
.hostname
);
219 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
224 * Make sure that the attributes are provided in the correct order and
225 * don't repeat groups...
228 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
231 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
234 * Out of order; return an error...
237 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
238 "%04X %s Attribute groups are out of order",
239 IPP_BAD_REQUEST
, con
->http
.hostname
);
241 send_ipp_status(con
, IPP_BAD_REQUEST
,
242 _("Attribute groups are out of order (%x < %x)."),
243 attr
->group_tag
, group
);
247 group
= attr
->group_tag
;
252 * Then make sure that the first three attributes are:
255 * attributes-natural-language
256 * printer-uri/job-uri
259 attr
= con
->request
->attrs
;
260 if (attr
&& attr
->name
&&
261 !strcmp(attr
->name
, "attributes-charset") &&
262 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
270 if (attr
&& attr
->name
&&
271 !strcmp(attr
->name
, "attributes-natural-language") &&
272 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
277 * Reset language for this request if different from Accept-Language.
280 if (!con
->language
||
281 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
283 cupsLangFree(con
->language
);
284 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
290 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
291 IPP_TAG_URI
)) != NULL
)
293 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
294 IPP_TAG_URI
)) != NULL
)
296 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
297 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
302 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
303 "attributes-charset", NULL
,
304 charset
->values
[0].string
.text
);
306 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
307 "attributes-charset", NULL
, "utf-8");
310 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
311 "attributes-natural-language", NULL
,
312 language
->values
[0].string
.text
);
314 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
315 "attributes-natural-language", NULL
, DefaultLanguage
);
318 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
319 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
322 * Bad character set...
325 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
326 charset
->values
[0].string
.text
);
327 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
328 "%04X %s Unsupported attributes-charset value \"%s\"",
329 IPP_CHARSET
, con
->http
.hostname
,
330 charset
->values
[0].string
.text
);
331 send_ipp_status(con
, IPP_BAD_REQUEST
,
332 _("Unsupported character set \"%s\"."),
333 charset
->values
[0].string
.text
);
335 else if (!charset
|| !language
||
337 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
338 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
339 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
340 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
341 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
344 * Return an error, since attributes-charset,
345 * attributes-natural-language, and printer-uri/job-uri are required
346 * for all operations.
351 cupsdLogMessage(CUPSD_LOG_ERROR
,
352 "Missing attributes-charset attribute");
354 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
355 "%04X %s Missing attributes-charset attribute",
356 IPP_BAD_REQUEST
, con
->http
.hostname
);
361 cupsdLogMessage(CUPSD_LOG_ERROR
,
362 "Missing attributes-natural-language attribute");
364 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
365 "%04X %s Missing attributes-natural-language attribute",
366 IPP_BAD_REQUEST
, con
->http
.hostname
);
371 cupsdLogMessage(CUPSD_LOG_ERROR
,
372 "Missing printer-uri, job-uri, or ppd-name "
375 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
376 "%04X %s Missing printer-uri, job-uri, or ppd-name "
377 "attribute", IPP_BAD_REQUEST
, con
->http
.hostname
);
380 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
382 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
383 cupsdLogMessage(CUPSD_LOG_DEBUG
,
384 "attr \"%s\": group_tag = %x, value_tag = %x",
385 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
388 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
390 send_ipp_status(con
, IPP_BAD_REQUEST
,
391 _("Missing required attributes."));
396 * OK, all the checks pass so far; make sure requesting-user-name is
397 * not "root" from a remote host...
400 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
401 IPP_TAG_NAME
)) != NULL
)
404 * Check for root user...
407 if (!strcmp(username
->values
[0].string
.text
, "root") &&
408 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
409 strcmp(con
->username
, "root"))
412 * Remote unauthenticated user masquerading as local root...
415 _cupsStrFree(username
->values
[0].string
.text
);
416 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
420 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
421 IPP_TAG_INTEGER
)) != NULL
)
422 sub_id
= attr
->values
[0].integer
;
427 * Then try processing the operation...
431 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
432 ippOpString(con
->request
->request
.op
.operation_id
),
433 uri
->values
[0].string
.text
);
435 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
436 ippOpString(con
->request
->request
.op
.operation_id
));
438 switch (con
->request
->request
.op
.operation_id
)
440 case IPP_OP_PRINT_JOB
:
444 case IPP_OP_VALIDATE_JOB
:
445 validate_job(con
, uri
);
448 case IPP_OP_CREATE_JOB
:
449 create_job(con
, uri
);
452 case IPP_OP_SEND_DOCUMENT
:
453 send_document(con
, uri
);
456 case IPP_OP_CANCEL_JOB
:
457 cancel_job(con
, uri
);
460 case IPP_OP_GET_JOB_ATTRIBUTES
:
461 get_job_attrs(con
, uri
);
464 case IPP_OP_GET_JOBS
:
468 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
469 get_printer_attrs(con
, uri
);
472 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
473 get_printer_supported(con
, uri
);
476 case IPP_OP_HOLD_JOB
:
480 case IPP_OP_RELEASE_JOB
:
481 release_job(con
, uri
);
484 case IPP_OP_RESTART_JOB
:
485 restart_job(con
, uri
);
488 case IPP_OP_PAUSE_PRINTER
:
489 stop_printer(con
, uri
);
492 case IPP_OP_RESUME_PRINTER
:
493 start_printer(con
, uri
);
496 case IPP_OP_PURGE_JOBS
:
497 case IPP_OP_CANCEL_JOBS
:
498 case IPP_OP_CANCEL_MY_JOBS
:
499 cancel_all_jobs(con
, uri
);
502 case IPP_OP_SET_JOB_ATTRIBUTES
:
503 set_job_attrs(con
, uri
);
506 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
507 set_printer_attrs(con
, uri
);
510 case IPP_OP_HOLD_NEW_JOBS
:
511 hold_new_jobs(con
, uri
);
514 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
515 release_held_new_jobs(con
, uri
);
518 case IPP_OP_CLOSE_JOB
:
522 case IPP_OP_CUPS_GET_DEFAULT
:
526 case IPP_OP_CUPS_GET_PRINTERS
:
527 get_printers(con
, 0);
530 case IPP_OP_CUPS_GET_CLASSES
:
531 get_printers(con
, CUPS_PRINTER_CLASS
);
534 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
535 add_printer(con
, uri
);
538 case IPP_OP_CUPS_DELETE_PRINTER
:
539 delete_printer(con
, uri
);
542 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
546 case IPP_OP_CUPS_DELETE_CLASS
:
547 delete_printer(con
, uri
);
550 case IPP_OP_CUPS_ACCEPT_JOBS
:
551 case IPP_OP_ENABLE_PRINTER
:
552 accept_jobs(con
, uri
);
555 case IPP_OP_CUPS_REJECT_JOBS
:
556 case IPP_OP_DISABLE_PRINTER
:
557 reject_jobs(con
, uri
);
560 case IPP_OP_CUPS_SET_DEFAULT
:
561 set_default(con
, uri
);
564 case IPP_OP_CUPS_GET_DEVICES
:
568 case IPP_OP_CUPS_GET_DOCUMENT
:
569 get_document(con
, uri
);
572 case IPP_OP_CUPS_GET_PPD
:
576 case IPP_OP_CUPS_GET_PPDS
:
580 case IPP_OP_CUPS_MOVE_JOB
:
584 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
585 authenticate_job(con
, uri
);
588 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
589 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
590 create_subscriptions(con
, uri
);
593 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
594 get_subscription_attrs(con
, sub_id
);
597 case IPP_OP_GET_SUBSCRIPTIONS
:
598 get_subscriptions(con
, uri
);
601 case IPP_OP_RENEW_SUBSCRIPTION
:
602 renew_subscription(con
, sub_id
);
605 case IPP_OP_CANCEL_SUBSCRIPTION
:
606 cancel_subscription(con
, sub_id
);
609 case IPP_OP_GET_NOTIFICATIONS
:
610 get_notifications(con
);
614 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
615 "%04X %s Operation %04X (%s) not supported",
616 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
617 con
->request
->request
.op
.operation_id
,
618 ippOpString(con
->request
->request
.op
.operation_id
));
620 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
621 _("%s not supported."),
623 con
->request
->request
.op
.operation_id
));
633 * Sending data from the scheduler...
636 cupsdLogMessage(con
->response
->request
.status
.status_code
637 >= IPP_BAD_REQUEST
&&
638 con
->response
->request
.status
.status_code
639 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
640 "[Client %d] Returning IPP %s for %s (%s) from %s",
642 ippErrorString(con
->response
->request
.status
.status_code
),
643 ippOpString(con
->request
->request
.op
.operation_id
),
644 uri
? uri
->values
[0].string
.text
: "no URI",
647 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
649 #ifdef CUPSD_USE_CHUNKING
651 * Because older versions of CUPS (1.1.17 and older) and some IPP
652 * clients do not implement chunking properly, we cannot use
653 * chunking by default. This may become the default in future
654 * CUPS releases, or we might add a configuration directive for
658 if (con
->http
.version
== HTTP_1_1
)
660 cupsdLogMessage(CUPSD_LOG_DEBUG
,
661 "[Client %d] Transfer-Encoding: chunked",
664 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
667 if (cupsdFlushHeader(con
) < 0)
670 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
673 #endif /* CUPSD_USE_CHUNKING */
675 size_t length
; /* Length of response */
678 length
= ippLength(con
->response
);
680 if (con
->file
>= 0 && !con
->pipe_pid
)
682 struct stat fileinfo
; /* File information */
684 if (!fstat(con
->file
, &fileinfo
))
685 length
+= fileinfo
.st_size
;
688 cupsdLogMessage(CUPSD_LOG_DEBUG
,
689 "[Client %d] Content-Length: " CUPS_LLFMT
,
690 con
->http
.fd
, CUPS_LLCAST length
);
691 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
692 CUPS_LLCAST length
) < 0)
695 if (cupsdFlushHeader(con
) < 0)
698 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
699 con
->http
.data_remaining
= length
;
701 if (con
->http
.data_remaining
<= INT_MAX
)
702 con
->http
._data_remaining
= con
->http
.data_remaining
;
704 con
->http
._data_remaining
= INT_MAX
;
707 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
708 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
711 * Tell the caller the response header was sent successfully...
719 * Tell the caller the response header could not be sent...
728 * Sending data from a subprocess like cups-deviced; tell the caller
729 * everything is A-OK so far...
738 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
741 int /* O - 0 on success, -1 on error */
742 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
744 cupsd_printer_t
*printer
; /* Destination printer or class */
745 ipp_attribute_t
*attr
; /* job-sheets attribute */
746 int kbytes
; /* Kilobytes in banner */
749 job
->pending_timeout
= 0;
752 * See if we need to add the ending sheet...
755 if (!cupsdLoadJob(job
))
758 printer
= cupsdFindDest(job
->dest
);
759 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
761 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
762 attr
&& attr
->num_values
> 1)
768 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
769 attr
->values
[1].string
.text
);
771 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
774 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
782 * 'accept_jobs()' - Accept print jobs to a printer.
786 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
787 ipp_attribute_t
*uri
) /* I - Printer or class URI */
789 http_status_t status
; /* Policy status */
790 cups_ptype_t dtype
; /* Destination type (printer/class) */
791 cupsd_printer_t
*printer
; /* Printer data */
794 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
795 con
->http
.fd
, uri
->values
[0].string
.text
);
798 * Is the destination valid?
801 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
807 send_ipp_status(con
, IPP_NOT_FOUND
,
808 _("The printer or class does not exist."));
816 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
818 send_http_error(con
, status
, printer
);
823 * Accept jobs sent to the printer...
826 printer
->accepting
= 1;
827 printer
->state_message
[0] = '\0';
829 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
830 "Now accepting jobs.");
832 if (dtype
& CUPS_PRINTER_CLASS
)
834 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
836 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
837 printer
->name
, get_username(con
));
841 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
843 cupsdLogMessage(CUPSD_LOG_INFO
,
844 "Printer \"%s\" now accepting jobs (\"%s\").",
845 printer
->name
, get_username(con
));
849 * Everything was ok, so return OK status...
852 con
->response
->request
.status
.status_code
= IPP_OK
;
857 * 'add_class()' - Add a class to the system.
861 add_class(cupsd_client_t
*con
, /* I - Client connection */
862 ipp_attribute_t
*uri
) /* I - URI of class */
864 http_status_t status
; /* Policy status */
865 int i
; /* Looping var */
866 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
867 username
[HTTP_MAX_URI
], /* Username portion of URI */
868 host
[HTTP_MAX_URI
], /* Host portion of URI */
869 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
870 int port
; /* Port portion of URI */
871 cupsd_printer_t
*pclass
, /* Class */
872 *member
; /* Member printer/class */
873 cups_ptype_t dtype
; /* Destination type */
874 ipp_attribute_t
*attr
; /* Printer attribute */
875 int modify
; /* Non-zero if we just modified */
876 int need_restart_job
; /* Need to restart job? */
879 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
880 con
->http
.fd
, uri
->values
[0].string
.text
);
883 * Do we have a valid URI?
886 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
887 sizeof(scheme
), username
, sizeof(username
), host
,
888 sizeof(host
), &port
, resource
, sizeof(resource
));
891 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
894 * No, return an error...
897 send_ipp_status(con
, IPP_BAD_REQUEST
,
898 _("The printer-uri must be of the form "
899 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
904 * Do we have a valid printer name?
907 if (!validate_name(resource
+ 9))
910 * No, return an error...
913 send_ipp_status(con
, IPP_BAD_REQUEST
,
914 _("The printer-uri \"%s\" contains invalid characters."),
915 uri
->values
[0].string
.text
);
920 * See if the class already exists; if not, create a new class...
923 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
926 * Class doesn't exist; see if we have a printer of the same name...
929 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
932 * Yes, return an error...
935 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
936 _("A printer named \"%s\" already exists."),
942 * No, check the default policy and then add the class...
945 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
947 send_http_error(con
, status
, NULL
);
951 pclass
= cupsdAddClass(resource
+ 9);
954 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
957 send_http_error(con
, status
, pclass
);
964 * Look for attributes and copy them over as needed...
967 need_restart_job
= 0;
969 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
970 IPP_TAG_TEXT
)) != NULL
)
971 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
973 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
974 IPP_TAG_TEXT
)) != NULL
)
975 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
977 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
978 IPP_TAG_BOOLEAN
)) != NULL
&&
979 attr
->values
[0].boolean
!= pclass
->accepting
)
981 cupsdLogMessage(CUPSD_LOG_INFO
,
982 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
983 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
985 pclass
->accepting
= attr
->values
[0].boolean
;
987 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
988 pclass
->accepting
? "Now" : "No longer");
991 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
992 IPP_TAG_BOOLEAN
)) != NULL
)
994 if (pclass
->shared
&& !attr
->values
[0].boolean
)
995 cupsdDeregisterPrinter(pclass
, 1);
997 cupsdLogMessage(CUPSD_LOG_INFO
,
998 "Setting %s printer-is-shared to %d (was %d.)",
999 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
1001 pclass
->shared
= attr
->values
[0].boolean
;
1004 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1005 IPP_TAG_ENUM
)) != NULL
)
1007 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1008 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1010 send_ipp_status(con
, IPP_BAD_REQUEST
,
1011 _("Attempt to set %s printer-state to bad value %d."),
1012 pclass
->name
, attr
->values
[0].integer
);
1016 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1017 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1019 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1020 cupsdStopPrinter(pclass
, 0);
1023 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1024 need_restart_job
= 1;
1027 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1028 IPP_TAG_TEXT
)) != NULL
)
1030 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1031 sizeof(pclass
->state_message
));
1033 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1034 pclass
->state_message
);
1036 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1037 IPP_TAG_URI
)) != NULL
)
1040 * Clear the printer array as needed...
1043 need_restart_job
= 1;
1045 if (pclass
->num_printers
> 0)
1047 free(pclass
->printers
);
1048 pclass
->num_printers
= 0;
1052 * Add each printer or class that is listed...
1055 for (i
= 0; i
< attr
->num_values
; i
++)
1058 * Search for the printer or class URI...
1061 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1067 send_ipp_status(con
, IPP_NOT_FOUND
,
1068 _("The printer or class does not exist."));
1071 else if (dtype
& CUPS_PRINTER_CLASS
)
1073 send_ipp_status(con
, IPP_BAD_REQUEST
,
1074 _("Nested classes are not allowed."));
1079 * Add it to the class...
1082 cupsdAddPrinterToClass(pclass
, member
);
1086 set_printer_defaults(con
, pclass
);
1088 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1089 IPP_TAG_KEYWORD
)) != NULL
)
1090 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1093 * Update the printer class attributes and return...
1096 cupsdSetPrinterAttrs(pclass
);
1097 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1099 if (need_restart_job
&& pclass
->job
)
1102 * Reset the current job to a "pending" status...
1105 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1106 "Job restarted because the class was modified.");
1109 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1113 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1114 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1115 pclass
->name
, get_username(con
));
1117 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1118 pclass
->name
, get_username(con
));
1122 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1123 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1124 pclass
->name
, get_username(con
));
1126 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1127 pclass
->name
, get_username(con
));
1130 con
->response
->request
.status
.status_code
= IPP_OK
;
1135 * 'add_file()' - Add a file to a job.
1138 static int /* O - 0 on success, -1 on error */
1139 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1140 cupsd_job_t
*job
, /* I - Job to add to */
1141 mime_type_t
*filetype
, /* I - Type of file */
1142 int compression
) /* I - Compression */
1144 mime_type_t
**filetypes
; /* New filetypes array... */
1145 int *compressions
; /* New compressions array... */
1148 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1149 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1150 "compression=%d)", con
, con
? con
->http
.fd
: -1, job
->id
,
1151 filetype
->super
, filetype
->type
, compression
);
1154 * Add the file to the job...
1157 if (job
->num_files
== 0)
1159 compressions
= (int *)malloc(sizeof(int));
1160 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1164 compressions
= (int *)realloc(job
->compressions
,
1165 (job
->num_files
+ 1) * sizeof(int));
1166 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1167 (job
->num_files
+ 1) *
1168 sizeof(mime_type_t
*));
1172 job
->compressions
= compressions
;
1175 job
->filetypes
= filetypes
;
1177 if (!compressions
|| !filetypes
)
1179 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1180 "Job aborted because the scheduler ran out of memory.");
1183 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1184 _("Unable to allocate memory for file types."));
1189 job
->compressions
[job
->num_files
] = compression
;
1190 job
->filetypes
[job
->num_files
] = filetype
;
1195 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1202 * 'add_job()' - Add a job to a print queue.
1205 static cupsd_job_t
* /* O - Job object */
1206 add_job(cupsd_client_t
*con
, /* I - Client connection */
1207 cupsd_printer_t
*printer
, /* I - Destination printer */
1208 mime_type_t
*filetype
) /* I - First print file type, if any */
1210 http_status_t status
; /* Policy status */
1211 ipp_attribute_t
*attr
, /* Current attribute */
1212 *auth_info
; /* auth-info attribute */
1213 const char *mandatory
; /* Current mandatory job attribute */
1214 const char *val
; /* Default option value */
1215 int priority
; /* Job priority */
1216 cupsd_job_t
*job
; /* Current job */
1217 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1218 int kbytes
; /* Size of print file */
1219 int i
; /* Looping var */
1220 int lowerpagerange
; /* Page range bound */
1221 int exact
; /* Did we have an exact match? */
1222 ipp_attribute_t
*media_col
, /* media-col attribute */
1223 *media_margin
; /* media-*-margin attribute */
1224 ipp_t
*unsup_col
; /* media-col in unsupported response */
1225 static const char * const readonly
[] =/* List of read-only attributes */
1228 "job-k-octets-completed",
1229 "job-impressions-completed",
1230 "job-media-sheets-completed",
1232 "job-state-message",
1233 "job-state-reasons",
1234 "time-at-completed",
1236 "time-at-processing"
1240 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1241 con
, con
->http
.fd
, printer
, printer
->name
,
1242 filetype
, filetype
? filetype
->super
: "none",
1243 filetype
? filetype
->type
: "none");
1246 * Check remote printing to non-shared printer...
1249 if (!printer
->shared
&&
1250 _cups_strcasecmp(con
->http
.hostname
, "localhost") &&
1251 _cups_strcasecmp(con
->http
.hostname
, ServerName
))
1253 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1254 _("The printer or class is not shared."));
1262 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1264 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1266 send_http_error(con
, status
, printer
);
1269 else if (printer
->num_auth_info_required
== 1 &&
1270 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1273 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1277 else if (auth_info
&& !con
->http
.tls
&&
1278 !httpAddrLocalhost(con
->http
.hostaddr
))
1281 * Require encryption of auth-info over non-local connections...
1284 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1287 #endif /* HAVE_SSL */
1290 * See if the printer is accepting jobs...
1293 if (!printer
->accepting
)
1295 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1296 _("Destination \"%s\" is not accepting jobs."),
1302 * Validate job template attributes; for now just document-format,
1303 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1307 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1309 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
],
1310 IPP_TAG_ZERO
)) != NULL
)
1312 ippDeleteAttribute(con
->request
, attr
);
1314 if (StrictConformance
)
1316 send_ipp_status(con
, IPP_BAD_REQUEST
,
1317 _("The '%s' Job Description attribute cannot be "
1318 "supplied in a job creation request."), readonly
[i
]);
1322 cupsdLogMessage(CUPSD_LOG_INFO
,
1323 "Unexpected '%s' Job Description attribute in a job "
1324 "creation request.", readonly
[i
]);
1330 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1332 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1334 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1337 * Missing a required attribute...
1340 send_ipp_status(con
, IPP_CONFLICT
,
1341 _("The \"%s\" attribute is required for print jobs."),
1348 if (filetype
&& printer
->filetypes
&&
1349 !cupsArrayFind(printer
->filetypes
, filetype
))
1351 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1352 /* MIME media type string */
1355 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1358 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1359 _("Unsupported format \"%s\"."), mimetype
);
1361 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1362 "document-format", NULL
, mimetype
);
1367 if ((attr
= ippFindAttribute(con
->request
, "copies",
1368 IPP_TAG_INTEGER
)) != NULL
)
1370 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1372 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1373 attr
->values
[0].integer
);
1374 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1375 "copies", attr
->values
[0].integer
);
1380 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1381 IPP_TAG_ZERO
)) != NULL
)
1383 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1384 attr
->value_tag
!= IPP_TAG_NAME
)
1386 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1390 if (attr
->num_values
> 2)
1392 send_ipp_status(con
, IPP_BAD_REQUEST
,
1393 _("Too many job-sheets values (%d > 2)."),
1398 for (i
= 0; i
< attr
->num_values
; i
++)
1399 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1400 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1402 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1403 attr
->values
[i
].string
.text
);
1408 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1409 IPP_TAG_INTEGER
)) != NULL
)
1411 if (attr
->values
[0].integer
!= 1 &&
1412 attr
->values
[0].integer
!= 2 &&
1413 attr
->values
[0].integer
!= 4 &&
1414 attr
->values
[0].integer
!= 6 &&
1415 attr
->values
[0].integer
!= 9 &&
1416 attr
->values
[0].integer
!= 16)
1418 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1419 attr
->values
[0].integer
);
1420 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1421 "number-up", attr
->values
[0].integer
);
1426 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1427 IPP_TAG_RANGE
)) != NULL
)
1429 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1431 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1432 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1434 send_ipp_status(con
, IPP_BAD_REQUEST
,
1435 _("Bad page-ranges values %d-%d."),
1436 attr
->values
[i
].range
.lower
,
1437 attr
->values
[i
].range
.upper
);
1441 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1446 * Do media selection as needed...
1449 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1450 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1451 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1454 (media_col
= ippFindAttribute(con
->request
, "media-col",
1455 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1457 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1459 unsup_col
= ippNew();
1460 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1461 "media-bottom-margin",
1462 IPP_TAG_INTEGER
)) != NULL
)
1463 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1464 "media-bottom-margin", media_margin
->values
[0].integer
);
1466 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1467 "media-left-margin",
1468 IPP_TAG_INTEGER
)) != NULL
)
1469 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1470 "media-left-margin", media_margin
->values
[0].integer
);
1472 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1473 "media-right-margin",
1474 IPP_TAG_INTEGER
)) != NULL
)
1475 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1476 "media-right-margin", media_margin
->values
[0].integer
);
1478 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1480 IPP_TAG_INTEGER
)) != NULL
)
1481 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1482 "media-top-margin", media_margin
->values
[0].integer
);
1484 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1486 ippDelete(unsup_col
);
1491 * Make sure we aren't over our limit...
1494 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1497 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1499 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1503 if ((i
= check_quotas(con
, printer
)) < 0)
1505 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1510 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1515 * Create the job and set things up...
1518 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1519 IPP_TAG_INTEGER
)) != NULL
)
1520 priority
= attr
->values
[0].integer
;
1523 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1524 printer
->options
)) != NULL
)
1525 priority
= atoi(val
);
1529 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1533 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1534 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1536 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1537 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1538 attr
->num_values
!= 1)
1540 send_ipp_status(con
, IPP_ATTRIBUTES
,
1541 _("Bad job-name value: Wrong type or count."));
1542 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1543 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1546 else if (!ippValidateAttribute(attr
))
1548 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1549 cupsLastErrorString());
1550 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1551 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1555 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1557 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1558 _("Unable to add job for destination \"%s\"."),
1563 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1564 job
->attrs
= con
->request
;
1566 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1568 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1571 apply_printer_defaults(printer
, job
);
1573 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1575 if (con
->username
[0])
1577 cupsdSetString(&job
->username
, con
->username
);
1580 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1584 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1585 "add_job: requesting-user-name=\"%s\"",
1586 attr
->values
[0].string
.text
);
1588 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1591 cupsdSetString(&job
->username
, "anonymous");
1594 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1595 "job-originating-user-name", NULL
, job
->username
);
1598 attr
->group_tag
= IPP_TAG_JOB
;
1599 _cupsStrFree(attr
->name
);
1600 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1603 if (con
->username
[0] || auth_info
)
1605 save_auth_info(con
, job
, auth_info
);
1608 * Remove the auth-info attribute from the attribute data...
1612 ippDeleteAttribute(job
->attrs
, auth_info
);
1615 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1616 IPP_TAG_ZERO
)) != NULL
)
1619 * Request contains a job-originating-host-name attribute; validate it...
1622 if (attr
->value_tag
!= IPP_TAG_NAME
||
1623 attr
->num_values
!= 1 ||
1624 strcmp(con
->http
.hostname
, "localhost"))
1627 * Can't override the value if we aren't connected via localhost.
1628 * Also, we can only have 1 value and it must be a name value.
1631 switch (attr
->value_tag
)
1633 case IPP_TAG_STRING
:
1634 case IPP_TAG_TEXTLANG
:
1635 case IPP_TAG_NAMELANG
:
1638 case IPP_TAG_KEYWORD
:
1640 case IPP_TAG_URISCHEME
:
1641 case IPP_TAG_CHARSET
:
1642 case IPP_TAG_LANGUAGE
:
1643 case IPP_TAG_MIMETYPE
:
1645 * Free old strings...
1648 for (i
= 0; i
< attr
->num_values
; i
++)
1650 _cupsStrFree(attr
->values
[i
].string
.text
);
1651 attr
->values
[i
].string
.text
= NULL
;
1652 if (attr
->values
[i
].string
.language
)
1654 _cupsStrFree(attr
->values
[i
].string
.language
);
1655 attr
->values
[i
].string
.language
= NULL
;
1664 * Use the default connection hostname instead...
1667 attr
->value_tag
= IPP_TAG_NAME
;
1668 attr
->num_values
= 1;
1669 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1672 attr
->group_tag
= IPP_TAG_JOB
;
1677 * No job-originating-host-name attribute, so use the hostname from
1681 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1682 "job-originating-host-name", NULL
, con
->http
.hostname
);
1685 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1687 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1688 "time-at-processing", 0);
1689 attr
->value_tag
= IPP_TAG_NOVALUE
;
1690 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1691 "time-at-completed", 0);
1692 attr
->value_tag
= IPP_TAG_NOVALUE
;
1695 * Add remaining job attributes...
1698 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1699 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1700 "job-state", IPP_JOB_STOPPED
);
1701 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1702 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1703 "job-state-reasons", NULL
, "job-incoming");
1704 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1705 "job-media-sheets-completed", 0);
1706 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1709 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1710 IPP_TAG_INTEGER
)) != NULL
)
1711 attr
->values
[0].integer
= 0;
1713 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1715 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1716 IPP_TAG_KEYWORD
)) == NULL
)
1717 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1720 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1721 printer
->options
)) == NULL
)
1724 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1725 "job-hold-until", NULL
, val
);
1727 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1730 * Hold job until specified time...
1733 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1735 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1736 job
->state_value
= IPP_JOB_HELD
;
1738 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1740 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1742 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1743 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1744 job
->state_value
= IPP_JOB_HELD
;
1748 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1749 job
->state_value
= IPP_JOB_PENDING
;
1751 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1754 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1757 * Add job sheets options...
1760 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1761 IPP_TAG_ZERO
)) == NULL
)
1763 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1764 "Adding default job-sheets values \"%s,%s\"...",
1765 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1767 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1769 attr
->values
[0].string
.text
= _cupsStrRetain(printer
->job_sheets
[0]);
1770 attr
->values
[1].string
.text
= _cupsStrRetain(printer
->job_sheets
[1]);
1773 job
->job_sheets
= attr
;
1776 * Enforce classification level if set...
1781 cupsdLogMessage(CUPSD_LOG_INFO
,
1782 "Classification=\"%s\", ClassifyOverride=%d",
1783 Classification
? Classification
: "(null)",
1786 if (ClassifyOverride
)
1788 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1789 (attr
->num_values
== 1 ||
1790 !strcmp(attr
->values
[1].string
.text
, "none")))
1793 * Force the leading banner to have the classification on it...
1796 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1798 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1799 "job-sheets=\"%s,none\", "
1800 "job-originating-user-name=\"%s\"",
1801 Classification
, job
->username
);
1803 else if (attr
->num_values
== 2 &&
1804 strcmp(attr
->values
[0].string
.text
,
1805 attr
->values
[1].string
.text
) &&
1806 strcmp(attr
->values
[0].string
.text
, "none") &&
1807 strcmp(attr
->values
[1].string
.text
, "none"))
1810 * Can't put two different security markings on the same document!
1813 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1815 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1816 "job-sheets=\"%s,%s\", "
1817 "job-originating-user-name=\"%s\"",
1818 attr
->values
[0].string
.text
,
1819 attr
->values
[1].string
.text
, job
->username
);
1821 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1822 strcmp(attr
->values
[0].string
.text
, "none") &&
1823 (attr
->num_values
== 1 ||
1824 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1825 strcmp(attr
->values
[1].string
.text
, "none"))))
1827 if (attr
->num_values
== 1)
1828 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1829 "CLASSIFICATION OVERRIDDEN "
1830 "job-sheets=\"%s\", "
1831 "job-originating-user-name=\"%s\"",
1832 attr
->values
[0].string
.text
, job
->username
);
1834 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1835 "CLASSIFICATION OVERRIDDEN "
1836 "job-sheets=\"%s,%s\",fffff "
1837 "job-originating-user-name=\"%s\"",
1838 attr
->values
[0].string
.text
,
1839 attr
->values
[1].string
.text
, job
->username
);
1842 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1843 (attr
->num_values
== 1 ||
1844 strcmp(attr
->values
[1].string
.text
, Classification
)))
1847 * Force the banner to have the classification on it...
1850 if (attr
->num_values
> 1 &&
1851 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1853 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1854 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1858 if (attr
->num_values
== 1 ||
1859 strcmp(attr
->values
[0].string
.text
, "none"))
1860 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1862 if (attr
->num_values
> 1 &&
1863 strcmp(attr
->values
[1].string
.text
, "none"))
1864 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1867 if (attr
->num_values
> 1)
1868 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1869 "CLASSIFICATION FORCED "
1870 "job-sheets=\"%s,%s\", "
1871 "job-originating-user-name=\"%s\"",
1872 attr
->values
[0].string
.text
,
1873 attr
->values
[1].string
.text
, job
->username
);
1875 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1876 "CLASSIFICATION FORCED "
1877 "job-sheets=\"%s\", "
1878 "job-originating-user-name=\"%s\"",
1879 Classification
, job
->username
);
1884 * See if we need to add the starting sheet...
1887 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1889 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1890 attr
->values
[0].string
.text
);
1892 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1894 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1895 "Aborting job because the start banner could not be "
1900 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1903 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1904 IPP_TAG_ZERO
)) != NULL
)
1905 job
->job_sheets
= attr
;
1908 * Fill in the response info...
1911 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1912 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1913 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1916 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1918 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1920 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1921 NULL
, job
->reasons
->values
[0].string
.text
);
1923 con
->response
->request
.status
.status_code
= IPP_OK
;
1926 * Add any job subscriptions...
1929 add_job_subscriptions(con
, job
);
1932 * Set all but the first two attributes to the job attributes group...
1935 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1936 attr
->group_tag
= IPP_TAG_JOB
;
1939 * Fire the "job created" event...
1942 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1945 * Return the new job...
1953 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1957 add_job_subscriptions(
1958 cupsd_client_t
*con
, /* I - Client connection */
1959 cupsd_job_t
*job
) /* I - Newly created job */
1961 int i
; /* Looping var */
1962 ipp_attribute_t
*prev
, /* Previous attribute */
1963 *next
, /* Next attribute */
1964 *attr
; /* Current attribute */
1965 cupsd_subscription_t
*sub
; /* Subscription object */
1966 const char *recipient
, /* notify-recipient-uri */
1967 *pullmethod
; /* notify-pull-method */
1968 ipp_attribute_t
*user_data
; /* notify-user-data */
1969 int interval
; /* notify-time-interval */
1970 unsigned mask
; /* notify-events */
1974 * Find the first subscription group attribute; return if we have
1978 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1979 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1986 * Process the subscription attributes in the request...
1995 mask
= CUPSD_EVENT_NONE
;
1997 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1999 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2000 attr
->value_tag
== IPP_TAG_URI
)
2003 * Validate the recipient scheme against the ServerBin/notifier
2007 char notifier
[1024], /* Notifier filename */
2008 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2009 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2010 host
[HTTP_MAX_URI
], /* Host portion of URI */
2011 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2012 int port
; /* Port portion of URI */
2015 recipient
= attr
->values
[0].string
.text
;
2017 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2018 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2019 host
, sizeof(host
), &port
,
2020 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2022 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2023 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2024 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2025 "notify-status-code", IPP_URI_SCHEME
);
2029 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2031 if (access(notifier
, X_OK
))
2033 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2034 _("notify-recipient-uri URI \"%s\" uses unknown "
2035 "scheme."), recipient
);
2036 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2037 "notify-status-code", IPP_URI_SCHEME
);
2041 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2043 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2044 _("notify-recipient-uri URI \"%s\" is already used."),
2046 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2047 "notify-status-code", IPP_ATTRIBUTES
);
2051 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2052 attr
->value_tag
== IPP_TAG_KEYWORD
)
2054 pullmethod
= attr
->values
[0].string
.text
;
2056 if (strcmp(pullmethod
, "ippget"))
2058 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2059 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2060 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2061 "notify-status-code", IPP_ATTRIBUTES
);
2065 else if (!strcmp(attr
->name
, "notify-charset") &&
2066 attr
->value_tag
== IPP_TAG_CHARSET
&&
2067 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2068 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2070 send_ipp_status(con
, IPP_CHARSET
,
2071 _("Character set \"%s\" not supported."),
2072 attr
->values
[0].string
.text
);
2075 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2076 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2077 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2079 send_ipp_status(con
, IPP_CHARSET
,
2080 _("Language \"%s\" not supported."),
2081 attr
->values
[0].string
.text
);
2084 else if (!strcmp(attr
->name
, "notify-user-data") &&
2085 attr
->value_tag
== IPP_TAG_STRING
)
2087 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2089 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2090 _("The notify-user-data value is too large "
2091 "(%d > 63 octets)."),
2092 attr
->values
[0].unknown
.length
);
2098 else if (!strcmp(attr
->name
, "notify-events") &&
2099 attr
->value_tag
== IPP_TAG_KEYWORD
)
2101 for (i
= 0; i
< attr
->num_values
; i
++)
2102 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2104 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2106 send_ipp_status(con
, IPP_BAD_REQUEST
,
2107 _("The notify-lease-duration attribute cannot be "
2108 "used with job subscriptions."));
2111 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2112 attr
->value_tag
== IPP_TAG_INTEGER
)
2113 interval
= attr
->values
[0].integer
;
2118 if (!recipient
&& !pullmethod
)
2121 if (mask
== CUPSD_EVENT_NONE
)
2122 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2124 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2125 recipient
, 0)) != NULL
)
2127 sub
->interval
= interval
;
2129 cupsdSetString(&sub
->owner
, job
->username
);
2133 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2134 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2135 sub
->user_data_len
);
2138 ippAddSeparator(con
->response
);
2139 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2140 "notify-subscription-id", sub
->id
);
2142 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2150 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2153 * Remove all of the subscription attributes from the job request...
2155 * TODO: Optimize this since subscription groups have to come at the
2156 * end of the request...
2159 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2163 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2164 attr
->group_tag
== IPP_TAG_ZERO
)
2167 * Free and remove this attribute...
2170 ippDeleteAttribute(NULL
, attr
);
2175 job
->attrs
->attrs
= next
;
2181 job
->attrs
->last
= prev
;
2182 job
->attrs
->current
= prev
;
2187 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2189 * See RFC 4122 for the definition of UUIDs and the format.
2193 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2195 char uuid
[64]; /* job-uuid string */
2199 * Add a job-uuid attribute if none exists...
2202 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2203 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2204 _httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2205 uuid
, sizeof(uuid
)));
2210 * 'add_printer()' - Add a printer to the system.
2214 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2215 ipp_attribute_t
*uri
) /* I - URI of printer */
2217 http_status_t status
; /* Policy status */
2218 int i
; /* Looping var */
2219 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2220 username
[HTTP_MAX_URI
], /* Username portion of URI */
2221 host
[HTTP_MAX_URI
], /* Host portion of URI */
2222 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2223 int port
; /* Port portion of URI */
2224 cupsd_printer_t
*printer
; /* Printer/class */
2225 ipp_attribute_t
*attr
; /* Printer attribute */
2226 cups_file_t
*fp
; /* Script/PPD file */
2227 char line
[1024]; /* Line from file... */
2228 char srcfile
[1024], /* Source Script/PPD file */
2229 dstfile
[1024]; /* Destination Script/PPD file */
2230 int modify
; /* Non-zero if we are modifying */
2231 int changed_driver
, /* Changed the PPD/interface script? */
2232 need_restart_job
, /* Need to restart job? */
2233 set_device_uri
, /* Did we set the device URI? */
2234 set_port_monitor
; /* Did we set the port monitor? */
2237 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2238 con
->http
.fd
, uri
->values
[0].string
.text
);
2241 * Do we have a valid URI?
2244 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2245 sizeof(scheme
), username
, sizeof(username
), host
,
2246 sizeof(host
), &port
, resource
, sizeof(resource
));
2248 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2251 * No, return an error...
2254 send_ipp_status(con
, IPP_BAD_REQUEST
,
2255 _("The printer-uri must be of the form "
2256 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2261 * Do we have a valid printer name?
2264 if (!validate_name(resource
+ 10))
2267 * No, return an error...
2270 send_ipp_status(con
, IPP_BAD_REQUEST
,
2271 _("The printer-uri \"%s\" contains invalid characters."),
2272 uri
->values
[0].string
.text
);
2277 * See if the printer already exists; if not, create a new printer...
2280 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2283 * Printer doesn't exist; see if we have a class of the same name...
2286 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2289 * Yes, return an error...
2292 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2293 _("A class named \"%s\" already exists."),
2299 * No, check the default policy then add the printer...
2302 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2304 send_http_error(con
, status
, NULL
);
2308 printer
= cupsdAddPrinter(resource
+ 10);
2311 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2314 send_http_error(con
, status
, printer
);
2321 * Look for attributes and copy them over as needed...
2325 need_restart_job
= 0;
2327 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2328 IPP_TAG_TEXT
)) != NULL
)
2329 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2331 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2332 IPP_TAG_TEXT
)) != NULL
)
2333 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2337 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2338 IPP_TAG_URI
)) != NULL
)
2341 * Do we have a valid device URI?
2344 http_uri_status_t uri_status
; /* URI separation status */
2345 char old_device_uri
[1024];
2346 /* Old device URI */
2347 static const char * const uri_status_strings
[] =
2350 "Bad arguments to function.",
2351 "Bad resource path.",
2353 "Bad hostname/address.",
2354 "Bad username/password.",
2358 "Missing URI scheme.",
2359 "Unknown URI scheme",
2360 "Missing resource path."
2364 need_restart_job
= 1;
2366 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2367 attr
->values
[0].string
.text
,
2368 scheme
, sizeof(scheme
),
2369 username
, sizeof(username
),
2370 host
, sizeof(host
), &port
,
2371 resource
, sizeof(resource
));
2373 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2374 "%s device-uri: %s", printer
->name
,
2375 uri_status_strings
[uri_status
- HTTP_URI_STATUS_OVERFLOW
]);
2377 if (uri_status
< HTTP_URI_OK
)
2379 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2380 attr
->values
[0].string
.text
);
2384 if (!strcmp(scheme
, "file"))
2387 * See if the administrator has enabled file devices...
2390 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2393 * File devices are disabled and the URL is not file:/dev/null...
2396 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2397 _("File device URIs have been disabled. "
2398 "To enable, see the FileDevice directive in "
2399 "\"%s/cups-files.conf\"."),
2407 * See if the backend exists and is executable...
2410 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2411 if (access(srcfile
, X_OK
))
2414 * Could not find device in list!
2417 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2418 _("Bad device-uri scheme \"%s\"."), scheme
);
2423 if (printer
->sanitized_device_uri
)
2424 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2425 sizeof(old_device_uri
));
2427 old_device_uri
[0] = '\0';
2429 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2431 cupsdLogMessage(CUPSD_LOG_INFO
,
2432 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2433 printer
->name
, printer
->sanitized_device_uri
,
2439 set_port_monitor
= 0;
2441 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2442 IPP_TAG_NAME
)) != NULL
)
2444 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2447 need_restart_job
= 1;
2449 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2453 for (i
= 0; i
< supported
->num_values
; i
++)
2454 if (!strcmp(supported
->values
[i
].string
.text
,
2455 attr
->values
[0].string
.text
))
2459 if (!supported
|| i
>= supported
->num_values
)
2461 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2462 attr
->values
[0].string
.text
);
2466 cupsdLogMessage(CUPSD_LOG_INFO
,
2467 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2468 printer
->name
, attr
->values
[0].string
.text
,
2469 printer
->port_monitor
? printer
->port_monitor
: "none");
2471 if (strcmp(attr
->values
[0].string
.text
, "none"))
2472 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2474 cupsdClearString(&printer
->port_monitor
);
2476 set_port_monitor
= 1;
2479 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2480 IPP_TAG_BOOLEAN
)) != NULL
&&
2481 attr
->values
[0].boolean
!= printer
->accepting
)
2483 cupsdLogMessage(CUPSD_LOG_INFO
,
2484 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2485 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2487 printer
->accepting
= attr
->values
[0].boolean
;
2489 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2490 "%s accepting jobs.",
2491 printer
->accepting
? "Now" : "No longer");
2494 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2495 IPP_TAG_BOOLEAN
)) != NULL
)
2497 if (attr
->values
[0].boolean
&&
2498 printer
->num_auth_info_required
== 1 &&
2499 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2501 send_ipp_status(con
, IPP_BAD_REQUEST
,
2502 _("Cannot share a remote Kerberized printer."));
2506 if (printer
->shared
&& !attr
->values
[0].boolean
)
2507 cupsdDeregisterPrinter(printer
, 1);
2509 cupsdLogMessage(CUPSD_LOG_INFO
,
2510 "Setting %s printer-is-shared to %d (was %d.)",
2511 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2513 printer
->shared
= attr
->values
[0].boolean
;
2516 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2517 IPP_TAG_ENUM
)) != NULL
)
2519 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2520 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2522 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2523 attr
->values
[0].integer
);
2527 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2528 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2530 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2531 cupsdStopPrinter(printer
, 0);
2534 need_restart_job
= 1;
2535 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2539 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2540 IPP_TAG_TEXT
)) != NULL
)
2542 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2543 sizeof(printer
->state_message
));
2545 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2546 printer
->state_message
);
2549 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2550 IPP_TAG_KEYWORD
)) != NULL
)
2552 if (attr
->num_values
>
2553 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2555 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2556 _("Too many printer-state-reasons values (%d > %d)."),
2558 (int)(sizeof(printer
->reasons
) /
2559 sizeof(printer
->reasons
[0])));
2563 for (i
= 0; i
< printer
->num_reasons
; i
++)
2564 _cupsStrFree(printer
->reasons
[i
]);
2566 printer
->num_reasons
= 0;
2567 for (i
= 0; i
< attr
->num_values
; i
++)
2569 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2572 printer
->reasons
[printer
->num_reasons
] =
2573 _cupsStrRetain(attr
->values
[i
].string
.text
);
2574 printer
->num_reasons
++;
2576 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2577 printer
->state
!= IPP_PRINTER_STOPPED
)
2579 cupsdLogMessage(CUPSD_LOG_INFO
,
2580 "Setting %s printer-state to %d (was %d.)",
2581 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2582 cupsdStopPrinter(printer
, 0);
2586 if (PrintcapFormat
== PRINTCAP_PLIST
)
2587 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2589 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2590 "Printer \"%s\" state changed.", printer
->name
);
2593 set_printer_defaults(con
, printer
);
2595 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2596 IPP_TAG_KEYWORD
)) != NULL
)
2597 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2600 * See if we have all required attributes...
2603 if (!printer
->device_uri
)
2604 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2607 * See if we have an interface script or PPD file attached to the request...
2612 need_restart_job
= 1;
2615 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2617 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2620 * Yes; get the first line from it...
2624 cupsFileGets(fp
, line
, sizeof(line
));
2628 * Then see what kind of file it is...
2631 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2634 if (!strncmp(line
, "*PPD-Adobe", 10))
2637 * The new file is a PPD file, so remove any old interface script
2638 * that might be lying around...
2646 * This must be an interface script, so move the file over to the
2647 * interfaces directory and make it executable...
2650 if (copy_file(srcfile
, dstfile
))
2652 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2653 _("Unable to copy interface script - %s"),
2658 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2659 "Copied interface script successfully");
2660 chmod(dstfile
, 0755);
2663 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2666 if (!strncmp(line
, "*PPD-Adobe", 10))
2669 * The new file is a PPD file, so move the file over to the
2670 * ppd directory and make it readable by all...
2673 if (copy_file(srcfile
, dstfile
))
2675 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2676 _("Unable to copy PPD file - %s"),
2681 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2682 "Copied PPD file successfully");
2683 chmod(dstfile
, 0644);
2688 * This must be an interface script, so remove any old PPD file that
2689 * may be lying around...
2696 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2697 IPP_TAG_NAME
)) != NULL
)
2699 need_restart_job
= 1;
2702 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2705 * Raw driver, remove any existing PPD or interface script files.
2708 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2712 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2722 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2726 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2729 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2731 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2735 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2736 "Copied PPD file successfully");
2737 chmod(dstfile
, 0644);
2744 * If we changed the PPD/interface script, then remove the printer's cache
2745 * file and clear the printer-state-reasons...
2748 char cache_name
[1024]; /* Cache filename for printer attrs */
2750 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2754 cupsdSetPrinterReasons(printer
, "none");
2757 * (Re)register color profiles...
2760 cupsdRegisterColor(printer
);
2764 * If we set the device URI but not the port monitor, check which port
2765 * monitor to use by default...
2768 if (set_device_uri
&& !set_port_monitor
)
2770 ppd_file_t
*ppd
; /* PPD file */
2771 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2774 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2775 sizeof(scheme
), username
, sizeof(username
), host
,
2776 sizeof(host
), &port
, resource
, sizeof(resource
));
2778 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2780 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2782 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2784 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2785 if (!strcmp(scheme
, ppdattr
->spec
))
2787 cupsdLogMessage(CUPSD_LOG_INFO
,
2788 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2789 printer
->name
, ppdattr
->value
,
2790 printer
->port_monitor
? printer
->port_monitor
2793 if (strcmp(ppdattr
->value
, "none"))
2794 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2796 cupsdClearString(&printer
->port_monitor
);
2806 * Update the printer attributes and return...
2809 cupsdSetPrinterAttrs(printer
);
2810 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2812 if (need_restart_job
&& printer
->job
)
2815 * Restart the current job...
2818 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2819 "Job restarted because the printer was modified.");
2822 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2826 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2827 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2828 printer
->name
, get_username(con
));
2830 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2831 printer
->name
, get_username(con
));
2835 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2836 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2837 printer
->name
, get_username(con
));
2839 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2840 printer
->name
, get_username(con
));
2843 con
->response
->request
.status
.status_code
= IPP_OK
;
2848 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2849 * based upon the printer state...
2853 add_printer_state_reasons(
2854 cupsd_client_t
*con
, /* I - Client connection */
2855 cupsd_printer_t
*p
) /* I - Printer info */
2857 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2858 "add_printer_state_reasons(%p[%d], %p[%s])",
2859 con
, con
->http
.fd
, p
, p
->name
);
2861 if (p
->num_reasons
== 0)
2862 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2863 "printer-state-reasons", NULL
, "none");
2865 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2866 "printer-state-reasons", p
->num_reasons
, NULL
,
2867 (const char * const *)p
->reasons
);
2872 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2873 * the specified printer or class.
2877 add_queued_job_count(
2878 cupsd_client_t
*con
, /* I - Client connection */
2879 cupsd_printer_t
*p
) /* I - Printer or class */
2881 int count
; /* Number of jobs on destination */
2884 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2885 con
, con
->http
.fd
, p
, p
->name
);
2887 count
= cupsdGetPrinterJobCount(p
->name
);
2889 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2890 "queued-job-count", count
);
2895 * 'apply_printer_defaults()' - Apply printer default options to a job.
2899 apply_printer_defaults(
2900 cupsd_printer_t
*printer
, /* I - Printer */
2901 cupsd_job_t
*job
) /* I - Job */
2903 int i
, /* Looping var */
2904 num_options
; /* Number of default options */
2905 cups_option_t
*options
, /* Default options */
2906 *option
; /* Current option */
2910 * Collect all of the default options and add the missing ones to the
2914 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2915 option
= printer
->options
;
2918 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2920 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2925 * Encode these options as attributes in the job object...
2928 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2929 cupsFreeOptions(num_options
, options
);
2934 * 'authenticate_job()' - Set job authentication info.
2938 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2939 ipp_attribute_t
*uri
) /* I - Job URI */
2941 ipp_attribute_t
*attr
, /* job-id attribute */
2942 *auth_info
; /* auth-info attribute */
2943 int jobid
; /* Job ID */
2944 cupsd_job_t
*job
; /* Current job */
2945 char scheme
[HTTP_MAX_URI
],
2946 /* Method portion of URI */
2947 username
[HTTP_MAX_URI
],
2948 /* Username portion of URI */
2950 /* Host portion of URI */
2951 resource
[HTTP_MAX_URI
];
2952 /* Resource portion of URI */
2953 int port
; /* Port portion of URI */
2956 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2957 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
2960 * Start with "everything is OK" status...
2963 con
->response
->request
.status
.status_code
= IPP_OK
;
2966 * See if we have a job URI or a printer URI...
2969 if (!strcmp(uri
->name
, "printer-uri"))
2972 * Got a printer URI; see if we also have a job-id attribute...
2975 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2976 IPP_TAG_INTEGER
)) == NULL
)
2978 send_ipp_status(con
, IPP_BAD_REQUEST
,
2979 _("Got a printer-uri attribute but no job-id."));
2983 jobid
= attr
->values
[0].integer
;
2988 * Got a job URI; parse it to get the job ID...
2991 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2992 sizeof(scheme
), username
, sizeof(username
), host
,
2993 sizeof(host
), &port
, resource
, sizeof(resource
));
2995 if (strncmp(resource
, "/jobs/", 6))
3001 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3002 uri
->values
[0].string
.text
);
3006 jobid
= atoi(resource
+ 6);
3010 * See if the job exists...
3013 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3016 * Nope - return a "not found" error...
3019 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3024 * See if the job has been completed...
3027 if (job
->state_value
!= IPP_JOB_HELD
)
3030 * Return a "not-possible" error...
3033 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3034 _("Job #%d is not held for authentication."),
3040 * See if we have already authenticated...
3043 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3045 if (!con
->username
[0] && !auth_info
)
3047 cupsd_printer_t
*printer
; /* Job destination */
3050 * No auth data. If we need to authenticate via Kerberos, send a
3051 * HTTP auth challenge, otherwise just return an IPP error...
3054 printer
= cupsdFindDest(job
->dest
);
3056 if (printer
&& printer
->num_auth_info_required
> 0 &&
3057 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3058 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3060 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3061 _("No authentication information provided."));
3066 * See if the job is owned by the requesting user...
3069 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3071 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3072 cupsdFindDest(job
->dest
));
3077 * Save the authentication information for this job...
3080 save_auth_info(con
, job
, auth_info
);
3083 * Reset the job-hold-until value to "no-hold"...
3086 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3087 IPP_TAG_KEYWORD
)) == NULL
)
3088 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3092 attr
->value_tag
= IPP_TAG_KEYWORD
;
3093 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
3097 * Release the job and return...
3100 cupsdReleaseJob(job
);
3102 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3104 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3111 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3115 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3116 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3118 int i
; /* Looping var */
3119 http_status_t status
; /* Policy status */
3120 cups_ptype_t dtype
; /* Destination type */
3121 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3122 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3123 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3124 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3125 int port
; /* Port portion of URI */
3126 ipp_attribute_t
*attr
; /* Attribute in request */
3127 const char *username
= NULL
; /* Username */
3128 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3130 cupsd_printer_t
*printer
; /* Printer */
3131 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3132 cupsd_job_t
*job
; /* Job */
3135 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3136 con
->http
.fd
, uri
->values
[0].string
.text
);
3139 * Get the jobs to cancel/purge...
3142 switch (con
->request
->request
.op
.operation_id
)
3144 case IPP_PURGE_JOBS
:
3146 * Get the username (if any) for the jobs we want to cancel (only if
3147 * "my-jobs" is specified...
3150 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3151 IPP_TAG_BOOLEAN
)) != NULL
&&
3152 attr
->values
[0].boolean
)
3154 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3155 IPP_TAG_NAME
)) != NULL
)
3156 username
= attr
->values
[0].string
.text
;
3159 send_ipp_status(con
, IPP_BAD_REQUEST
,
3160 _("Missing requesting-user-name attribute."));
3166 * Look for the "purge-jobs" attribute...
3169 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3170 IPP_TAG_BOOLEAN
)) != NULL
)
3171 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3173 purge
= CUPSD_JOB_PURGE
;
3176 case IPP_CANCEL_MY_JOBS
:
3177 if (con
->username
[0])
3178 username
= con
->username
;
3179 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3180 IPP_TAG_NAME
)) != NULL
)
3181 username
= attr
->values
[0].string
.text
;
3184 send_ipp_status(con
, IPP_BAD_REQUEST
,
3185 _("Missing requesting-user-name attribute."));
3193 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3196 * See if we have a printer URI...
3199 if (strcmp(uri
->name
, "printer-uri"))
3201 send_ipp_status(con
, IPP_BAD_REQUEST
,
3202 _("The printer-uri attribute is required."));
3207 * And if the destination is valid...
3210 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3216 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3217 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3218 hostname
, sizeof(hostname
), &port
,
3219 resource
, sizeof(resource
));
3221 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3222 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3224 send_ipp_status(con
, IPP_NOT_FOUND
,
3225 _("The printer or class does not exist."));
3233 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3235 send_http_error(con
, status
, NULL
);
3241 for (i
= 0; i
< job_ids
->num_values
; i
++)
3243 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3246 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3247 _cups_strcasecmp(job
->username
, username
))
3251 if (i
< job_ids
->num_values
)
3253 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3254 job_ids
->values
[i
].integer
);
3258 for (i
= 0; i
< job_ids
->num_values
; i
++)
3260 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3262 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3263 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3264 "Job canceled by user.");
3267 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3268 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3274 * Cancel all jobs on all printers...
3277 cupsdCancelJobs(NULL
, username
, purge
);
3279 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3280 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3290 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3293 send_http_error(con
, status
, printer
);
3299 for (i
= 0; i
< job_ids
->num_values
; i
++)
3301 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3302 _cups_strcasecmp(job
->dest
, printer
->name
))
3305 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3306 _cups_strcasecmp(job
->username
, username
))
3310 if (i
< job_ids
->num_values
)
3312 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3313 job_ids
->values
[i
].integer
);
3317 for (i
= 0; i
< job_ids
->num_values
; i
++)
3319 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3321 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3322 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3323 "Job canceled by user.");
3326 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3327 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3333 * Cancel all of the jobs on the named printer...
3336 cupsdCancelJobs(printer
->name
, username
, purge
);
3338 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3340 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3345 con
->response
->request
.status
.status_code
= IPP_OK
;
3350 * 'cancel_job()' - Cancel a print job.
3354 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3355 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3357 ipp_attribute_t
*attr
; /* Current attribute */
3358 int jobid
; /* Job ID */
3359 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3360 username
[HTTP_MAX_URI
], /* Username portion of URI */
3361 host
[HTTP_MAX_URI
], /* Host portion of URI */
3362 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3363 int port
; /* Port portion of URI */
3364 cupsd_job_t
*job
; /* Job information */
3365 cups_ptype_t dtype
; /* Destination type (printer/class) */
3366 cupsd_printer_t
*printer
; /* Printer data */
3367 cupsd_jobaction_t purge
; /* Purge the job? */
3370 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3371 con
->http
.fd
, uri
->values
[0].string
.text
);
3374 * See if we have a job URI or a printer URI...
3377 if (!strcmp(uri
->name
, "printer-uri"))
3380 * Got a printer URI; see if we also have a job-id attribute...
3383 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3384 IPP_TAG_INTEGER
)) == NULL
)
3386 send_ipp_status(con
, IPP_BAD_REQUEST
,
3387 _("Got a printer-uri attribute but no job-id."));
3391 if ((jobid
= attr
->values
[0].integer
) == 0)
3394 * Find the current job on the specified printer...
3397 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3403 send_ipp_status(con
, IPP_NOT_FOUND
,
3404 _("The printer or class does not exist."));
3409 * See if there are any pending jobs...
3412 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3414 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3415 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3416 !_cups_strcasecmp(job
->dest
, printer
->name
))
3424 * No, try stopped jobs...
3427 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3429 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3430 if (job
->state_value
== IPP_JOB_STOPPED
&&
3431 !_cups_strcasecmp(job
->dest
, printer
->name
))
3438 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3448 * Got a job URI; parse it to get the job ID...
3451 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3452 sizeof(scheme
), username
, sizeof(username
), host
,
3453 sizeof(host
), &port
, resource
, sizeof(resource
));
3455 if (strncmp(resource
, "/jobs/", 6))
3461 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3462 uri
->values
[0].string
.text
);
3466 jobid
= atoi(resource
+ 6);
3470 * Look for the "purge-job" attribute...
3473 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3474 IPP_TAG_BOOLEAN
)) != NULL
)
3475 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3477 purge
= CUPSD_JOB_DEFAULT
;
3480 * See if the job exists...
3483 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3486 * Nope - return a "not found" error...
3489 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3494 * See if the job is owned by the requesting user...
3497 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3499 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3500 cupsdFindDest(job
->dest
));
3505 * See if the job is already completed, canceled, or aborted; if so,
3506 * we can't cancel...
3509 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3511 switch (job
->state_value
)
3513 case IPP_JOB_CANCELED
:
3514 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3515 _("Job #%d is already canceled - can\'t cancel."),
3519 case IPP_JOB_ABORTED
:
3520 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3521 _("Job #%d is already aborted - can\'t cancel."),
3526 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3527 _("Job #%d is already completed - can\'t cancel."),
3536 * Cancel the job and return...
3539 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3540 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3541 "Job canceled by \"%s\"",
3545 if (purge
== CUPSD_JOB_PURGE
)
3546 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3549 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3552 con
->response
->request
.status
.status_code
= IPP_OK
;
3557 * 'cancel_subscription()' - Cancel a subscription.
3561 cancel_subscription(
3562 cupsd_client_t
*con
, /* I - Client connection */
3563 int sub_id
) /* I - Subscription ID */
3565 http_status_t status
; /* Policy status */
3566 cupsd_subscription_t
*sub
; /* Subscription */
3569 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3570 "cancel_subscription(con=%p[%d], sub_id=%d)",
3571 con
, con
->http
.fd
, sub_id
);
3574 * Is the subscription ID valid?
3577 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3580 * Bad subscription ID...
3583 send_ipp_status(con
, IPP_NOT_FOUND
,
3584 _("Subscription #%d does not exist."), sub_id
);
3592 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3594 con
, sub
->owner
)) != HTTP_OK
)
3596 send_http_error(con
, status
, sub
->dest
);
3601 * Cancel the subscription...
3604 cupsdDeleteSubscription(sub
, 1);
3606 con
->response
->request
.status
.status_code
= IPP_OK
;
3611 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3614 static int /* O - 1 if OK, 0 if not */
3615 check_rss_recipient(
3616 const char *recipient
) /* I - Recipient URI */
3618 cupsd_subscription_t
*sub
; /* Current subscription */
3621 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3623 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3627 * Compare the URIs up to the first ?...
3630 const char *r1
, *r2
;
3632 for (r1
= recipient
, r2
= sub
->recipient
;
3633 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3645 * 'check_quotas()' - Check quotas for a printer and user.
3648 static int /* O - 1 if OK, 0 if forbidden,
3649 -1 if limit reached */
3650 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3651 cupsd_printer_t
*p
) /* I - Printer or class */
3653 char username
[33], /* Username */
3654 *name
; /* Current user name */
3655 cupsd_quota_t
*q
; /* Quota data */
3656 #ifdef HAVE_MBR_UID_TO_UUID
3658 * Use Apple membership APIs which require that all names represent
3659 * valid user account or group records accessible by the server.
3662 uuid_t usr_uuid
; /* UUID for job requesting user */
3663 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3664 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3665 int mbr_err
; /* Error from membership function */
3666 int is_member
; /* Is this user a member? */
3669 * Use standard POSIX APIs for checking users and groups...
3672 struct passwd
*pw
; /* User password data */
3673 #endif /* HAVE_MBR_UID_TO_UUID */
3676 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3677 con
, con
->http
.fd
, p
, p
->name
);
3680 * Figure out who is printing...
3683 strlcpy(username
, get_username(con
), sizeof(username
));
3685 if ((name
= strchr(username
, '@')) != NULL
)
3686 *name
= '\0'; /* Strip @REALM */
3689 * Check global active job limits for printers and users...
3692 if (MaxJobsPerPrinter
)
3695 * Check if there are too many pending jobs on this printer...
3698 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3700 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3709 * Check if there are too many pending jobs for this user...
3712 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3714 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3721 * Check against users...
3724 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3727 if (cupsArrayCount(p
->users
))
3729 #ifdef HAVE_MBR_UID_TO_UUID
3731 * Get UUID for job requesting user...
3734 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3740 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3741 "check_quotas: UUID lookup failed for user \"%s\"",
3743 cupsdLogMessage(CUPSD_LOG_INFO
,
3744 "Denying user \"%s\" access to printer \"%s\" "
3745 "(unknown user)...",
3751 * Get UID and GID of requesting user...
3754 pw
= getpwnam(username
);
3756 #endif /* HAVE_MBR_UID_TO_UUID */
3758 for (name
= (char *)cupsArrayFirst(p
->users
);
3760 name
= (char *)cupsArrayNext(p
->users
))
3764 * Check group membership...
3767 #ifdef HAVE_MBR_UID_TO_UUID
3770 if (uuid_parse(name
+ 2, grp_uuid
))
3771 uuid_clear(grp_uuid
);
3773 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3776 * Invalid ACL entries are ignored for matching; just record a
3777 * warning in the log...
3780 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3781 "check_quotas: UUID lookup failed for ACL entry "
3782 "\"%s\" (err=%d)", name
, mbr_err
);
3783 cupsdLogMessage(CUPSD_LOG_WARN
,
3784 "Access control entry \"%s\" not a valid group name; "
3785 "entry ignored", name
);
3788 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3792 * At this point, there should be no errors, but check anyways...
3795 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3796 "check_quotas: group \"%s\" membership check "
3797 "failed (err=%d)", name
+ 1, mbr_err
);
3802 * Stop if we found a match...
3809 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3811 #endif /* HAVE_MBR_UID_TO_UUID */
3813 #ifdef HAVE_MBR_UID_TO_UUID
3818 if (uuid_parse(name
+ 1, usr2_uuid
))
3819 uuid_clear(usr2_uuid
);
3821 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3824 * Invalid ACL entries are ignored for matching; just record a
3825 * warning in the log...
3828 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3829 "check_quotas: UUID lookup failed for ACL entry "
3830 "\"%s\" (err=%d)", name
, mbr_err
);
3831 cupsdLogMessage(CUPSD_LOG_WARN
,
3832 "Access control entry \"%s\" not a valid user name; "
3833 "entry ignored", name
);
3836 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3840 else if (!_cups_strcasecmp(username
, name
))
3842 #endif /* HAVE_MBR_UID_TO_UUID */
3844 if ((name
!= NULL
) == p
->deny_users
)
3846 cupsdLogMessage(CUPSD_LOG_INFO
,
3847 "Denying user \"%s\" access to printer \"%s\"...",
3857 if (p
->k_limit
|| p
->page_limit
)
3859 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3861 cupsdLogMessage(CUPSD_LOG_ERROR
,
3862 "Unable to allocate quota data for user \"%s\"",
3867 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3868 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3870 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3877 * If we have gotten this far, we're done!
3885 * 'close_job()' - Close a multi-file job.
3889 close_job(cupsd_client_t
*con
, /* I - Client connection */
3890 ipp_attribute_t
*uri
) /* I - Printer URI */
3892 cupsd_job_t
*job
; /* Job */
3893 ipp_attribute_t
*attr
; /* Attribute */
3894 char job_uri
[HTTP_MAX_URI
],
3896 username
[256]; /* User name */
3899 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3900 con
->http
.fd
, uri
->values
[0].string
.text
);
3903 * See if we have a job URI or a printer URI...
3906 if (strcmp(uri
->name
, "printer-uri"))
3909 * job-uri is not supported by Close-Job!
3912 send_ipp_status(con
, IPP_BAD_REQUEST
,
3913 _("Close-Job doesn't support the job-uri attribute."));
3918 * Got a printer URI; see if we also have a job-id attribute...
3921 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3922 IPP_TAG_INTEGER
)) == NULL
)
3924 send_ipp_status(con
, IPP_BAD_REQUEST
,
3925 _("Got a printer-uri attribute but no job-id."));
3929 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3932 * Nope - return a "not found" error...
3935 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3936 attr
->values
[0].integer
);
3941 * See if the job is owned by the requesting user...
3944 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3946 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3947 cupsdFindDest(job
->dest
));
3952 * Add any ending sheet...
3955 if (cupsdTimeoutJob(job
))
3958 if (job
->state_value
== IPP_JOB_STOPPED
)
3960 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3961 job
->state_value
= IPP_JOB_PENDING
;
3963 else if (job
->state_value
== IPP_JOB_HELD
)
3965 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3966 IPP_TAG_KEYWORD
)) == NULL
)
3967 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3969 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3971 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3972 job
->state_value
= IPP_JOB_PENDING
;
3977 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3980 * Fill in the response info...
3983 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3984 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3985 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3988 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3990 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
3993 con
->response
->request
.status
.status_code
= IPP_OK
;
3996 * Start the job if necessary...
4004 * 'copy_attrs()' - Copy attributes from one request to another.
4008 copy_attrs(ipp_t
*to
, /* I - Destination request */
4009 ipp_t
*from
, /* I - Source request */
4010 cups_array_t
*ra
, /* I - Requested attributes */
4011 ipp_tag_t group
, /* I - Group to copy */
4012 int quickcopy
, /* I - Do a quick copy? */
4013 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4015 ipp_attribute_t
*fromattr
; /* Source attribute */
4018 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4019 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4020 to
, from
, ra
, group
, quickcopy
);
4025 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4028 * Filter attributes as needed...
4031 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4032 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4035 if (!strcmp(fromattr
->name
, "document-password") ||
4036 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4037 !strcmp(fromattr
->name
, "job-password") ||
4038 !strcmp(fromattr
->name
, "job-password-encryption") ||
4039 !strcmp(fromattr
->name
, "job-printer-uri"))
4043 (cupsArrayFind(exclude
, fromattr
->name
) ||
4044 cupsArrayFind(exclude
, "all")))
4047 * We need to exclude this attribute for security reasons; we require the
4048 * job-id attribute regardless of the security settings for IPP
4051 * The job-printer-uri attribute is handled by copy_job_attrs().
4053 * Subscription attribute security is handled by copy_subscription_attrs().
4056 if (strcmp(fromattr
->name
, "job-id"))
4060 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4063 * Don't send collection attributes by default to IPP/1.x clients
4064 * since many do not support collections. Also don't send
4065 * media-col-database unless specifically requested by the client.
4068 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4070 (to
->request
.status
.version
[0] == 1 ||
4071 !strcmp(fromattr
->name
, "media-col-database")))
4074 ippCopyAttribute(to
, fromattr
, quickcopy
);
4081 * 'copy_banner()' - Copy a banner file to the requests directory for the
4085 static int /* O - Size of banner file in kbytes */
4086 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4087 cupsd_job_t
*job
, /* I - Job information */
4088 const char *name
) /* I - Name of banner */
4090 int i
; /* Looping var */
4091 int kbytes
; /* Size of banner file in kbytes */
4092 char filename
[1024]; /* Job filename */
4093 cupsd_banner_t
*banner
; /* Pointer to banner */
4094 cups_file_t
*in
; /* Input file */
4095 cups_file_t
*out
; /* Output file */
4096 int ch
; /* Character from file */
4097 char attrname
[255], /* Name of attribute */
4098 *s
; /* Pointer into name */
4099 ipp_attribute_t
*attr
; /* Attribute */
4102 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4103 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4104 con
, con
? con
->http
.fd
: -1, job
, job
->id
,
4105 name
? name
: "(null)");
4108 * Find the banner; return if not found or "none"...
4111 if (!name
|| !strcmp(name
, "none") ||
4112 (banner
= cupsdFindBanner(name
)) == NULL
)
4116 * Open the banner and job files...
4119 if (add_file(con
, job
, banner
->filetype
, 0))
4122 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4124 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4126 cupsdLogMessage(CUPSD_LOG_ERROR
,
4127 "Unable to create banner job file %s - %s",
4128 filename
, strerror(errno
));
4133 fchmod(cupsFileNumber(out
), 0640);
4134 fchown(cupsFileNumber(out
), RunUser
, Group
);
4137 * Try the localized banner file under the subdirectory...
4140 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4142 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4145 * Convert ll-cc to ll_CC...
4149 attrname
[3] = toupper(attrname
[3] & 255);
4150 attrname
[4] = toupper(attrname
[4] & 255);
4153 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4156 if (access(filename
, 0) && strlen(attrname
) > 2)
4159 * Wasn't able to find "ll_CC" locale file; try the non-national
4160 * localization banner directory.
4165 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4169 if (access(filename
, 0))
4172 * Use the non-localized banner file.
4175 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4178 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4182 cupsdLogMessage(CUPSD_LOG_ERROR
,
4183 "Unable to open banner template file %s - %s",
4184 filename
, strerror(errno
));
4190 * Parse the file to the end...
4193 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4197 * Get an attribute name...
4200 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4201 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4203 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4213 * Ignore { followed by stuff that is not an attribute name...
4216 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4221 * See if it is defined...
4224 if (attrname
[0] == '?')
4229 if (!strcmp(s
, "printer-name"))
4231 cupsFilePuts(out
, job
->dest
);
4234 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4237 * See if we have a leading question mark...
4240 if (attrname
[0] != '?')
4243 * Nope, write to file as-is; probably a PostScript procedure...
4246 cupsFilePrintf(out
, "{%s}", attrname
);
4253 * Output value(s)...
4256 for (i
= 0; i
< attr
->num_values
; i
++)
4259 cupsFilePutChar(out
, ',');
4261 switch (attr
->value_tag
)
4263 case IPP_TAG_INTEGER
:
4265 if (!strncmp(s
, "time-at-", 8))
4267 struct timeval tv
; /* Time value */
4269 tv
.tv_sec
= attr
->values
[i
].integer
;
4272 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4275 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4278 case IPP_TAG_BOOLEAN
:
4279 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4282 case IPP_TAG_NOVALUE
:
4283 cupsFilePuts(out
, "novalue");
4286 case IPP_TAG_RANGE
:
4287 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4288 attr
->values
[i
].range
.upper
);
4291 case IPP_TAG_RESOLUTION
:
4292 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4293 attr
->values
[i
].resolution
.yres
,
4294 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4299 case IPP_TAG_STRING
:
4302 case IPP_TAG_KEYWORD
:
4303 case IPP_TAG_CHARSET
:
4304 case IPP_TAG_LANGUAGE
:
4305 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4308 * Need to quote strings for PS banners...
4313 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4315 if (*p
== '(' || *p
== ')' || *p
== '\\')
4317 cupsFilePutChar(out
, '\\');
4318 cupsFilePutChar(out
, *p
);
4320 else if (*p
< 32 || *p
> 126)
4321 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4323 cupsFilePutChar(out
, *p
);
4327 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4331 break; /* anti-compiler-warning-code */
4335 else if (ch
== '\\') /* Quoted char */
4337 ch
= cupsFileGetChar(in
);
4339 if (ch
!= '{') /* Only do special handling for \{ */
4340 cupsFilePutChar(out
, '\\');
4342 cupsFilePutChar(out
, ch
);
4345 cupsFilePutChar(out
, ch
);
4349 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4351 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4352 IPP_TAG_INTEGER
)) != NULL
)
4353 attr
->values
[0].integer
+= kbytes
;
4362 * 'copy_file()' - Copy a PPD file or interface script...
4365 static int /* O - 0 = success, -1 = error */
4366 copy_file(const char *from
, /* I - Source file */
4367 const char *to
) /* I - Destination file */
4369 cups_file_t
*src
, /* Source file */
4370 *dst
; /* Destination file */
4371 int bytes
; /* Bytes to read/write */
4372 char buffer
[2048]; /* Copy buffer */
4375 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4378 * Open the source and destination file for a copy...
4381 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4384 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4391 * Copy the source file to the destination...
4394 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4395 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
4403 * Close both files and return...
4408 return (cupsFileClose(dst
));
4413 * 'copy_model()' - Copy a PPD model file, substituting default values
4417 static int /* O - 0 = success, -1 = error */
4418 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4419 const char *from
, /* I - Source file */
4420 const char *to
) /* I - Destination file */
4422 fd_set input
; /* select() input set */
4423 struct timeval timeout
; /* select() timeout */
4424 int maxfd
; /* Max file descriptor for select() */
4425 char tempfile
[1024]; /* Temporary PPD file */
4426 int tempfd
; /* Temporary PPD file descriptor */
4427 int temppid
; /* Process ID of cups-driverd */
4428 int temppipe
[2]; /* Temporary pipes */
4429 char *argv
[4], /* Command-line arguments */
4430 *envp
[MAX_ENV
]; /* Environment */
4431 cups_file_t
*src
, /* Source file */
4432 *dst
; /* Destination file */
4433 ppd_file_t
*ppd
; /* PPD file */
4434 int bytes
, /* Bytes from pipe */
4435 total
; /* Total bytes from pipe */
4436 char buffer
[2048]; /* Copy buffer */
4437 int i
; /* Looping var */
4438 char option
[PPD_MAX_NAME
], /* Option name */
4439 choice
[PPD_MAX_NAME
]; /* Choice name */
4440 ppd_size_t
*size
; /* Default size */
4441 int num_defaults
; /* Number of default options */
4442 cups_option_t
*defaults
; /* Default options */
4443 char cups_protocol
[PPD_MAX_LINE
];
4444 /* cupsProtocol attribute */
4447 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4448 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4452 * Run cups-driverd to get the PPD file...
4455 argv
[0] = "cups-driverd";
4457 argv
[2] = (char *)from
;
4460 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4462 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4463 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4464 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4465 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4468 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4469 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4471 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4472 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4483 * Wait up to 30 seconds for the PPD file to be copied...
4488 if (temppipe
[0] > CGIPipes
[0])
4489 maxfd
= temppipe
[0] + 1;
4491 maxfd
= CGIPipes
[0] + 1;
4496 * See if we have data ready...
4500 FD_SET(temppipe
[0], &input
);
4501 FD_SET(CGIPipes
[0], &input
);
4503 timeout
.tv_sec
= 30;
4504 timeout
.tv_usec
= 0;
4506 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4516 * We have timed out...
4522 if (FD_ISSET(temppipe
[0], &input
))
4525 * Read the PPD file from the pipe, and write it to the PPD file.
4528 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4530 if (write(tempfd
, buffer
, bytes
) < bytes
)
4539 if (FD_ISSET(CGIPipes
[0], &input
))
4549 * No data from cups-deviced...
4552 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4558 * Open the source file for a copy...
4561 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4568 * Read the source file and see what page sizes are supported...
4571 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4579 * Open the destination (if possible) and set the default options...
4584 cups_protocol
[0] = '\0';
4586 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4589 * Read all of the default lines from the old PPD...
4592 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4593 if (!strncmp(buffer
, "*Default", 8))
4596 * Add the default option...
4599 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4600 choice
, sizeof(choice
)))
4602 ppd_option_t
*ppdo
; /* PPD option */
4606 * Only add the default if the default hasn't already been
4607 * set and the choice exists in the new PPD...
4610 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4611 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4612 ppdFindChoice(ppdo
, choice
))
4613 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4617 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4618 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4622 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4625 * Add the default media sizes...
4628 num_defaults
= cupsAddOption("PageSize", size
->name
,
4629 num_defaults
, &defaults
);
4630 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4631 num_defaults
, &defaults
);
4632 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4633 num_defaults
, &defaults
);
4634 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4635 num_defaults
, &defaults
);
4641 * Open the destination file for a copy...
4644 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4646 cupsFreeOptions(num_defaults
, defaults
);
4653 * Copy the source file to the destination...
4656 cupsFileRewind(src
);
4658 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4660 if (!strncmp(buffer
, "*Default", 8))
4663 * Check for an previous default option choice...
4666 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4667 choice
, sizeof(choice
)))
4669 const char *val
; /* Default option value */
4672 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4675 * Substitute the previous choice...
4678 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4683 cupsFilePrintf(dst
, "%s\n", buffer
);
4686 if (cups_protocol
[0])
4687 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4689 cupsFreeOptions(num_defaults
, defaults
);
4692 * Close both files and return...
4699 return (cupsFileClose(dst
));
4704 * 'copy_job_attrs()' - Copy job attributes.
4708 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4709 cupsd_job_t
*job
, /* I - Job */
4710 cups_array_t
*ra
, /* I - Requested attributes array */
4711 cups_array_t
*exclude
) /* I - Private attributes array */
4713 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4717 * Send the requested attributes for each job...
4720 if (!cupsArrayFind(exclude
, "all"))
4722 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4723 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4724 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4725 "number-of-documents", job
->num_files
);
4727 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4728 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4729 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4730 "job-media-progress", job
->progress
);
4732 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4733 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4735 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4736 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4738 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4739 "job-more-info", NULL
, job_uri
);
4742 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4743 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4744 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4745 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4746 job
->num_files
> 0);
4748 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4749 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4750 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4751 "job-printer-up-time", time(NULL
));
4754 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4756 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4757 con
->clientname
, con
->clientport
,
4758 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4761 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4762 "job-printer-uri", NULL
, job_uri
);
4765 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4767 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4768 con
->clientname
, con
->clientport
, "/jobs/%d",
4770 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4771 "job-uri", NULL
, job_uri
);
4774 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4779 * 'copy_printer_attrs()' - Copy printer attributes.
4784 cupsd_client_t
*con
, /* I - Client connection */
4785 cupsd_printer_t
*printer
, /* I - Printer */
4786 cups_array_t
*ra
) /* I - Requested attributes array */
4788 char printer_uri
[HTTP_MAX_URI
];
4790 char printer_icons
[HTTP_MAX_URI
];
4792 time_t curtime
; /* Current time */
4793 int i
; /* Looping var */
4797 * Copy the printer attributes to the response using requested-attributes
4798 * and document-format attributes that may be provided by the client.
4801 curtime
= time(NULL
);
4803 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4804 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4805 "marker-change-time", printer
->marker_time
);
4807 if (printer
->num_printers
> 0 &&
4808 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4810 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4811 cupsd_printer_t
*p2
; /* Printer in class */
4812 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4815 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4816 IPP_TAG_URI
, "member-uris",
4817 printer
->num_printers
, NULL
,
4820 for (i
= 0; i
< printer
->num_printers
; i
++)
4822 p2
= printer
->printers
[i
];
4824 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4825 IPP_TAG_URI
)) != NULL
)
4826 member_uris
->values
[i
].string
.text
=
4827 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4830 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4831 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4833 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4834 "/classes/%s" : "/printers/%s", p2
->name
);
4835 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4841 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4842 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4843 "printer-alert", NULL
, printer
->alert
);
4845 if (printer
->alert_description
&&
4846 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4847 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4848 "printer-alert-description", NULL
,
4849 printer
->alert_description
);
4851 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4852 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4853 ippTimeToDate(curtime
));
4855 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4856 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4858 if (printer
->reg_name
)
4859 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4860 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4862 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4863 "printer-dns-sd-name", 0);
4865 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4867 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4868 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4869 "printer-error-policy", NULL
, printer
->error_policy
);
4871 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4873 static const char * const errors
[] =/* printer-error-policy-supported values */
4876 "retry-current-job",
4881 if (printer
->type
& CUPS_PRINTER_CLASS
)
4882 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4883 "printer-error-policy-supported", NULL
, "retry-current-job");
4885 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4886 "printer-error-policy-supported",
4887 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4890 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4892 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4893 "http", NULL
, con
->clientname
, con
->clientport
,
4894 "/icons/%s.png", printer
->name
);
4895 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4896 NULL
, printer_icons
);
4897 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4900 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4901 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
4902 printer
->accepting
);
4904 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4905 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
4908 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4910 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4911 "http", NULL
, con
->clientname
, con
->clientport
,
4912 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4913 "/classes/%s" : "/printers/%s", printer
->name
);
4914 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4915 "printer-more-info", NULL
, printer_uri
);
4918 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4919 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4920 "printer-op-policy", NULL
, printer
->op_policy
);
4922 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4923 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4926 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4927 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4928 "printer-state-change-time", printer
->state_time
);
4930 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4931 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4932 "printer-state-message", NULL
, printer
->state_message
);
4934 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4935 add_printer_state_reasons(con
, printer
);
4937 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4939 int type
; /* printer-type value */
4942 * Add the CUPS-specific printer-type attribute...
4945 type
= printer
->type
;
4947 if (printer
== DefaultPrinter
)
4948 type
|= CUPS_PRINTER_DEFAULT
;
4950 if (!printer
->accepting
)
4951 type
|= CUPS_PRINTER_REJECTING
;
4953 if (!printer
->shared
)
4954 type
|= CUPS_PRINTER_NOT_SHARED
;
4956 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
4960 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4961 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4962 "printer-up-time", curtime
);
4964 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
4966 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4967 "ipp", NULL
, con
->clientname
, con
->clientport
,
4968 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4969 "/classes/%s" : "/printers/%s", printer
->name
);
4970 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4971 "printer-uri-supported", NULL
, printer_uri
);
4972 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4976 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4977 add_queued_job_count(con
, printer
);
4979 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4980 if (printer
->ppd_attrs
)
4981 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4982 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
4987 * 'copy_subscription_attrs()' - Copy subscription attributes.
4991 copy_subscription_attrs(
4992 cupsd_client_t
*con
, /* I - Client connection */
4993 cupsd_subscription_t
*sub
, /* I - Subscription */
4994 cups_array_t
*ra
, /* I - Requested attributes array */
4995 cups_array_t
*exclude
) /* I - Private attributes array */
4997 ipp_attribute_t
*attr
; /* Current attribute */
4998 char printer_uri
[HTTP_MAX_URI
];
5000 int count
; /* Number of events */
5001 unsigned mask
; /* Current event mask */
5002 const char *name
; /* Current event name */
5005 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5006 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5007 con
, sub
, ra
, exclude
);
5010 * Copy the subscription attributes to the response using the
5011 * requested-attributes attribute that may be provided by the client.
5014 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5016 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5017 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5019 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5021 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5024 * Simple event list...
5027 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5028 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5029 "notify-events", NULL
, name
);
5034 * Complex event list...
5037 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5038 if (sub
->mask
& mask
)
5041 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5042 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5043 "notify-events", count
, NULL
, NULL
);
5045 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5046 if (sub
->mask
& mask
)
5048 attr
->values
[count
].string
.text
=
5049 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5056 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5057 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5058 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5059 "notify-lease-duration", sub
->lease
);
5061 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5062 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5063 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5064 "notify-recipient-uri", NULL
, sub
->recipient
);
5065 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5066 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5067 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5068 "notify-pull-method", NULL
, "ippget");
5070 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5071 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5072 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5073 "notify-subscriber-user-name", NULL
, sub
->owner
);
5075 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5076 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5077 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5078 "notify-time-interval", sub
->interval
);
5080 if (sub
->user_data_len
> 0 &&
5081 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5082 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5083 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5084 sub
->user_data
, sub
->user_data_len
);
5087 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5088 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5089 "notify-job-id", sub
->job
->id
);
5091 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5093 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5094 "ipp", NULL
, con
->clientname
, con
->clientport
,
5095 "/printers/%s", sub
->dest
->name
);
5096 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5097 "notify-printer-uri", NULL
, printer_uri
);
5100 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5101 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5102 "notify-subscription-id", sub
->id
);
5107 * 'create_job()' - Print a file to a printer or class.
5111 create_job(cupsd_client_t
*con
, /* I - Client connection */
5112 ipp_attribute_t
*uri
) /* I - Printer URI */
5114 int i
; /* Looping var */
5115 cupsd_printer_t
*printer
; /* Printer */
5116 cupsd_job_t
*job
; /* New job */
5117 static const char * const forbidden_attrs
[] =
5118 { /* List of forbidden attributes */
5122 "document-natural-language"
5126 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5127 con
->http
.fd
, uri
->values
[0].string
.text
);
5130 * Is the destination valid?
5133 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5139 send_ipp_status(con
, IPP_NOT_FOUND
,
5140 _("The printer or class does not exist."));
5145 * Check for invalid Create-Job attributes and log a warning or error depending
5146 * on whether cupsd is running in "strict conformance" mode...
5150 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5152 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5154 if (StrictConformance
)
5156 send_ipp_status(con
, IPP_BAD_REQUEST
,
5157 _("The '%s' operation attribute cannot be supplied in a "
5158 "Create-Job request."), forbidden_attrs
[i
]);
5162 cupsdLogMessage(CUPSD_LOG_WARN
,
5163 "Unexpected '%s' operation attribute in a Create-Job "
5164 "request.", forbidden_attrs
[i
]);
5168 * Create the job object...
5171 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5174 job
->pending_timeout
= 1;
5177 * Save and log the job...
5180 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5181 job
->dest
, job
->username
);
5186 * 'create_requested_array()' - Create an array for the requested-attributes.
5189 static cups_array_t
* /* O - Array of attributes or NULL */
5190 create_requested_array(ipp_t
*request
) /* I - IPP request */
5192 cups_array_t
*ra
; /* Requested attributes array */
5196 * Create the array for standard attributes...
5199 ra
= ippCreateRequestedArray(request
);
5202 * Add CUPS defaults as needed...
5205 if (cupsArrayFind(ra
, "printer-defaults"))
5208 * Include user-set defaults...
5211 char *name
; /* Option name */
5213 cupsArrayRemove(ra
, "printer-defaults");
5215 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5217 name
= (char *)cupsArrayNext(CommonDefaults
))
5218 if (!cupsArrayFind(ra
, name
))
5219 cupsArrayAdd(ra
, name
);
5227 * 'create_subscriptions()' - Create one or more notification subscriptions.
5231 create_subscriptions(
5232 cupsd_client_t
*con
, /* I - Client connection */
5233 ipp_attribute_t
*uri
) /* I - Printer URI */
5235 http_status_t status
; /* Policy status */
5236 int i
; /* Looping var */
5237 ipp_attribute_t
*attr
; /* Current attribute */
5238 cups_ptype_t dtype
; /* Destination type (printer/class) */
5239 char scheme
[HTTP_MAX_URI
],
5240 /* Scheme portion of URI */
5241 userpass
[HTTP_MAX_URI
],
5242 /* Username portion of URI */
5244 /* Host portion of URI */
5245 resource
[HTTP_MAX_URI
];
5246 /* Resource portion of URI */
5247 int port
; /* Port portion of URI */
5248 cupsd_printer_t
*printer
; /* Printer/class */
5249 cupsd_job_t
*job
; /* Job */
5250 int jobid
; /* Job ID */
5251 cupsd_subscription_t
*sub
; /* Subscription object */
5252 const char *username
, /* requesting-user-name or
5253 authenticated username */
5254 *recipient
, /* notify-recipient-uri */
5255 *pullmethod
; /* notify-pull-method */
5256 ipp_attribute_t
*user_data
; /* notify-user-data */
5257 int interval
, /* notify-time-interval */
5258 lease
; /* notify-lease-duration */
5259 unsigned mask
; /* notify-events */
5260 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5261 *notify_lease
; /* notify-lease-duration(-default) */
5265 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5267 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5268 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5269 attr
->value_tag
, attr
->name
);
5271 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5276 * Is the destination valid?
5279 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5281 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5282 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5283 sizeof(host
), &port
, resource
, sizeof(resource
));
5285 if (!strcmp(resource
, "/"))
5287 dtype
= (cups_ptype_t
)0;
5290 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5292 dtype
= (cups_ptype_t
)0;
5295 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5297 dtype
= CUPS_PRINTER_CLASS
;
5300 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5306 send_ipp_status(con
, IPP_NOT_FOUND
,
5307 _("The printer or class does not exist."));
5317 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5320 send_http_error(con
, status
, printer
);
5324 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5326 send_http_error(con
, status
, NULL
);
5331 * Get the user that is requesting the subscription...
5334 username
= get_username(con
);
5337 * Find the first subscription group attribute; return if we have
5341 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5342 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5347 send_ipp_status(con
, IPP_BAD_REQUEST
,
5348 _("No subscription attributes in request."));
5353 * Process the subscription attributes in the request...
5356 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5364 lease
= DefaultLeaseDuration
;
5366 mask
= CUPSD_EVENT_NONE
;
5370 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5372 notify_lease
= ippFindAttribute(printer
->attrs
,
5373 "notify-lease-duration-default",
5377 lease
= notify_lease
->values
[0].integer
;
5381 notify_events
= NULL
;
5382 notify_lease
= NULL
;
5385 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5387 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5388 attr
->value_tag
== IPP_TAG_URI
)
5391 * Validate the recipient scheme against the ServerBin/notifier
5395 char notifier
[1024]; /* Notifier filename */
5398 recipient
= attr
->values
[0].string
.text
;
5400 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5401 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5402 host
, sizeof(host
), &port
,
5403 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5405 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5406 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5407 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5408 "notify-status-code", IPP_URI_SCHEME
);
5412 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5414 if (access(notifier
, X_OK
))
5416 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5417 _("notify-recipient-uri URI \"%s\" uses unknown "
5418 "scheme."), recipient
);
5419 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5420 "notify-status-code", IPP_URI_SCHEME
);
5424 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5426 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5427 _("notify-recipient-uri URI \"%s\" is already used."),
5429 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5430 "notify-status-code", IPP_ATTRIBUTES
);
5434 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5435 attr
->value_tag
== IPP_TAG_KEYWORD
)
5437 pullmethod
= attr
->values
[0].string
.text
;
5439 if (strcmp(pullmethod
, "ippget"))
5441 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5442 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5443 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5444 "notify-status-code", IPP_ATTRIBUTES
);
5448 else if (!strcmp(attr
->name
, "notify-charset") &&
5449 attr
->value_tag
== IPP_TAG_CHARSET
&&
5450 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5451 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5453 send_ipp_status(con
, IPP_CHARSET
,
5454 _("Character set \"%s\" not supported."),
5455 attr
->values
[0].string
.text
);
5458 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5459 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5460 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5462 send_ipp_status(con
, IPP_CHARSET
,
5463 _("Language \"%s\" not supported."),
5464 attr
->values
[0].string
.text
);
5467 else if (!strcmp(attr
->name
, "notify-user-data") &&
5468 attr
->value_tag
== IPP_TAG_STRING
)
5470 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5472 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5473 _("The notify-user-data value is too large "
5474 "(%d > 63 octets)."),
5475 attr
->values
[0].unknown
.length
);
5481 else if (!strcmp(attr
->name
, "notify-events") &&
5482 attr
->value_tag
== IPP_TAG_KEYWORD
)
5483 notify_events
= attr
;
5484 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5485 attr
->value_tag
== IPP_TAG_INTEGER
)
5486 lease
= attr
->values
[0].integer
;
5487 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5488 attr
->value_tag
== IPP_TAG_INTEGER
)
5489 interval
= attr
->values
[0].integer
;
5490 else if (!strcmp(attr
->name
, "notify-job-id") &&
5491 attr
->value_tag
== IPP_TAG_INTEGER
)
5492 jobid
= attr
->values
[0].integer
;
5499 for (i
= 0; i
< notify_events
->num_values
; i
++)
5500 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5504 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5506 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5507 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5508 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5510 if (!recipient
&& !pullmethod
)
5513 if (mask
== CUPSD_EVENT_NONE
)
5516 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5518 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5521 send_ipp_status(con
, IPP_BAD_REQUEST
,
5522 _("notify-events not specified."));
5527 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5529 cupsdLogMessage(CUPSD_LOG_INFO
,
5530 "create_subscriptions: Limiting notify-lease-duration to "
5533 lease
= MaxLeaseDuration
;
5538 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5540 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5548 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5550 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5551 _("There are too many subscriptions."));
5556 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5559 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5560 "Added subscription #%d for printer \"%s\".",
5561 sub
->id
, printer
->name
);
5563 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5566 sub
->interval
= interval
;
5568 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5570 cupsdSetString(&sub
->owner
, username
);
5574 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5575 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5576 sub
->user_data_len
);
5579 ippAddSeparator(con
->response
);
5580 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5581 "notify-subscription-id", sub
->id
);
5583 con
->response
->request
.status
.status_code
= IPP_OK
;
5589 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5594 * 'delete_printer()' - Remove a printer or class from the system.
5598 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5599 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5601 http_status_t status
; /* Policy status */
5602 cups_ptype_t dtype
; /* Destination type (printer/class) */
5603 cupsd_printer_t
*printer
; /* Printer/class */
5604 char filename
[1024]; /* Script/PPD filename */
5607 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5608 con
->http
.fd
, uri
->values
[0].string
.text
);
5611 * Do we have a valid URI?
5614 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5620 send_ipp_status(con
, IPP_NOT_FOUND
,
5621 _("The printer or class does not exist."));
5629 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5631 send_http_error(con
, status
, NULL
);
5636 * Remove old jobs...
5639 cupsdCancelJobs(printer
->name
, NULL
, 1);
5642 * Remove old subscriptions and send a "deleted printer" event...
5645 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5646 "%s \"%s\" deleted by \"%s\".",
5647 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5648 printer
->name
, get_username(con
));
5650 cupsdExpireSubscriptions(printer
, NULL
);
5653 * Remove any old PPD or script files...
5656 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5659 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s.O", ServerRoot
,
5663 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5666 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5670 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5673 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5677 * Unregister color profiles...
5680 cupsdUnregisterColor(printer
);
5682 if (dtype
& CUPS_PRINTER_CLASS
)
5684 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5685 printer
->name
, get_username(con
));
5687 cupsdDeletePrinter(printer
, 0);
5688 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5692 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5693 printer
->name
, get_username(con
));
5695 if (cupsdDeletePrinter(printer
, 0))
5696 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5698 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5701 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5704 * Return with no errors...
5707 con
->response
->request
.status
.status_code
= IPP_OK
;
5712 * 'get_default()' - Get the default destination.
5716 get_default(cupsd_client_t
*con
) /* I - Client connection */
5718 http_status_t status
; /* Policy status */
5719 cups_array_t
*ra
; /* Requested attributes array */
5722 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5728 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5730 send_http_error(con
, status
, NULL
);
5736 ra
= create_requested_array(con
->request
);
5738 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5740 cupsArrayDelete(ra
);
5742 con
->response
->request
.status
.status_code
= IPP_OK
;
5745 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5750 * 'get_devices()' - Get the list of available devices on the local system.
5754 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5756 http_status_t status
; /* Policy status */
5757 ipp_attribute_t
*limit
, /* limit attribute */
5758 *timeout
, /* timeout attribute */
5759 *requested
, /* requested-attributes attribute */
5760 *exclude
, /* exclude-schemes attribute */
5761 *include
; /* include-schemes attribute */
5762 char command
[1024], /* cups-deviced command */
5763 options
[2048], /* Options to pass to command */
5765 /* String for requested attributes */
5767 /* String for excluded schemes */
5769 /* String for included schemes */
5772 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
5778 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5780 send_http_error(con
, status
, NULL
);
5785 * Run cups-deviced command with the given options...
5788 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5789 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5790 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5792 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5793 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5796 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5798 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5801 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5803 exclude_str
[0] = '\0';
5806 url_encode_attr(include
, include_str
, sizeof(include_str
));
5808 include_str
[0] = '\0';
5810 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5811 snprintf(options
, sizeof(options
),
5812 "%d+%d+%d+%d+%s%s%s%s%s",
5813 con
->request
->request
.op
.request_id
,
5814 limit
? limit
->values
[0].integer
: 0,
5815 timeout
? timeout
->values
[0].integer
: 15,
5818 exclude_str
[0] ? "%20" : "", exclude_str
,
5819 include_str
[0] ? "%20" : "", include_str
);
5821 if (cupsdSendCommand(con
, command
, options
, 1))
5824 * Command started successfully, don't send an IPP response here...
5827 ippDelete(con
->response
);
5828 con
->response
= NULL
;
5833 * Command failed, return "internal error" so the user knows something
5837 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5838 _("cups-deviced failed to execute."));
5844 * 'get_document()' - Get a copy of a job file.
5848 get_document(cupsd_client_t
*con
, /* I - Client connection */
5849 ipp_attribute_t
*uri
) /* I - Job URI */
5851 http_status_t status
; /* Policy status */
5852 ipp_attribute_t
*attr
; /* Current attribute */
5853 int jobid
; /* Job ID */
5854 int docnum
; /* Document number */
5855 cupsd_job_t
*job
; /* Current job */
5856 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
5857 username
[HTTP_MAX_URI
], /* Username portion of URI */
5858 host
[HTTP_MAX_URI
], /* Host portion of URI */
5859 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5860 int port
; /* Port portion of URI */
5861 char filename
[1024], /* Filename for document */
5862 format
[1024]; /* Format for document */
5865 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
5866 con
->http
.fd
, uri
->values
[0].string
.text
);
5869 * See if we have a job URI or a printer URI...
5872 if (!strcmp(uri
->name
, "printer-uri"))
5875 * Got a printer URI; see if we also have a job-id attribute...
5878 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5879 IPP_TAG_INTEGER
)) == NULL
)
5881 send_ipp_status(con
, IPP_BAD_REQUEST
,
5882 _("Got a printer-uri attribute but no job-id."));
5886 jobid
= attr
->values
[0].integer
;
5891 * Got a job URI; parse it to get the job ID...
5894 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5895 sizeof(scheme
), username
, sizeof(username
), host
,
5896 sizeof(host
), &port
, resource
, sizeof(resource
));
5898 if (strncmp(resource
, "/jobs/", 6))
5904 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
5905 uri
->values
[0].string
.text
);
5909 jobid
= atoi(resource
+ 6);
5913 * See if the job exists...
5916 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5919 * Nope - return a "not found" error...
5922 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
5930 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
5931 job
->username
)) != HTTP_OK
)
5933 send_http_error(con
, status
, NULL
);
5938 * Get the document number...
5941 if ((attr
= ippFindAttribute(con
->request
, "document-number",
5942 IPP_TAG_INTEGER
)) == NULL
)
5944 send_ipp_status(con
, IPP_BAD_REQUEST
,
5945 _("Missing document-number attribute."));
5949 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
5950 attr
->num_values
> 1)
5952 send_ipp_status(con
, IPP_NOT_FOUND
,
5953 _("Document #%d does not exist in job #%d."), docnum
,
5958 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
5960 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
5962 cupsdLogMessage(CUPSD_LOG_ERROR
,
5963 "Unable to open document %d in job %d - %s", docnum
, jobid
,
5965 send_ipp_status(con
, IPP_NOT_FOUND
,
5966 _("Unable to open document #%d in job #%d."), docnum
,
5971 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
5975 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
5976 job
->filetypes
[docnum
- 1]->type
);
5978 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
5980 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
5982 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
5983 IPP_TAG_NAME
)) != NULL
)
5984 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
5985 NULL
, attr
->values
[0].string
.text
);
5990 * 'get_job_attrs()' - Get job attributes.
5994 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5995 ipp_attribute_t
*uri
) /* I - Job URI */
5997 http_status_t status
; /* Policy status */
5998 ipp_attribute_t
*attr
; /* Current attribute */
5999 int jobid
; /* Job ID */
6000 cupsd_job_t
*job
; /* Current job */
6001 cupsd_printer_t
*printer
; /* Current printer */
6002 cupsd_policy_t
*policy
; /* Current security policy */
6003 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6004 username
[HTTP_MAX_URI
], /* Username portion of URI */
6005 host
[HTTP_MAX_URI
], /* Host portion of URI */
6006 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6007 int port
; /* Port portion of URI */
6008 cups_array_t
*ra
, /* Requested attributes array */
6009 *exclude
; /* Private attributes array */
6012 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6013 con
->http
.fd
, uri
->values
[0].string
.text
);
6016 * See if we have a job URI or a printer URI...
6019 if (!strcmp(uri
->name
, "printer-uri"))
6022 * Got a printer URI; see if we also have a job-id attribute...
6025 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6026 IPP_TAG_INTEGER
)) == NULL
)
6028 send_ipp_status(con
, IPP_BAD_REQUEST
,
6029 _("Got a printer-uri attribute but no job-id."));
6033 jobid
= attr
->values
[0].integer
;
6038 * Got a job URI; parse it to get the job ID...
6041 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6042 sizeof(scheme
), username
, sizeof(username
), host
,
6043 sizeof(host
), &port
, resource
, sizeof(resource
));
6045 if (strncmp(resource
, "/jobs/", 6))
6051 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6052 uri
->values
[0].string
.text
);
6056 jobid
= atoi(resource
+ 6);
6060 * See if the job exists...
6063 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6066 * Nope - return a "not found" error...
6069 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6077 if ((printer
= job
->printer
) == NULL
)
6078 printer
= cupsdFindDest(job
->dest
);
6081 policy
= printer
->op_policy_ptr
;
6083 policy
= DefaultPolicyPtr
;
6085 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6087 send_http_error(con
, status
, NULL
);
6091 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6094 * Copy attributes...
6099 ra
= create_requested_array(con
->request
);
6100 copy_job_attrs(con
, job
, ra
, exclude
);
6101 cupsArrayDelete(ra
);
6103 con
->response
->request
.status
.status_code
= IPP_OK
;
6108 * 'get_jobs()' - Get a list of jobs for the specified printer.
6112 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6113 ipp_attribute_t
*uri
) /* I - Printer URI */
6115 http_status_t status
; /* Policy status */
6116 ipp_attribute_t
*attr
; /* Current attribute */
6117 const char *dest
; /* Destination */
6118 cups_ptype_t dtype
; /* Destination type (printer/class) */
6119 cups_ptype_t dmask
; /* Destination type mask */
6120 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6121 username
[HTTP_MAX_URI
], /* Username portion of URI */
6122 host
[HTTP_MAX_URI
], /* Host portion of URI */
6123 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6124 int port
; /* Port portion of URI */
6125 int job_comparison
; /* Job comparison */
6126 ipp_jstate_t job_state
; /* job-state value */
6127 int first_job_id
; /* First job ID */
6128 int limit
; /* Maximum number of jobs to return */
6129 int count
; /* Number of jobs that match */
6130 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6131 cupsd_job_t
*job
; /* Current job pointer */
6132 cupsd_printer_t
*printer
; /* Printer */
6133 cups_array_t
*list
; /* Which job list... */
6134 cups_array_t
*ra
, /* Requested attributes array */
6135 *exclude
; /* Private attributes array */
6136 cupsd_policy_t
*policy
; /* Current policy */
6139 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
6140 uri
->values
[0].string
.text
);
6143 * Is the destination valid?
6146 if (strcmp(uri
->name
, "printer-uri"))
6148 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6152 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6153 sizeof(scheme
), username
, sizeof(username
), host
,
6154 sizeof(host
), &port
, resource
, sizeof(resource
));
6156 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6159 dtype
= (cups_ptype_t
)0;
6160 dmask
= (cups_ptype_t
)0;
6163 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6166 dtype
= (cups_ptype_t
)0;
6167 dmask
= CUPS_PRINTER_CLASS
;
6170 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6173 dtype
= CUPS_PRINTER_CLASS
;
6174 dmask
= CUPS_PRINTER_CLASS
;
6177 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6184 send_ipp_status(con
, IPP_NOT_FOUND
,
6185 _("The printer or class does not exist."));
6190 dtype
&= CUPS_PRINTER_CLASS
;
6191 dmask
= CUPS_PRINTER_CLASS
;
6199 policy
= printer
->op_policy_ptr
;
6201 policy
= DefaultPolicyPtr
;
6203 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6205 send_http_error(con
, status
, NULL
);
6209 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6212 * See if the "which-jobs" attribute have been specified...
6215 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6216 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6218 send_ipp_status(con
, IPP_CONFLICT
,
6219 _("The %s attribute cannot be provided with job-ids."),
6223 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6225 job_comparison
= -1;
6226 job_state
= IPP_JOB_STOPPED
;
6229 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6232 job_state
= IPP_JOB_CANCELED
;
6235 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6238 job_state
= IPP_JOB_ABORTED
;
6241 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6244 job_state
= IPP_JOB_PENDING
;
6247 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6250 job_state
= IPP_JOB_CANCELED
;
6253 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6256 job_state
= IPP_JOB_PENDING
;
6259 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6262 job_state
= IPP_JOB_HELD
;
6265 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6268 job_state
= IPP_JOB_PROCESSING
;
6269 list
= PrintingJobs
;
6271 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6274 job_state
= IPP_JOB_STOPPED
;
6279 send_ipp_status(con
, IPP_ATTRIBUTES
,
6280 _("The which-jobs value \"%s\" is not supported."),
6281 attr
->values
[0].string
.text
);
6282 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6283 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6288 * See if they want to limit the number of jobs reported...
6291 if ((attr
= ippFindAttribute(con
->request
, "limit",
6292 IPP_TAG_INTEGER
)) != NULL
)
6296 send_ipp_status(con
, IPP_CONFLICT
,
6297 _("The %s attribute cannot be provided with job-ids."),
6302 limit
= attr
->values
[0].integer
;
6307 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
6308 IPP_TAG_INTEGER
)) != NULL
)
6312 send_ipp_status(con
, IPP_CONFLICT
,
6313 _("The %s attribute cannot be provided with job-ids."),
6318 first_job_id
= attr
->values
[0].integer
;
6324 * See if we only want to see jobs for a specific user...
6327 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
6328 IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6330 send_ipp_status(con
, IPP_CONFLICT
,
6331 _("The %s attribute cannot be provided with job-ids."),
6335 else if (attr
&& attr
->values
[0].boolean
)
6336 strlcpy(username
, get_username(con
), sizeof(username
));
6340 ra
= create_requested_array(con
->request
);
6343 * OK, build a list of jobs for this printer...
6348 int i
; /* Looping var */
6350 for (i
= 0; i
< job_ids
->num_values
; i
++)
6352 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6356 if (i
< job_ids
->num_values
)
6358 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6359 job_ids
->values
[i
].integer
);
6363 for (i
= 0; i
< job_ids
->num_values
; i
++)
6365 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6371 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6377 ippAddSeparator(con
->response
);
6379 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6380 job
->printer
->op_policy_ptr
:
6381 policy
, con
, job
->printer
,
6384 copy_job_attrs(con
, job
, ra
, exclude
);
6389 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6390 (limit
<= 0 || count
< limit
) && job
;
6391 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6394 * Filter out jobs that don't match...
6397 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6398 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6399 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6400 job
->username
, job
->state_value
, job
->attrs
);
6402 if (!job
->dest
|| !job
->username
)
6405 if (!job
->dest
|| !job
->username
)
6408 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6409 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6411 if ((job
->dtype
& dmask
) != dtype
&&
6412 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6415 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6416 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6417 (job_comparison
> 0 && job
->state_value
< job_state
))
6420 if (job
->id
< first_job_id
)
6427 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d",
6432 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6436 ippAddSeparator(con
->response
);
6440 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6441 job
->printer
->op_policy_ptr
:
6442 policy
, con
, job
->printer
,
6445 copy_job_attrs(con
, job
, ra
, exclude
);
6448 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6451 cupsArrayDelete(ra
);
6453 con
->response
->request
.status
.status_code
= IPP_OK
;
6458 * 'get_notifications()' - Get events for a subscription.
6462 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6464 int i
, j
; /* Looping vars */
6465 http_status_t status
; /* Policy status */
6466 cupsd_subscription_t
*sub
; /* Subscription */
6467 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6468 *sequences
; /* notify-sequence-numbers */
6469 int min_seq
; /* Minimum sequence number */
6470 int interval
; /* Poll interval */
6473 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6477 * Get subscription attributes...
6480 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6482 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6487 send_ipp_status(con
, IPP_BAD_REQUEST
,
6488 _("Missing notify-subscription-ids attribute."));
6493 * Are the subscription IDs valid?
6496 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6498 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6501 * Bad subscription ID...
6504 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6505 ids
->values
[i
].integer
);
6513 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6515 con
, sub
->owner
)) != HTTP_OK
)
6517 send_http_error(con
, status
, sub
->dest
);
6522 * Check the subscription type and update the interval accordingly.
6525 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6528 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6530 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6536 * Tell the client to poll again in N seconds...
6540 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6541 "notify-get-interval", interval
);
6543 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6544 "printer-up-time", time(NULL
));
6547 * Copy the subscription event attributes to the response.
6550 con
->response
->request
.status
.status_code
=
6551 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6553 for (i
= 0; i
< ids
->num_values
; i
++)
6556 * Get the subscription and sequence number...
6559 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6561 if (sequences
&& i
< sequences
->num_values
)
6562 min_seq
= sequences
->values
[i
].integer
;
6567 * If we don't have any new events, nothing to do here...
6570 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6574 * Otherwise copy all of the new events...
6577 if (sub
->first_event_id
> min_seq
)
6580 j
= min_seq
- sub
->first_event_id
;
6582 for (; j
< cupsArrayCount(sub
->events
); j
++)
6584 ippAddSeparator(con
->response
);
6586 copy_attrs(con
->response
,
6587 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6588 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6595 * 'get_ppd()' - Get a named PPD from the local system.
6599 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6600 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6602 http_status_t status
; /* Policy status */
6603 cupsd_printer_t
*dest
; /* Destination */
6604 cups_ptype_t dtype
; /* Destination type */
6607 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6608 con
->http
.fd
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6610 if (!strcmp(uri
->name
, "ppd-name"))
6613 * Return a PPD file from cups-driverd...
6616 char command
[1024], /* cups-driverd command */
6617 options
[1024], /* Options to pass to command */
6618 ppd_name
[1024]; /* ppd-name */
6625 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6627 send_http_error(con
, status
, NULL
);
6632 * Run cups-driverd command with the given options...
6635 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6636 url_encode_string(uri
->values
[0].string
.text
, ppd_name
, sizeof(ppd_name
));
6637 snprintf(options
, sizeof(options
), "get+%d+%s",
6638 con
->request
->request
.op
.request_id
, ppd_name
);
6640 if (cupsdSendCommand(con
, command
, options
, 0))
6643 * Command started successfully, don't send an IPP response here...
6646 ippDelete(con
->response
);
6647 con
->response
= NULL
;
6652 * Command failed, return "internal error" so the user knows something
6656 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6657 _("cups-driverd failed to execute."));
6660 else if (!strcmp(uri
->name
, "printer-uri") &&
6661 cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &dest
))
6663 int i
; /* Looping var */
6664 char filename
[1024]; /* PPD filename */
6671 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6673 send_http_error(con
, status
, dest
);
6678 * See if we need the PPD for a class or remote printer...
6681 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6684 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6686 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6687 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6688 "printer-uri", NULL
, dest
->uri
);
6691 else if (dtype
& CUPS_PRINTER_CLASS
)
6693 for (i
= 0; i
< dest
->num_printers
; i
++)
6694 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6696 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6697 dest
->printers
[i
]->name
);
6699 if (!access(filename
, 0))
6703 if (i
< dest
->num_printers
)
6704 dest
= dest
->printers
[i
];
6707 con
->response
->request
.status
.status_code
= CUPS_SEE_OTHER
;
6708 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
6709 "printer-uri", NULL
, dest
->printers
[0]->uri
);
6715 * Found the printer with the PPD file, now see if there is one...
6718 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6720 send_ipp_status(con
, IPP_NOT_FOUND
,
6721 _("The PPD file \"%s\" could not be opened: %s"),
6722 uri
->values
[0].string
.text
, strerror(errno
));
6726 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6730 con
->response
->request
.status
.status_code
= IPP_OK
;
6733 send_ipp_status(con
, IPP_NOT_FOUND
,
6734 _("The PPD file \"%s\" could not be found."),
6735 uri
->values
[0].string
.text
);
6740 * 'get_ppds()' - Get the list of PPD files on the local system.
6744 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6746 http_status_t status
; /* Policy status */
6747 ipp_attribute_t
*limit
, /* Limit attribute */
6748 *device
, /* ppd-device-id attribute */
6749 *language
, /* ppd-natural-language attribute */
6750 *make
, /* ppd-make attribute */
6751 *model
, /* ppd-make-and-model attribute */
6752 *model_number
, /* ppd-model-number attribute */
6753 *product
, /* ppd-product attribute */
6754 *psversion
, /* ppd-psverion attribute */
6755 *type
, /* ppd-type attribute */
6756 *requested
, /* requested-attributes attribute */
6757 *exclude
, /* exclude-schemes attribute */
6758 *include
; /* include-schemes attribute */
6759 char command
[1024], /* cups-driverd command */
6760 options
[4096], /* Options to pass to command */
6761 device_str
[256],/* Escaped ppd-device-id string */
6763 /* Escaped ppd-natural-language */
6764 make_str
[256], /* Escaped ppd-make string */
6765 model_str
[256], /* Escaped ppd-make-and-model string */
6766 model_number_str
[256],
6767 /* ppd-model-number string */
6769 /* Escaped ppd-product string */
6771 /* Escaped ppd-psversion string */
6772 type_str
[256], /* Escaped ppd-type string */
6774 /* String for requested attributes */
6776 /* String for excluded schemes */
6778 /* String for included schemes */
6781 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
6787 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6789 send_http_error(con
, status
, NULL
);
6794 * Run cups-driverd command with the given options...
6797 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6798 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6799 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6801 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6802 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6804 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6806 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6807 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6808 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6809 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6811 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6813 include
= ippFindAttribute(con
->request
, "include-schemes",
6817 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6819 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6822 url_encode_attr(device
, device_str
, sizeof(device_str
));
6824 device_str
[0] = '\0';
6827 url_encode_attr(language
, language_str
, sizeof(language_str
));
6829 language_str
[0] = '\0';
6832 url_encode_attr(make
, make_str
, sizeof(make_str
));
6837 url_encode_attr(model
, model_str
, sizeof(model_str
));
6839 model_str
[0] = '\0';
6842 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
6843 model_number
->values
[0].integer
);
6845 model_number_str
[0] = '\0';
6848 url_encode_attr(product
, product_str
, sizeof(product_str
));
6850 product_str
[0] = '\0';
6853 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
6855 psversion_str
[0] = '\0';
6858 url_encode_attr(type
, type_str
, sizeof(type_str
));
6863 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6865 exclude_str
[0] = '\0';
6868 url_encode_attr(include
, include_str
, sizeof(include_str
));
6870 include_str
[0] = '\0';
6872 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6873 snprintf(options
, sizeof(options
),
6874 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
6875 con
->request
->request
.op
.request_id
,
6876 limit
? limit
->values
[0].integer
: 0,
6878 device
? "%20" : "", device_str
,
6879 language
? "%20" : "", language_str
,
6880 make
? "%20" : "", make_str
,
6881 model
? "%20" : "", model_str
,
6882 model_number
? "%20" : "", model_number_str
,
6883 product
? "%20" : "", product_str
,
6884 psversion
? "%20" : "", psversion_str
,
6885 type
? "%20" : "", type_str
,
6886 exclude_str
[0] ? "%20" : "", exclude_str
,
6887 include_str
[0] ? "%20" : "", include_str
);
6889 if (cupsdSendCommand(con
, command
, options
, 0))
6892 * Command started successfully, don't send an IPP response here...
6895 ippDelete(con
->response
);
6896 con
->response
= NULL
;
6901 * Command failed, return "internal error" so the user knows something
6905 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6906 _("cups-driverd failed to execute."));
6912 * 'get_printer_attrs()' - Get printer attributes.
6916 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
6917 ipp_attribute_t
*uri
) /* I - Printer URI */
6919 http_status_t status
; /* Policy status */
6920 cups_ptype_t dtype
; /* Destination type (printer/class) */
6921 cupsd_printer_t
*printer
; /* Printer/class */
6922 cups_array_t
*ra
; /* Requested attributes array */
6925 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
6926 con
->http
.fd
, uri
->values
[0].string
.text
);
6929 * Is the destination valid?
6932 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6938 send_ipp_status(con
, IPP_NOT_FOUND
,
6939 _("The printer or class does not exist."));
6947 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6949 send_http_error(con
, status
, printer
);
6954 * Send the attributes...
6957 ra
= create_requested_array(con
->request
);
6959 copy_printer_attrs(con
, printer
, ra
);
6961 cupsArrayDelete(ra
);
6963 con
->response
->request
.status
.status_code
= IPP_OK
;
6968 * 'get_printer_supported()' - Get printer supported values.
6972 get_printer_supported(
6973 cupsd_client_t
*con
, /* I - Client connection */
6974 ipp_attribute_t
*uri
) /* I - Printer URI */
6976 http_status_t status
; /* Policy status */
6977 cups_ptype_t dtype
; /* Destination type (printer/class) */
6978 cupsd_printer_t
*printer
; /* Printer/class */
6981 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
6982 con
->http
.fd
, uri
->values
[0].string
.text
);
6985 * Is the destination valid?
6988 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6994 send_ipp_status(con
, IPP_NOT_FOUND
,
6995 _("The printer or class does not exist."));
7003 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7005 send_http_error(con
, status
, printer
);
7010 * Return a list of attributes that can be set via Set-Printer-Attributes.
7013 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7015 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7016 "printer-location", 0);
7018 con
->response
->request
.status
.status_code
= IPP_OK
;
7023 * 'get_printers()' - Get a list of printers or classes.
7027 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7028 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7030 http_status_t status
; /* Policy status */
7031 ipp_attribute_t
*attr
; /* Current attribute */
7032 int limit
; /* Max number of printers to return */
7033 int count
; /* Number of printers that match */
7034 cupsd_printer_t
*printer
; /* Current printer pointer */
7035 int printer_type
, /* printer-type attribute */
7036 printer_mask
; /* printer-type-mask attribute */
7037 char *location
; /* Location string */
7038 const char *username
; /* Current user */
7039 char *first_printer_name
; /* first-printer-name attribute */
7040 cups_array_t
*ra
; /* Requested attributes array */
7041 int local
; /* Local connection? */
7044 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7045 con
->http
.fd
, type
);
7051 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7053 send_http_error(con
, status
, NULL
);
7058 * Check for printers...
7061 if (!Printers
|| !cupsArrayCount(Printers
))
7063 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7068 * See if they want to limit the number of printers reported...
7071 if ((attr
= ippFindAttribute(con
->request
, "limit",
7072 IPP_TAG_INTEGER
)) != NULL
)
7073 limit
= attr
->values
[0].integer
;
7077 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7078 IPP_TAG_NAME
)) != NULL
)
7079 first_printer_name
= attr
->values
[0].string
.text
;
7081 first_printer_name
= NULL
;
7084 * Support filtering...
7087 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7088 IPP_TAG_ENUM
)) != NULL
)
7089 printer_type
= attr
->values
[0].integer
;
7093 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7094 IPP_TAG_ENUM
)) != NULL
)
7095 printer_mask
= attr
->values
[0].integer
;
7099 local
= httpAddrLocalhost(&(con
->clientaddr
));
7101 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7102 IPP_TAG_TEXT
)) != NULL
)
7103 location
= attr
->values
[0].string
.text
;
7107 if (con
->username
[0])
7108 username
= con
->username
;
7109 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7110 IPP_TAG_NAME
)) != NULL
)
7111 username
= attr
->values
[0].string
.text
;
7115 ra
= create_requested_array(con
->request
);
7118 * OK, build a list of printers for this printer...
7121 if (first_printer_name
)
7123 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7124 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7127 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7130 count
< limit
&& printer
;
7131 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7133 if (!local
&& !printer
->shared
)
7136 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7137 (printer
->type
& printer_mask
) == printer_type
&&
7139 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7142 * If a username is specified, see if it is allowed or denied
7146 if (cupsArrayCount(printer
->users
) && username
&&
7147 !user_allowed(printer
, username
))
7151 * Add the group separator as needed...
7155 ippAddSeparator(con
->response
);
7160 * Send the attributes...
7163 copy_printer_attrs(con
, printer
, ra
);
7167 cupsArrayDelete(ra
);
7169 con
->response
->request
.status
.status_code
= IPP_OK
;
7174 * 'get_subscription_attrs()' - Get subscription attributes.
7178 get_subscription_attrs(
7179 cupsd_client_t
*con
, /* I - Client connection */
7180 int sub_id
) /* I - Subscription ID */
7182 http_status_t status
; /* Policy status */
7183 cupsd_subscription_t
*sub
; /* Subscription */
7184 cupsd_policy_t
*policy
; /* Current security policy */
7185 cups_array_t
*ra
, /* Requested attributes array */
7186 *exclude
; /* Private attributes array */
7189 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7190 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7191 con
, con
->http
.fd
, sub_id
);
7194 * Is the subscription ID valid?
7197 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7200 * Bad subscription ID...
7203 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7213 policy
= sub
->dest
->op_policy_ptr
;
7215 policy
= DefaultPolicyPtr
;
7217 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7219 send_http_error(con
, status
, sub
->dest
);
7223 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7226 * Copy the subscription attributes to the response using the
7227 * requested-attributes attribute that may be provided by the client.
7230 ra
= create_requested_array(con
->request
);
7232 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7234 cupsArrayDelete(ra
);
7236 con
->response
->request
.status
.status_code
= IPP_OK
;
7241 * 'get_subscriptions()' - Get subscriptions.
7245 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7246 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7248 http_status_t status
; /* Policy status */
7249 int count
; /* Number of subscriptions */
7250 int limit
; /* Limit */
7251 cupsd_subscription_t
*sub
; /* Subscription */
7252 cups_array_t
*ra
; /* Requested attributes array */
7253 ipp_attribute_t
*attr
; /* Attribute */
7254 cups_ptype_t dtype
; /* Destination type (printer/class) */
7255 char scheme
[HTTP_MAX_URI
],
7256 /* Scheme portion of URI */
7257 username
[HTTP_MAX_URI
],
7258 /* Username portion of URI */
7260 /* Host portion of URI */
7261 resource
[HTTP_MAX_URI
];
7262 /* Resource portion of URI */
7263 int port
; /* Port portion of URI */
7264 cupsd_job_t
*job
; /* Job pointer */
7265 cupsd_printer_t
*printer
; /* Printer */
7266 cupsd_policy_t
*policy
; /* Policy */
7267 cups_array_t
*exclude
; /* Private attributes array */
7270 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7271 "get_subscriptions(con=%p[%d], uri=%s)",
7272 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
7275 * Is the destination valid?
7278 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7279 sizeof(scheme
), username
, sizeof(username
), host
,
7280 sizeof(host
), &port
, resource
, sizeof(resource
));
7282 if (!strcmp(resource
, "/") ||
7283 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7284 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7285 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7290 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7293 job
= cupsdFindJob(atoi(resource
+ 6));
7297 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7298 atoi(resource
+ 6));
7302 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7308 send_ipp_status(con
, IPP_NOT_FOUND
,
7309 _("The printer or class does not exist."));
7312 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7313 IPP_TAG_INTEGER
)) != NULL
)
7315 job
= cupsdFindJob(attr
->values
[0].integer
);
7319 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7320 attr
->values
[0].integer
);
7332 policy
= printer
->op_policy_ptr
;
7334 policy
= DefaultPolicyPtr
;
7336 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7338 send_http_error(con
, status
, printer
);
7343 * Copy the subscription attributes to the response using the
7344 * requested-attributes attribute that may be provided by the client.
7347 ra
= create_requested_array(con
->request
);
7349 if ((attr
= ippFindAttribute(con
->request
, "limit",
7350 IPP_TAG_INTEGER
)) != NULL
)
7351 limit
= attr
->values
[0].integer
;
7356 * See if we only want to see subscriptions for a specific user...
7359 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7360 IPP_TAG_BOOLEAN
)) != NULL
&&
7361 attr
->values
[0].boolean
)
7362 strlcpy(username
, get_username(con
), sizeof(username
));
7366 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7368 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7369 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7370 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7372 ippAddSeparator(con
->response
);
7374 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7375 policy
, con
, sub
->dest
,
7378 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7381 if (limit
&& count
>= limit
)
7385 cupsArrayDelete(ra
);
7388 con
->response
->request
.status
.status_code
= IPP_OK
;
7390 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7395 * 'get_username()' - Get the username associated with a request.
7398 static const char * /* O - Username */
7399 get_username(cupsd_client_t
*con
) /* I - Connection */
7401 ipp_attribute_t
*attr
; /* Attribute */
7404 if (con
->username
[0])
7405 return (con
->username
);
7406 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7407 IPP_TAG_NAME
)) != NULL
)
7408 return (attr
->values
[0].string
.text
);
7410 return ("anonymous");
7415 * 'hold_job()' - Hold a print job.
7419 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7420 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7422 ipp_attribute_t
*attr
; /* Current job-hold-until */
7423 const char *when
; /* New value */
7424 int jobid
; /* Job ID */
7425 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7426 username
[HTTP_MAX_URI
], /* Username portion of URI */
7427 host
[HTTP_MAX_URI
], /* Host portion of URI */
7428 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7429 int port
; /* Port portion of URI */
7430 cupsd_job_t
*job
; /* Job information */
7433 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
7434 uri
->values
[0].string
.text
);
7437 * See if we have a job URI or a printer URI...
7440 if (!strcmp(uri
->name
, "printer-uri"))
7443 * Got a printer URI; see if we also have a job-id attribute...
7446 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7447 IPP_TAG_INTEGER
)) == NULL
)
7449 send_ipp_status(con
, IPP_BAD_REQUEST
,
7450 _("Got a printer-uri attribute but no job-id."));
7454 jobid
= attr
->values
[0].integer
;
7459 * Got a job URI; parse it to get the job ID...
7462 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7463 sizeof(scheme
), username
, sizeof(username
), host
,
7464 sizeof(host
), &port
, resource
, sizeof(resource
));
7466 if (strncmp(resource
, "/jobs/", 6))
7472 send_ipp_status(con
, IPP_BAD_REQUEST
,
7473 _("Bad job-uri \"%s\"."),
7474 uri
->values
[0].string
.text
);
7478 jobid
= atoi(resource
+ 6);
7482 * See if the job exists...
7485 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7488 * Nope - return a "not found" error...
7491 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7496 * See if the job is owned by the requesting user...
7499 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7501 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7502 cupsdFindDest(job
->dest
));
7507 * See if the job is in a state that allows holding...
7510 if (job
->state_value
> IPP_JOB_STOPPED
)
7513 * Return a "not-possible" error...
7516 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7517 _("Job #%d is finished and cannot be altered."),
7523 * Hold the job and return...
7526 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7527 IPP_TAG_KEYWORD
)) == NULL
)
7528 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7532 when
= attr
->values
[0].string
.text
;
7534 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7535 "Job job-hold-until value changed by user.");
7538 when
= "indefinite";
7540 cupsdSetJobHoldUntil(job
, when
, 1);
7541 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7544 con
->response
->request
.status
.status_code
= IPP_OK
;
7549 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7553 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7554 ipp_attribute_t
*uri
) /* I - Printer URI */
7556 http_status_t status
; /* Policy status */
7557 cups_ptype_t dtype
; /* Destination type (printer/class) */
7558 cupsd_printer_t
*printer
; /* Printer data */
7561 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7562 con
->http
.fd
, uri
->values
[0].string
.text
);
7565 * Is the destination valid?
7568 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7574 send_ipp_status(con
, IPP_NOT_FOUND
,
7575 _("The printer or class does not exist."));
7583 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7585 send_http_error(con
, status
, printer
);
7590 * Hold pending/new jobs sent to the printer...
7593 printer
->holding_new_jobs
= 1;
7595 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7597 if (dtype
& CUPS_PRINTER_CLASS
)
7598 cupsdLogMessage(CUPSD_LOG_INFO
,
7599 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7600 printer
->name
, get_username(con
));
7602 cupsdLogMessage(CUPSD_LOG_INFO
,
7603 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7604 printer
->name
, get_username(con
));
7607 * Everything was ok, so return OK status...
7610 con
->response
->request
.status
.status_code
= IPP_OK
;
7615 * 'move_job()' - Move a job to a new destination.
7619 move_job(cupsd_client_t
*con
, /* I - Client connection */
7620 ipp_attribute_t
*uri
) /* I - Job URI */
7622 http_status_t status
; /* Policy status */
7623 ipp_attribute_t
*attr
; /* Current attribute */
7624 int jobid
; /* Job ID */
7625 cupsd_job_t
*job
; /* Current job */
7626 const char *src
; /* Source printer/class */
7627 cups_ptype_t stype
, /* Source type (printer or class) */
7628 dtype
; /* Destination type (printer/class) */
7629 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7630 username
[HTTP_MAX_URI
], /* Username portion of URI */
7631 host
[HTTP_MAX_URI
], /* Host portion of URI */
7632 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7633 int port
; /* Port portion of URI */
7634 cupsd_printer_t
*sprinter
, /* Source printer */
7635 *dprinter
; /* Destination printer */
7638 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
7639 uri
->values
[0].string
.text
);
7642 * Get the new printer or class...
7645 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7646 IPP_TAG_URI
)) == NULL
)
7649 * Need job-printer-uri...
7652 send_ipp_status(con
, IPP_BAD_REQUEST
,
7653 _("job-printer-uri attribute missing."));
7657 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7663 send_ipp_status(con
, IPP_NOT_FOUND
,
7664 _("The printer or class does not exist."));
7669 * See if we have a job URI or a printer URI...
7672 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7673 sizeof(scheme
), username
, sizeof(username
), host
,
7674 sizeof(host
), &port
, resource
, sizeof(resource
));
7676 if (!strcmp(uri
->name
, "printer-uri"))
7679 * Got a printer URI; see if we also have a job-id attribute...
7682 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7683 IPP_TAG_INTEGER
)) == NULL
)
7689 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7690 &sprinter
)) == NULL
)
7696 send_ipp_status(con
, IPP_NOT_FOUND
,
7697 _("The printer or class does not exist."));
7706 * Otherwise, just move a single job...
7709 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7712 * Nope - return a "not found" error...
7715 send_ipp_status(con
, IPP_NOT_FOUND
,
7716 _("Job #%d does not exist."), attr
->values
[0].integer
);
7722 * Job found, initialize source pointers...
7733 * Got a job URI; parse it to get the job ID...
7736 if (strncmp(resource
, "/jobs/", 6))
7742 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7743 uri
->values
[0].string
.text
);
7748 * See if the job exists...
7751 jobid
= atoi(resource
+ 6);
7753 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7756 * Nope - return a "not found" error...
7759 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7765 * Job found, initialize source pointers...
7774 * Check the policy of the destination printer...
7777 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7778 job
? job
->username
: NULL
)) != HTTP_OK
)
7780 send_http_error(con
, status
, dprinter
);
7785 * Now move the job or jobs...
7791 * See if the job has been completed...
7794 if (job
->state_value
> IPP_JOB_STOPPED
)
7797 * Return a "not-possible" error...
7800 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7801 _("Job #%d is finished and cannot be altered."),
7807 * See if the job is owned by the requesting user...
7810 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7812 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7813 cupsdFindDest(job
->dest
));
7818 * Move the job to a different printer or class...
7821 cupsdMoveJob(job
, dprinter
);
7826 * Got the source printer, now look through the jobs...
7829 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7831 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7834 * See if the job is pointing at the source printer or has not been
7838 if (_cups_strcasecmp(job
->dest
, src
) ||
7839 job
->state_value
> IPP_JOB_STOPPED
)
7843 * See if the job can be moved by the requesting user...
7846 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7850 * Move the job to a different printer or class...
7853 cupsdMoveJob(job
, dprinter
);
7858 * Start jobs if possible...
7864 * Return with "everything is OK" status...
7867 con
->response
->request
.status
.status_code
= IPP_OK
;
7872 * 'ppd_parse_line()' - Parse a PPD default line.
7875 static int /* O - 0 on success, -1 on failure */
7876 ppd_parse_line(const char *line
, /* I - Line */
7877 char *option
, /* O - Option name */
7878 int olen
, /* I - Size of option name */
7879 char *choice
, /* O - Choice name */
7880 int clen
) /* I - Size of choice name */
7883 * Verify this is a default option line...
7886 if (strncmp(line
, "*Default", 8))
7890 * Read the option name...
7893 for (line
+= 8, olen
--;
7894 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7905 * Skip everything else up to the colon (:)...
7908 while (*line
&& *line
!= ':')
7917 * Now grab the option choice, skipping leading whitespace...
7920 while (isspace(*line
& 255))
7924 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7935 * Return with no errors...
7943 * 'print_job()' - Print a file to a printer or class.
7947 print_job(cupsd_client_t
*con
, /* I - Client connection */
7948 ipp_attribute_t
*uri
) /* I - Printer URI */
7950 ipp_attribute_t
*attr
; /* Current attribute */
7951 ipp_attribute_t
*format
; /* Document-format attribute */
7952 const char *default_format
; /* document-format-default value */
7953 cupsd_job_t
*job
; /* New job */
7954 char filename
[1024]; /* Job filename */
7955 mime_type_t
*filetype
; /* Type of file */
7956 char super
[MIME_MAX_SUPER
], /* Supertype of file */
7957 type
[MIME_MAX_TYPE
], /* Subtype of file */
7958 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
7959 /* Textual name of mime type */
7960 cupsd_printer_t
*printer
; /* Printer data */
7961 struct stat fileinfo
; /* File information */
7962 int kbytes
; /* Size of file */
7963 int compression
; /* Document compression */
7966 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
7967 uri
->values
[0].string
.text
);
7970 * Validate print file attributes, for now just document-format and
7971 * compression (CUPS only supports "none" and "gzip")...
7974 compression
= CUPS_FILE_NONE
;
7976 if ((attr
= ippFindAttribute(con
->request
, "compression",
7977 IPP_TAG_KEYWORD
)) != NULL
)
7979 if (strcmp(attr
->values
[0].string
.text
, "none")
7981 && strcmp(attr
->values
[0].string
.text
, "gzip")
7982 #endif /* HAVE_LIBZ */
7985 send_ipp_status(con
, IPP_ATTRIBUTES
,
7986 _("Unsupported compression \"%s\"."),
7987 attr
->values
[0].string
.text
);
7988 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7989 "compression", NULL
, attr
->values
[0].string
.text
);
7994 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
7995 compression
= CUPS_FILE_GZIP
;
7996 #endif /* HAVE_LIBZ */
8000 * Do we have a file to print?
8005 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8010 * Is the destination valid?
8013 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8019 send_ipp_status(con
, IPP_NOT_FOUND
,
8020 _("The printer or class does not exist."));
8025 * Is it a format we support?
8028 if ((format
= ippFindAttribute(con
->request
, "document-format",
8029 IPP_TAG_MIMETYPE
)) != NULL
)
8032 * Grab format from client...
8035 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8038 send_ipp_status(con
, IPP_BAD_REQUEST
,
8039 _("Bad document-format \"%s\"."),
8040 format
->values
[0].string
.text
);
8044 else if ((default_format
= cupsGetOption("document-format",
8045 printer
->num_options
,
8046 printer
->options
)) != NULL
)
8049 * Use default document format...
8052 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8054 send_ipp_status(con
, IPP_BAD_REQUEST
,
8055 _("Bad document-format \"%s\"."),
8066 strlcpy(super
, "application", sizeof(super
));
8067 strlcpy(type
, "octet-stream", sizeof(type
));
8070 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8073 * Auto-type the file...
8076 ipp_attribute_t
*doc_name
; /* document-name attribute */
8079 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8081 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8082 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8083 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8087 filetype
= mimeType(MimeDatabase
, super
, type
);
8089 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8090 filetype
->super
, filetype
->type
);
8093 filetype
= mimeType(MimeDatabase
, super
, type
);
8097 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8100 * Replace the document-format attribute value with the auto-typed or
8104 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8109 _cupsStrFree(format
->values
[0].string
.text
);
8111 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8114 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8115 "document-format", NULL
, mimetype
);
8119 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8120 _("Unsupported document-format \"%s\"."),
8121 format
? format
->values
[0].string
.text
:
8122 "application/octet-stream");
8123 cupsdLogMessage(CUPSD_LOG_INFO
,
8124 "Hint: Do you have the raw file printing rules enabled?");
8127 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8128 "document-format", NULL
, format
->values
[0].string
.text
);
8134 * Read any embedded job ticket info from PS files...
8137 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8138 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8139 !_cups_strcasecmp(filetype
->type
, "pdf")))
8140 read_job_ticket(con
);
8143 * Create the job object...
8146 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8150 * Update quota data...
8153 if (stat(con
->filename
, &fileinfo
))
8156 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8158 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8160 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8161 IPP_TAG_INTEGER
)) != NULL
)
8162 attr
->values
[0].integer
+= kbytes
;
8165 * Add the job file...
8168 if (add_file(con
, job
, filetype
, compression
))
8171 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8173 rename(con
->filename
, filename
);
8174 cupsdClearString(&con
->filename
);
8177 * See if we need to add the ending sheet...
8180 if (cupsdTimeoutJob(job
))
8184 * Log and save the job...
8187 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8188 "File of type %s/%s queued by \"%s\".",
8189 filetype
->super
, filetype
->type
, job
->username
);
8190 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8191 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8192 job
->dest
, job
->username
);
8195 * Start the job if possible...
8203 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8205 * This function only gets called when printing a single PDF or PostScript
8206 * file using the Print-Job operation. It doesn't work for Create-Job +
8207 * Send-File, since the job attributes need to be set at job creation
8208 * time for banners to work. The embedded job ticket stuff is here
8209 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8210 * options and IPP attributes which otherwise would be lost.
8212 * The format of a job ticket is simple:
8214 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8216 * %cupsJobTicket: attr1=value1
8217 * %cupsJobTicket: attr2=value2
8219 * %cupsJobTicket: attrN=valueN
8221 * Job ticket lines must appear immediately after the first line that
8222 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8223 * stops looking for job ticket info when it finds a line that does not begin
8224 * with "%cupsJobTicket:".
8226 * The maximum length of a job ticket line, including the prefix, is
8227 * 255 characters to conform with the Adobe DSC.
8229 * Read-only attributes are rejected with a notice to the error log in
8230 * case a malicious user tries anything. Since the job ticket is read
8231 * prior to attribute validation in print_job(), job ticket attributes
8232 * will go through the same validation as IPP attributes...
8236 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8238 cups_file_t
*fp
; /* File to read from */
8239 char line
[256]; /* Line data */
8240 int num_options
; /* Number of options */
8241 cups_option_t
*options
; /* Options */
8242 ipp_t
*ticket
; /* New attributes */
8243 ipp_attribute_t
*attr
, /* Current attribute */
8244 *attr2
, /* Job attribute */
8245 *prev2
; /* Previous job attribute */
8249 * First open the print file...
8252 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8254 cupsdLogMessage(CUPSD_LOG_ERROR
,
8255 "Unable to open print file for job ticket - %s",
8261 * Skip the first line...
8264 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8266 cupsdLogMessage(CUPSD_LOG_ERROR
,
8267 "Unable to read from print file for job ticket - %s",
8273 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8276 * Not a DSC-compliant file, so no job ticket info will be available...
8284 * Read job ticket info from the file...
8290 while (cupsFileGets(fp
, line
, sizeof(line
)))
8293 * Stop at the first non-ticket line...
8296 if (strncmp(line
, "%cupsJobTicket:", 15))
8300 * Add the options to the option array...
8303 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8307 * Done with the file; see if we have any options...
8312 if (num_options
== 0)
8316 * OK, convert the options to an attribute list, and apply them to
8321 cupsEncodeOptions(ticket
, num_options
, options
);
8324 * See what the user wants to change.
8327 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8329 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8332 if (!strcmp(attr
->name
, "job-originating-host-name") ||
8333 !strcmp(attr
->name
, "job-originating-user-name") ||
8334 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8335 !strcmp(attr
->name
, "job-k-octets") ||
8336 !strcmp(attr
->name
, "job-id") ||
8337 !strncmp(attr
->name
, "job-state", 9) ||
8338 !strncmp(attr
->name
, "time-at-", 8))
8339 continue; /* Read-only attrs */
8341 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8342 IPP_TAG_ZERO
)) != NULL
)
8345 * Some other value; first free the old value...
8348 if (con
->request
->attrs
== attr2
)
8350 con
->request
->attrs
= attr2
->next
;
8355 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8356 if (prev2
->next
== attr2
)
8358 prev2
->next
= attr2
->next
;
8363 if (con
->request
->last
== attr2
)
8364 con
->request
->last
= prev2
;
8366 ippDeleteAttribute(NULL
, attr2
);
8370 * Add new option by copying it...
8373 ippCopyAttribute(con
->request
, attr
, 0);
8377 * Then free the attribute list and option array...
8381 cupsFreeOptions(num_options
, options
);
8386 * 'reject_jobs()' - Reject print jobs to a printer.
8390 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8391 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8393 http_status_t status
; /* Policy status */
8394 cups_ptype_t dtype
; /* Destination type (printer/class) */
8395 cupsd_printer_t
*printer
; /* Printer data */
8396 ipp_attribute_t
*attr
; /* printer-state-message text */
8399 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8400 con
->http
.fd
, uri
->values
[0].string
.text
);
8403 * Is the destination valid?
8406 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8412 send_ipp_status(con
, IPP_NOT_FOUND
,
8413 _("The printer or class does not exist."));
8421 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8423 send_http_error(con
, status
, printer
);
8428 * Reject jobs sent to the printer...
8431 printer
->accepting
= 0;
8433 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8434 IPP_TAG_TEXT
)) == NULL
)
8435 strlcpy(printer
->state_message
, "Rejecting Jobs",
8436 sizeof(printer
->state_message
));
8438 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8439 sizeof(printer
->state_message
));
8441 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8442 "No longer accepting jobs.");
8444 if (dtype
& CUPS_PRINTER_CLASS
)
8446 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8448 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8449 printer
->name
, get_username(con
));
8453 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8455 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8456 printer
->name
, get_username(con
));
8460 * Everything was ok, so return OK status...
8463 con
->response
->request
.status
.status_code
= IPP_OK
;
8468 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8472 release_held_new_jobs(
8473 cupsd_client_t
*con
, /* I - Connection */
8474 ipp_attribute_t
*uri
) /* I - Printer URI */
8476 http_status_t status
; /* Policy status */
8477 cups_ptype_t dtype
; /* Destination type (printer/class) */
8478 cupsd_printer_t
*printer
; /* Printer data */
8481 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8482 con
->http
.fd
, uri
->values
[0].string
.text
);
8485 * Is the destination valid?
8488 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8494 send_ipp_status(con
, IPP_NOT_FOUND
,
8495 _("The printer or class does not exist."));
8503 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8505 send_http_error(con
, status
, printer
);
8510 * Hold pending/new jobs sent to the printer...
8513 printer
->holding_new_jobs
= 0;
8515 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8517 if (dtype
& CUPS_PRINTER_CLASS
)
8518 cupsdLogMessage(CUPSD_LOG_INFO
,
8519 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8520 printer
->name
, get_username(con
));
8522 cupsdLogMessage(CUPSD_LOG_INFO
,
8523 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8524 printer
->name
, get_username(con
));
8527 * Everything was ok, so return OK status...
8530 con
->response
->request
.status
.status_code
= IPP_OK
;
8535 * 'release_job()' - Release a held print job.
8539 release_job(cupsd_client_t
*con
, /* I - Client connection */
8540 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8542 ipp_attribute_t
*attr
; /* Current attribute */
8543 int jobid
; /* Job ID */
8544 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8545 username
[HTTP_MAX_URI
], /* Username portion of URI */
8546 host
[HTTP_MAX_URI
], /* Host portion of URI */
8547 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8548 int port
; /* Port portion of URI */
8549 cupsd_job_t
*job
; /* Job information */
8552 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8553 con
->http
.fd
, uri
->values
[0].string
.text
);
8556 * See if we have a job URI or a printer URI...
8559 if (!strcmp(uri
->name
, "printer-uri"))
8562 * Got a printer URI; see if we also have a job-id attribute...
8565 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8566 IPP_TAG_INTEGER
)) == NULL
)
8568 send_ipp_status(con
, IPP_BAD_REQUEST
,
8569 _("Got a printer-uri attribute but no job-id."));
8573 jobid
= attr
->values
[0].integer
;
8578 * Got a job URI; parse it to get the job ID...
8581 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8582 sizeof(scheme
), username
, sizeof(username
), host
,
8583 sizeof(host
), &port
, resource
, sizeof(resource
));
8585 if (strncmp(resource
, "/jobs/", 6))
8591 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8592 uri
->values
[0].string
.text
);
8596 jobid
= atoi(resource
+ 6);
8600 * See if the job exists...
8603 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8606 * Nope - return a "not found" error...
8609 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8614 * See if job is "held"...
8617 if (job
->state_value
!= IPP_JOB_HELD
)
8620 * Nope - return a "not possible" error...
8623 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8628 * See if the job is owned by the requesting user...
8631 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8633 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8634 cupsdFindDest(job
->dest
));
8639 * Reset the job-hold-until value to "no-hold"...
8642 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8643 IPP_TAG_KEYWORD
)) == NULL
)
8644 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8648 _cupsStrFree(attr
->values
[0].string
.text
);
8650 attr
->value_tag
= IPP_TAG_KEYWORD
;
8651 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
8653 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8654 "Job job-hold-until value changed by user.");
8655 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8659 * Release the job and return...
8662 cupsdReleaseJob(job
);
8664 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8665 "Job released by user.");
8667 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8669 con
->response
->request
.status
.status_code
= IPP_OK
;
8676 * 'renew_subscription()' - Renew an existing subscription...
8681 cupsd_client_t
*con
, /* I - Client connection */
8682 int sub_id
) /* I - Subscription ID */
8684 http_status_t status
; /* Policy status */
8685 cupsd_subscription_t
*sub
; /* Subscription */
8686 ipp_attribute_t
*lease
; /* notify-lease-duration */
8689 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8690 "renew_subscription(con=%p[%d], sub_id=%d)",
8691 con
, con
->http
.fd
, sub_id
);
8694 * Is the subscription ID valid?
8697 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8700 * Bad subscription ID...
8703 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8711 * Job subscriptions cannot be renewed...
8714 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8715 _("Job subscriptions cannot be renewed."));
8723 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8725 con
, sub
->owner
)) != HTTP_OK
)
8727 send_http_error(con
, status
, sub
->dest
);
8732 * Renew the subscription...
8735 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8738 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8740 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8742 cupsdLogMessage(CUPSD_LOG_INFO
,
8743 "renew_subscription: Limiting notify-lease-duration to "
8746 sub
->lease
= MaxLeaseDuration
;
8749 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8751 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8753 con
->response
->request
.status
.status_code
= IPP_OK
;
8755 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8756 "notify-lease-duration", sub
->lease
);
8761 * 'restart_job()' - Restart an old print job.
8765 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8766 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8768 ipp_attribute_t
*attr
; /* Current attribute */
8769 int jobid
; /* Job ID */
8770 cupsd_job_t
*job
; /* Job information */
8771 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8772 username
[HTTP_MAX_URI
], /* Username portion of URI */
8773 host
[HTTP_MAX_URI
], /* Host portion of URI */
8774 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8775 int port
; /* Port portion of URI */
8778 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8779 con
->http
.fd
, uri
->values
[0].string
.text
);
8782 * See if we have a job URI or a printer URI...
8785 if (!strcmp(uri
->name
, "printer-uri"))
8788 * Got a printer URI; see if we also have a job-id attribute...
8791 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8792 IPP_TAG_INTEGER
)) == NULL
)
8794 send_ipp_status(con
, IPP_BAD_REQUEST
,
8795 _("Got a printer-uri attribute but no job-id."));
8799 jobid
= attr
->values
[0].integer
;
8804 * Got a job URI; parse it to get the job ID...
8807 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8808 sizeof(scheme
), username
, sizeof(username
), host
,
8809 sizeof(host
), &port
, resource
, sizeof(resource
));
8811 if (strncmp(resource
, "/jobs/", 6))
8817 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8818 uri
->values
[0].string
.text
);
8822 jobid
= atoi(resource
+ 6);
8826 * See if the job exists...
8829 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8832 * Nope - return a "not found" error...
8835 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8840 * See if job is in any of the "completed" states...
8843 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8846 * Nope - return a "not possible" error...
8849 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
8855 * See if we have retained the job files...
8860 if (!job
->attrs
|| job
->num_files
== 0)
8863 * Nope - return a "not possible" error...
8866 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8867 _("Job #%d cannot be restarted - no files."), jobid
);
8872 * See if the job is owned by the requesting user...
8875 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8877 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8878 cupsdFindDest(job
->dest
));
8883 * See if the job-hold-until attribute is specified...
8886 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8887 IPP_TAG_KEYWORD
)) == NULL
)
8888 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8890 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
8893 * Return the job to a held state...
8896 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
8897 "Restarted by \"%s\" with job-hold-until=%s.",
8898 username
, attr
->values
[0].string
.text
);
8899 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
8901 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
8902 NULL
, job
, "Job restarted by user with job-hold-until=%s",
8903 attr
->values
[0].string
.text
);
8908 * Restart the job...
8911 cupsdRestartJob(job
);
8915 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
8917 con
->response
->request
.status
.status_code
= IPP_OK
;
8922 * 'save_auth_info()' - Save authentication information for a job.
8927 cupsd_client_t
*con
, /* I - Client connection */
8928 cupsd_job_t
*job
, /* I - Job */
8929 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
8931 int i
; /* Looping var */
8932 char filename
[1024]; /* Job authentication filename */
8933 cups_file_t
*fp
; /* Job authentication file */
8934 char line
[65536]; /* Line for file */
8935 cupsd_printer_t
*dest
; /* Destination printer/class */
8939 * This function saves the in-memory authentication information for
8940 * a job so that it can be used to authenticate with a remote host.
8941 * The information is stored in a file that is readable only by the
8942 * root user. The fields are Base-64 encoded, each on a separate line,
8943 * followed by random number (up to 1024) of newlines to limit the
8944 * amount of information that is exposed.
8946 * Because of the potential for exposing of authentication information,
8947 * this functionality is only enabled when running cupsd as root.
8949 * This caching only works for the Basic and BasicDigest authentication
8950 * types. Digest authentication cannot be cached this way, and in
8951 * the future Kerberos authentication may make all of this obsolete.
8953 * Authentication information is saved whenever an authenticated
8954 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
8957 * This information is deleted after a job is completed or canceled,
8958 * so reprints may require subsequent re-authentication.
8964 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
8968 * Create the authentication file and change permissions...
8971 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
8972 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
8974 cupsdLogMessage(CUPSD_LOG_ERROR
,
8975 "Unable to save authentication info to \"%s\" - %s",
8976 filename
, strerror(errno
));
8980 fchown(cupsFileNumber(fp
), 0, 0);
8981 fchmod(cupsFileNumber(fp
), 0400);
8983 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
8986 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
8988 cupsdClearString(job
->auth_env
+ i
);
8990 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
8993 * Write 1 to 3 auth values...
8997 i
< auth_info
->num_values
&&
8998 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9001 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9003 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
9004 strlen(auth_info
->values
[i
].string
.text
));
9005 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9008 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9009 auth_info
->values
[i
].string
.text
);
9011 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9012 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9013 auth_info
->values
[i
].string
.text
);
9014 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9015 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9016 auth_info
->values
[i
].string
.text
);
9017 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9018 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9019 auth_info
->values
[i
].string
.text
);
9020 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9021 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9022 auth_info
->values
[i
].string
.text
);
9027 else if (auth_info
&& auth_info
->num_values
== 2 &&
9028 dest
->num_auth_info_required
== 1 &&
9029 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9032 * Allow fallback to username+password for Kerberized queues...
9035 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
,
9036 strlen(auth_info
->values
[0].string
.text
));
9037 cupsFilePutConf(fp
, "username", line
);
9039 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9040 auth_info
->values
[0].string
.text
);
9042 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
,
9043 strlen(auth_info
->values
[1].string
.text
));
9044 cupsFilePutConf(fp
, "password", line
);
9046 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9047 auth_info
->values
[1].string
.text
);
9049 else if (con
->username
[0])
9052 * Write the authenticated username...
9055 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
9056 cupsFilePutConf(fp
, "username", line
);
9058 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9061 * Write the authenticated password...
9064 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
9065 cupsFilePutConf(fp
, "password", line
);
9067 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9071 if (con
->gss_uid
> 0)
9073 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9074 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9076 #endif /* HAVE_GSSAPI */
9079 * Write a random number of newlines to the end of the file...
9082 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9083 cupsFilePutChar(fp
, '\n');
9086 * Close the file and return...
9094 * 'send_document()' - Send a file to a printer or class.
9098 send_document(cupsd_client_t
*con
, /* I - Client connection */
9099 ipp_attribute_t
*uri
) /* I - Printer URI */
9101 ipp_attribute_t
*attr
; /* Current attribute */
9102 ipp_attribute_t
*format
; /* Request's document-format attribute */
9103 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9104 const char *default_format
;/* document-format-default value */
9105 int jobid
; /* Job ID number */
9106 cupsd_job_t
*job
; /* Current job */
9107 char job_uri
[HTTP_MAX_URI
],
9109 scheme
[HTTP_MAX_URI
],
9110 /* Method portion of URI */
9111 username
[HTTP_MAX_URI
],
9112 /* Username portion of URI */
9114 /* Host portion of URI */
9115 resource
[HTTP_MAX_URI
];
9116 /* Resource portion of URI */
9117 int port
; /* Port portion of URI */
9118 mime_type_t
*filetype
; /* Type of file */
9119 char super
[MIME_MAX_SUPER
],
9120 /* Supertype of file */
9121 type
[MIME_MAX_TYPE
],
9122 /* Subtype of file */
9123 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9124 /* Textual name of mime type */
9125 char filename
[1024]; /* Job filename */
9126 cupsd_printer_t
*printer
; /* Current printer */
9127 struct stat fileinfo
; /* File information */
9128 int kbytes
; /* Size of file */
9129 int compression
; /* Type of compression */
9130 int start_job
; /* Start the job? */
9133 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9134 con
->http
.fd
, uri
->values
[0].string
.text
);
9137 * See if we have a job URI or a printer URI...
9140 if (!strcmp(uri
->name
, "printer-uri"))
9143 * Got a printer URI; see if we also have a job-id attribute...
9146 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9147 IPP_TAG_INTEGER
)) == NULL
)
9149 send_ipp_status(con
, IPP_BAD_REQUEST
,
9150 _("Got a printer-uri attribute but no job-id."));
9154 jobid
= attr
->values
[0].integer
;
9159 * Got a job URI; parse it to get the job ID...
9162 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9163 sizeof(scheme
), username
, sizeof(username
), host
,
9164 sizeof(host
), &port
, resource
, sizeof(resource
));
9166 if (strncmp(resource
, "/jobs/", 6))
9172 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9173 uri
->values
[0].string
.text
);
9177 jobid
= atoi(resource
+ 6);
9181 * See if the job exists...
9184 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9187 * Nope - return a "not found" error...
9190 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9194 printer
= cupsdFindDest(job
->dest
);
9197 * See if the job is owned by the requesting user...
9200 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9202 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9203 cupsdFindDest(job
->dest
));
9208 * OK, see if the client is sending the document compressed - CUPS
9209 * only supports "none" and "gzip".
9212 compression
= CUPS_FILE_NONE
;
9214 if ((attr
= ippFindAttribute(con
->request
, "compression",
9215 IPP_TAG_KEYWORD
)) != NULL
)
9217 if (strcmp(attr
->values
[0].string
.text
, "none")
9219 && strcmp(attr
->values
[0].string
.text
, "gzip")
9220 #endif /* HAVE_LIBZ */
9223 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9224 attr
->values
[0].string
.text
);
9225 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9226 "compression", NULL
, attr
->values
[0].string
.text
);
9231 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9232 compression
= CUPS_FILE_GZIP
;
9233 #endif /* HAVE_LIBZ */
9237 * Do we have a file to print?
9240 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9241 IPP_TAG_BOOLEAN
)) == NULL
)
9243 send_ipp_status(con
, IPP_BAD_REQUEST
,
9244 _("Missing last-document attribute in request."));
9251 * Check for an empty request with "last-document" set to true, which is
9252 * used to close an "open" job by RFC 2911, section 3.3.2.
9255 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9258 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9263 * Is it a format we support?
9266 if ((format
= ippFindAttribute(con
->request
, "document-format",
9267 IPP_TAG_MIMETYPE
)) != NULL
)
9270 * Grab format from client...
9273 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9276 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9277 format
->values
[0].string
.text
);
9281 else if ((default_format
= cupsGetOption("document-format",
9282 printer
->num_options
,
9283 printer
->options
)) != NULL
)
9286 * Use default document format...
9289 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9291 send_ipp_status(con
, IPP_BAD_REQUEST
,
9292 _("Bad document-format-default \"%s\"."), default_format
);
9299 * No document format attribute? Auto-type it!
9302 strlcpy(super
, "application", sizeof(super
));
9303 strlcpy(type
, "octet-stream", sizeof(type
));
9306 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9309 * Auto-type the file...
9312 ipp_attribute_t
*doc_name
; /* document-name attribute */
9315 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9317 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9318 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9319 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9323 filetype
= mimeType(MimeDatabase
, super
, type
);
9326 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9327 filetype
->super
, filetype
->type
);
9330 filetype
= mimeType(MimeDatabase
, super
, type
);
9335 * Replace the document-format attribute value with the auto-typed or
9339 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9342 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9343 IPP_TAG_MIMETYPE
)) != NULL
)
9345 _cupsStrFree(jformat
->values
[0].string
.text
);
9347 jformat
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
9350 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9351 "document-format", NULL
, mimetype
);
9355 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9356 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9357 cupsdLogMessage(CUPSD_LOG_INFO
,
9358 "Hint: Do you have the raw file printing rules enabled?");
9361 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9362 "document-format", NULL
, format
->values
[0].string
.text
);
9367 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9369 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9372 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9373 _("Unsupported document-format \"%s\"."), mimetype
);
9375 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9376 "document-format", NULL
, mimetype
);
9382 * Add the file to the job...
9387 if (add_file(con
, job
, filetype
, compression
))
9390 if (stat(con
->filename
, &fileinfo
))
9393 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9395 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9397 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
9398 IPP_TAG_INTEGER
)) != NULL
)
9399 attr
->values
[0].integer
+= kbytes
;
9401 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
9403 rename(con
->filename
, filename
);
9405 cupsdClearString(&con
->filename
);
9407 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9408 filetype
->super
, filetype
->type
, job
->username
);
9411 * Start the job if this is the last document...
9416 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9417 IPP_TAG_BOOLEAN
)) != NULL
&&
9418 attr
->values
[0].boolean
)
9421 * See if we need to add the ending sheet...
9424 if (cupsdTimeoutJob(job
))
9427 if (job
->state_value
== IPP_JOB_STOPPED
)
9429 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9430 job
->state_value
= IPP_JOB_PENDING
;
9432 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9434 else if (job
->state_value
== IPP_JOB_HELD
)
9436 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9437 IPP_TAG_KEYWORD
)) == NULL
)
9438 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9440 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9442 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9443 job
->state_value
= IPP_JOB_PENDING
;
9445 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9448 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9452 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9458 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9459 IPP_TAG_KEYWORD
)) == NULL
)
9460 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9462 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9464 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9465 job
->state_value
= IPP_JOB_HELD
;
9466 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9468 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9471 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9478 * Fill in the response info...
9481 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9482 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9483 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9486 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9488 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9490 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9491 NULL
, job
->reasons
->values
[0].string
.text
);
9493 con
->response
->request
.status
.status_code
= IPP_OK
;
9496 * Start the job if necessary...
9505 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9510 cupsd_client_t
*con
, /* I - Client connection */
9511 http_status_t status
, /* I - HTTP status code */
9512 cupsd_printer_t
*printer
) /* I - Printer, if any */
9514 ipp_attribute_t
*uri
; /* Request URI, if any */
9517 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9518 IPP_TAG_URI
)) == NULL
)
9519 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9521 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9522 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9523 con
->http
.fd
, httpStatus(status
),
9525 ippOpString(con
->request
->request
.op
.operation_id
) :
9527 uri
? uri
->values
[0].string
.text
: "no URI",
9528 con
->http
.hostname
);
9532 int auth_type
; /* Type of authentication required */
9535 auth_type
= CUPSD_AUTH_NONE
;
9537 if (status
== HTTP_UNAUTHORIZED
&&
9538 printer
->num_auth_info_required
> 0 &&
9539 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9541 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9542 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9543 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9546 * Creating and authenticating jobs requires Kerberos...
9549 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9554 * Use policy/location-defined authentication requirements...
9557 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9558 cupsd_location_t
*auth
; /* Pointer to authentication element */
9561 if (printer
->type
& CUPS_PRINTER_CLASS
)
9562 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9564 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9566 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9567 auth
->type
== CUPSD_AUTH_NONE
)
9568 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9570 con
->request
->request
.op
.operation_id
:
9575 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9576 auth_type
= cupsdDefaultAuthType();
9578 auth_type
= auth
->type
;
9582 cupsdSendError(con
, status
, auth_type
);
9585 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9587 ippDelete(con
->response
);
9588 con
->response
= NULL
;
9595 * 'send_ipp_status()' - Send a status back to the IPP client.
9599 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9600 ipp_status_t status
, /* I - IPP status code */
9601 const char *message
,/* I - Status message */
9602 ...) /* I - Additional args as needed */
9604 va_list ap
; /* Pointer to additional args */
9605 char formatted
[1024]; /* Formatted errror message */
9608 va_start(ap
, message
);
9609 vsnprintf(formatted
, sizeof(formatted
),
9610 _cupsLangString(con
->language
, message
), ap
);
9613 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9614 ippOpString(con
->request
->request
.op
.operation_id
),
9615 ippErrorString(status
), formatted
);
9617 con
->response
->request
.status
.status_code
= status
;
9619 if (ippFindAttribute(con
->response
, "attributes-charset",
9620 IPP_TAG_ZERO
) == NULL
)
9621 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9622 "attributes-charset", NULL
, "utf-8");
9624 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9625 IPP_TAG_ZERO
) == NULL
)
9626 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9627 "attributes-natural-language", NULL
, DefaultLanguage
);
9629 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9630 "status-message", NULL
, formatted
);
9635 * 'set_default()' - Set the default destination...
9639 set_default(cupsd_client_t
*con
, /* I - Client connection */
9640 ipp_attribute_t
*uri
) /* I - Printer URI */
9642 http_status_t status
; /* Policy status */
9643 cups_ptype_t dtype
; /* Destination type (printer/class) */
9644 cupsd_printer_t
*printer
, /* Printer */
9645 *oldprinter
; /* Old default printer */
9648 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9649 con
->http
.fd
, uri
->values
[0].string
.text
);
9652 * Is the destination valid?
9655 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9661 send_ipp_status(con
, IPP_NOT_FOUND
,
9662 _("The printer or class does not exist."));
9670 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9672 send_http_error(con
, status
, NULL
);
9677 * Set it as the default...
9680 oldprinter
= DefaultPrinter
;
9681 DefaultPrinter
= printer
;
9684 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9685 "%s is no longer the default printer.", oldprinter
->name
);
9687 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9688 "%s is now the default printer.", printer
->name
);
9690 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9691 CUPSD_DIRTY_PRINTCAP
);
9693 cupsdLogMessage(CUPSD_LOG_INFO
,
9694 "Default destination set to \"%s\" by \"%s\".",
9695 printer
->name
, get_username(con
));
9698 * Everything was ok, so return OK status...
9701 con
->response
->request
.status
.status_code
= IPP_OK
;
9706 * 'set_job_attrs()' - Set job attributes.
9710 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9711 ipp_attribute_t
*uri
) /* I - Job URI */
9713 ipp_attribute_t
*attr
, /* Current attribute */
9714 *attr2
; /* Job attribute */
9715 int jobid
; /* Job ID */
9716 cupsd_job_t
*job
; /* Current job */
9717 char scheme
[HTTP_MAX_URI
],
9718 /* Method portion of URI */
9719 username
[HTTP_MAX_URI
],
9720 /* Username portion of URI */
9722 /* Host portion of URI */
9723 resource
[HTTP_MAX_URI
];
9724 /* Resource portion of URI */
9725 int port
; /* Port portion of URI */
9726 int event
; /* Events? */
9727 int check_jobs
; /* Check jobs? */
9730 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9731 con
->http
.fd
, uri
->values
[0].string
.text
);
9734 * Start with "everything is OK" status...
9737 con
->response
->request
.status
.status_code
= IPP_OK
;
9740 * See if we have a job URI or a printer URI...
9743 if (!strcmp(uri
->name
, "printer-uri"))
9746 * Got a printer URI; see if we also have a job-id attribute...
9749 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9750 IPP_TAG_INTEGER
)) == NULL
)
9752 send_ipp_status(con
, IPP_BAD_REQUEST
,
9753 _("Got a printer-uri attribute but no job-id."));
9757 jobid
= attr
->values
[0].integer
;
9762 * Got a job URI; parse it to get the job ID...
9765 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9766 sizeof(scheme
), username
, sizeof(username
), host
,
9767 sizeof(host
), &port
, resource
, sizeof(resource
));
9769 if (strncmp(resource
, "/jobs/", 6))
9775 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9776 uri
->values
[0].string
.text
);
9780 jobid
= atoi(resource
+ 6);
9784 * See if the job exists...
9787 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9790 * Nope - return a "not found" error...
9793 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9798 * See if the job has been completed...
9801 if (job
->state_value
> IPP_JOB_STOPPED
)
9804 * Return a "not-possible" error...
9807 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9808 _("Job #%d is finished and cannot be altered."), jobid
);
9813 * See if the job is owned by the requesting user...
9816 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9818 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9819 cupsdFindDest(job
->dest
));
9824 * See what the user wants to change.
9832 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9834 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9837 if (!strcmp(attr
->name
, "attributes-charset") ||
9838 !strcmp(attr
->name
, "attributes-natural-language") ||
9839 !strcmp(attr
->name
, "document-compression") ||
9840 !strcmp(attr
->name
, "document-format") ||
9841 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9842 !strcmp(attr
->name
, "job-document-access-errors") ||
9843 !strcmp(attr
->name
, "job-id") ||
9844 !strcmp(attr
->name
, "job-impressions-completed") ||
9845 !strcmp(attr
->name
, "job-k-octets") ||
9846 !strcmp(attr
->name
, "job-originating-host-name") ||
9847 !strcmp(attr
->name
, "job-originating-user-name") ||
9848 !strcmp(attr
->name
, "job-printer-up-time") ||
9849 !strcmp(attr
->name
, "job-printer-uri") ||
9850 !strcmp(attr
->name
, "job-sheets") ||
9851 !strcmp(attr
->name
, "job-state-message") ||
9852 !strcmp(attr
->name
, "job-state-reasons") ||
9853 !strcmp(attr
->name
, "job-uri") ||
9854 !strcmp(attr
->name
, "number-of-documents") ||
9855 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9856 !strcmp(attr
->name
, "output-device-assigned") ||
9857 !strncmp(attr
->name
, "date-time-at-", 13) ||
9858 !strncmp(attr
->name
, "job-k-octets", 12) ||
9859 !strncmp(attr
->name
, "job-media-sheets", 16) ||
9860 !strncmp(attr
->name
, "time-at-", 8))
9866 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
9867 _("%s cannot be changed."), attr
->name
);
9869 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9870 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9874 if (!strcmp(attr
->name
, "job-priority"))
9877 * Change the job priority...
9880 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
9882 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
9884 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9885 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9887 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
9889 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9890 _("Job is completed and cannot be changed."));
9893 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9895 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
9896 attr
->values
[0].integer
);
9897 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
9900 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
9901 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
9904 else if (!strcmp(attr
->name
, "job-state"))
9907 * Change the job state...
9910 if (attr
->value_tag
!= IPP_TAG_ENUM
)
9912 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
9914 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9915 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9919 switch (attr
->values
[0].integer
)
9921 case IPP_JOB_PENDING
:
9923 if (job
->state_value
> IPP_JOB_HELD
)
9925 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9926 _("Job state cannot be changed."));
9929 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9931 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
9932 attr
->values
[0].integer
);
9933 cupsdSetJobState(job
, attr
->values
[0].integer
,
9935 "Job state changed by \"%s\"", username
);
9940 case IPP_JOB_PROCESSING
:
9941 case IPP_JOB_STOPPED
:
9942 if (job
->state_value
!= attr
->values
[0].integer
)
9944 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9945 _("Job state cannot be changed."));
9950 case IPP_JOB_CANCELED
:
9951 case IPP_JOB_ABORTED
:
9952 case IPP_JOB_COMPLETED
:
9953 if (job
->state_value
> IPP_JOB_PROCESSING
)
9955 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9956 _("Job state cannot be changed."));
9959 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9961 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
9962 attr
->values
[0].integer
);
9963 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
9965 "Job state changed by \"%s\"", username
);
9972 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
9974 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
9975 IPP_TAG_ZERO
)) != NULL
)
9978 * Some other value; first free the old value...
9981 if (job
->attrs
->prev
)
9982 job
->attrs
->prev
->next
= attr2
->next
;
9984 job
->attrs
->attrs
= attr2
->next
;
9986 if (job
->attrs
->last
== attr2
)
9987 job
->attrs
->last
= job
->attrs
->prev
;
9989 ippDeleteAttribute(NULL
, attr2
);
9992 * Then copy the attribute...
9995 ippCopyAttribute(job
->attrs
, attr
, 0);
9998 * See if the job-name or job-hold-until is being changed.
10001 if (!strcmp(attr
->name
, "job-hold-until"))
10003 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10004 attr
->values
[0].string
.text
);
10005 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10007 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10009 cupsdReleaseJob(job
);
10013 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10014 "Job held by \"%s\".", username
);
10016 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10019 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10022 * Delete the attribute...
10025 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10026 IPP_TAG_ZERO
)) != NULL
)
10028 if (job
->attrs
->prev
)
10029 job
->attrs
->prev
->next
= attr2
->next
;
10031 job
->attrs
->attrs
= attr2
->next
;
10033 if (attr2
== job
->attrs
->last
)
10034 job
->attrs
->last
= job
->attrs
->prev
;
10036 ippDeleteAttribute(NULL
, attr2
);
10038 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10044 * Add new option by copying it...
10047 ippCopyAttribute(job
->attrs
, attr
, 0);
10049 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10058 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10061 * Send events as needed...
10064 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10065 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10066 cupsdFindDest(job
->dest
), job
,
10067 "Job priority changed by user.");
10069 if (event
& CUPSD_EVENT_JOB_STATE
)
10070 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10071 job
->state_value
== IPP_JOB_HELD
?
10072 "Job held by user." : "Job restarted by user.");
10074 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10075 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10076 "Job options changed by user.");
10079 * Start jobs if possible...
10088 * 'set_printer_attrs()' - Set printer attributes.
10092 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10093 ipp_attribute_t
*uri
) /* I - Printer */
10095 http_status_t status
; /* Policy status */
10096 cups_ptype_t dtype
; /* Destination type (printer/class) */
10097 cupsd_printer_t
*printer
; /* Printer/class */
10098 ipp_attribute_t
*attr
; /* Printer attribute */
10099 int changed
= 0; /* Was anything changed? */
10102 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10103 con
->http
.fd
, uri
->values
[0].string
.text
);
10106 * Is the destination valid?
10109 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10115 send_ipp_status(con
, IPP_NOT_FOUND
,
10116 _("The printer or class does not exist."));
10124 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10126 send_http_error(con
, status
, printer
);
10131 * Return a list of attributes that can be set via Set-Printer-Attributes.
10134 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10135 IPP_TAG_TEXT
)) != NULL
)
10137 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10141 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10142 IPP_TAG_TEXT
)) != NULL
)
10144 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10149 * Update the printer attributes and return...
10154 cupsdSetPrinterAttrs(printer
);
10155 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10157 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10158 "Printer \"%s\" description or location changed by \"%s\".",
10159 printer
->name
, get_username(con
));
10161 cupsdLogMessage(CUPSD_LOG_INFO
,
10162 "Printer \"%s\" description or location changed by \"%s\".",
10163 printer
->name
, get_username(con
));
10166 con
->response
->request
.status
.status_code
= IPP_OK
;
10171 * 'set_printer_defaults()' - Set printer default options from a request.
10175 set_printer_defaults(
10176 cupsd_client_t
*con
, /* I - Client connection */
10177 cupsd_printer_t
*printer
) /* I - Printer */
10179 int i
; /* Looping var */
10180 ipp_attribute_t
*attr
; /* Current attribute */
10181 int namelen
; /* Length of attribute name */
10182 char name
[256], /* New attribute name */
10183 value
[256]; /* String version of integer attrs */
10186 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10189 * Skip non-printer attributes...
10192 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10195 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10197 if (!strcmp(attr
->name
, "job-sheets-default"))
10200 * Only allow keywords and names...
10203 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10207 * Only allow job-sheets-default to be set when running without a
10208 * system high classification level...
10211 if (Classification
)
10214 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10216 if (attr
->num_values
> 1)
10217 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10219 cupsdSetString(&printer
->job_sheets
[1], "none");
10221 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10223 cupsdFreeStrings(&(printer
->users
));
10225 printer
->deny_users
= 0;
10227 if (attr
->value_tag
== IPP_TAG_NAME
&&
10228 (attr
->num_values
> 1 ||
10229 strcmp(attr
->values
[0].string
.text
, "all")))
10231 for (i
= 0; i
< attr
->num_values
; i
++)
10232 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10235 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10237 cupsdFreeStrings(&(printer
->users
));
10239 printer
->deny_users
= 1;
10241 if (attr
->value_tag
== IPP_TAG_NAME
&&
10242 (attr
->num_values
> 1 ||
10243 strcmp(attr
->values
[0].string
.text
, "none")))
10245 for (i
= 0; i
< attr
->num_values
; i
++)
10246 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10249 else if (!strcmp(attr
->name
, "job-quota-period"))
10251 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10254 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10255 attr
->values
[0].integer
);
10256 cupsdFreeQuotas(printer
);
10258 printer
->quota_period
= attr
->values
[0].integer
;
10260 else if (!strcmp(attr
->name
, "job-k-limit"))
10262 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10265 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10266 attr
->values
[0].integer
);
10267 cupsdFreeQuotas(printer
);
10269 printer
->k_limit
= attr
->values
[0].integer
;
10271 else if (!strcmp(attr
->name
, "job-page-limit"))
10273 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10276 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10277 attr
->values
[0].integer
);
10278 cupsdFreeQuotas(printer
);
10280 printer
->page_limit
= attr
->values
[0].integer
;
10282 else if (!strcmp(attr
->name
, "printer-op-policy"))
10284 cupsd_policy_t
*p
; /* Policy */
10287 if (attr
->value_tag
!= IPP_TAG_NAME
)
10290 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10292 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10293 "Setting printer-op-policy to \"%s\"...",
10294 attr
->values
[0].string
.text
);
10295 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10296 printer
->op_policy_ptr
= p
;
10300 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10301 _("Unknown printer-op-policy \"%s\"."),
10302 attr
->values
[0].string
.text
);
10306 else if (!strcmp(attr
->name
, "printer-error-policy"))
10308 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10311 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10312 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10313 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10314 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10315 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10317 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10318 _("Unknown printer-error-policy \"%s\"."),
10319 attr
->values
[0].string
.text
);
10323 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10324 "Setting printer-error-policy to \"%s\"...",
10325 attr
->values
[0].string
.text
);
10326 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10330 * Skip any other non-default attributes...
10333 namelen
= strlen(attr
->name
);
10334 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10335 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10339 * OK, anything else must be a user-defined default...
10342 strlcpy(name
, attr
->name
, sizeof(name
));
10343 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10345 switch (attr
->value_tag
)
10347 case IPP_TAG_DELETEATTR
:
10348 printer
->num_options
= cupsRemoveOption(name
,
10349 printer
->num_options
,
10350 &(printer
->options
));
10351 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10352 "Deleting %s", attr
->name
);
10355 case IPP_TAG_NAME
:
10356 case IPP_TAG_TEXT
:
10357 case IPP_TAG_KEYWORD
:
10359 printer
->num_options
= cupsAddOption(name
,
10360 attr
->values
[0].string
.text
,
10361 printer
->num_options
,
10362 &(printer
->options
));
10363 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10364 "Setting %s to \"%s\"...", attr
->name
,
10365 attr
->values
[0].string
.text
);
10368 case IPP_TAG_BOOLEAN
:
10369 printer
->num_options
= cupsAddOption(name
,
10370 attr
->values
[0].boolean
?
10372 printer
->num_options
,
10373 &(printer
->options
));
10374 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10375 "Setting %s to %s...", attr
->name
,
10376 attr
->values
[0].boolean
? "true" : "false");
10379 case IPP_TAG_INTEGER
:
10380 case IPP_TAG_ENUM
:
10381 sprintf(value
, "%d", attr
->values
[0].integer
);
10382 printer
->num_options
= cupsAddOption(name
, value
,
10383 printer
->num_options
,
10384 &(printer
->options
));
10385 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10386 "Setting %s to %s...", attr
->name
, value
);
10389 case IPP_TAG_RANGE
:
10390 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10391 attr
->values
[0].range
.upper
);
10392 printer
->num_options
= cupsAddOption(name
, value
,
10393 printer
->num_options
,
10394 &(printer
->options
));
10395 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10396 "Setting %s to %s...", attr
->name
, value
);
10399 case IPP_TAG_RESOLUTION
:
10400 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10401 attr
->values
[0].resolution
.yres
,
10402 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10404 printer
->num_options
= cupsAddOption(name
, value
,
10405 printer
->num_options
,
10406 &(printer
->options
));
10407 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10408 "Setting %s to %s...", attr
->name
, value
);
10412 /* Do nothing for other values */
10420 * 'start_printer()' - Start a printer.
10424 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10425 ipp_attribute_t
*uri
) /* I - Printer URI */
10427 int i
; /* Temporary variable */
10428 http_status_t status
; /* Policy status */
10429 cups_ptype_t dtype
; /* Destination type (printer/class) */
10430 cupsd_printer_t
*printer
; /* Printer data */
10433 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10434 con
->http
.fd
, uri
->values
[0].string
.text
);
10437 * Is the destination valid?
10440 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10446 send_ipp_status(con
, IPP_NOT_FOUND
,
10447 _("The printer or class does not exist."));
10455 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10457 send_http_error(con
, status
, printer
);
10462 * Start the printer...
10465 printer
->state_message
[0] = '\0';
10467 cupsdStartPrinter(printer
, 1);
10469 if (dtype
& CUPS_PRINTER_CLASS
)
10470 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10471 printer
->name
, get_username(con
));
10473 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10474 printer
->name
, get_username(con
));
10482 if ((i
= check_quotas(con
, printer
)) < 0)
10484 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10489 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10494 * Everything was ok, so return OK status...
10497 con
->response
->request
.status
.status_code
= IPP_OK
;
10502 * 'stop_printer()' - Stop a printer.
10506 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10507 ipp_attribute_t
*uri
) /* I - Printer URI */
10509 http_status_t status
; /* Policy status */
10510 cups_ptype_t dtype
; /* Destination type (printer/class) */
10511 cupsd_printer_t
*printer
; /* Printer data */
10512 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10515 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10516 con
->http
.fd
, uri
->values
[0].string
.text
);
10519 * Is the destination valid?
10522 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10528 send_ipp_status(con
, IPP_NOT_FOUND
,
10529 _("The printer or class does not exist."));
10537 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10539 send_http_error(con
, status
, printer
);
10544 * Stop the printer...
10547 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10548 IPP_TAG_TEXT
)) == NULL
)
10549 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10552 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10553 sizeof(printer
->state_message
));
10556 cupsdStopPrinter(printer
, 1);
10558 if (dtype
& CUPS_PRINTER_CLASS
)
10559 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10560 printer
->name
, get_username(con
));
10562 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10563 printer
->name
, get_username(con
));
10566 * Everything was ok, so return OK status...
10569 con
->response
->request
.status
.status_code
= IPP_OK
;
10574 * 'url_encode_attr()' - URL-encode a string attribute.
10578 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10579 char *buffer
,/* I - String buffer */
10580 int bufsize
)/* I - Size of buffer */
10582 int i
; /* Looping var */
10583 char *bufptr
, /* Pointer into buffer */
10584 *bufend
; /* End of buffer */
10587 strlcpy(buffer
, attr
->name
, bufsize
);
10588 bufptr
= buffer
+ strlen(buffer
);
10589 bufend
= buffer
+ bufsize
- 1;
10591 for (i
= 0; i
< attr
->num_values
; i
++)
10593 if (bufptr
>= bufend
)
10601 if (bufptr
>= bufend
)
10606 bufptr
= url_encode_string(attr
->values
[i
].string
.text
,
10607 bufptr
, bufend
- bufptr
+ 1);
10609 if (bufptr
>= bufend
)
10620 * 'url_encode_string()' - URL-encode a string.
10623 static char * /* O - End of string */
10624 url_encode_string(const char *s
, /* I - String */
10625 char *buffer
, /* I - String buffer */
10626 int bufsize
) /* I - Size of buffer */
10628 char *bufptr
, /* Pointer into buffer */
10629 *bufend
; /* End of buffer */
10630 static const char *hex
= "0123456789ABCDEF";
10635 bufend
= buffer
+ bufsize
- 1;
10637 while (*s
&& bufptr
< bufend
)
10639 if (*s
== ' ' || *s
== '%' || *s
== '+')
10641 if (bufptr
>= (bufend
- 2))
10645 *bufptr
++ = hex
[(*s
>> 4) & 15];
10646 *bufptr
++ = hex
[*s
& 15];
10650 else if (*s
== '\'' || *s
== '\\')
10652 if (bufptr
>= (bufend
- 1))
10669 * 'user_allowed()' - See if a user is allowed to print to a queue.
10672 static int /* O - 0 if not allowed, 1 if allowed */
10673 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10674 const char *username
) /* I - Username */
10676 struct passwd
*pw
; /* User password data */
10677 char baseuser
[256], /* Base username */
10678 *baseptr
, /* Pointer to "@" in base username */
10679 *name
; /* Current user name */
10682 if (cupsArrayCount(p
->users
) == 0)
10685 if (!strcmp(username
, "root"))
10688 if (strchr(username
, '@'))
10691 * Strip @REALM for username check...
10694 strlcpy(baseuser
, username
, sizeof(baseuser
));
10696 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10699 username
= baseuser
;
10702 pw
= getpwnam(username
);
10705 for (name
= (char *)cupsArrayFirst(p
->users
);
10707 name
= (char *)cupsArrayNext(p
->users
))
10709 if (name
[0] == '@')
10712 * Check group membership...
10715 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10718 else if (name
[0] == '#')
10724 if (cupsdCheckGroup(username
, pw
, name
))
10727 else if (!_cups_strcasecmp(username
, name
))
10731 return ((name
!= NULL
) != p
->deny_users
);
10736 * 'validate_job()' - Validate printer options and destination.
10740 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10741 ipp_attribute_t
*uri
) /* I - Printer URI */
10743 http_status_t status
; /* Policy status */
10744 ipp_attribute_t
*attr
, /* Current attribute */
10745 *auth_info
; /* auth-info attribute */
10746 ipp_attribute_t
*format
, /* Document-format attribute */
10747 *name
; /* Job-name attribute */
10748 cups_ptype_t dtype
; /* Destination type (printer/class) */
10749 char super
[MIME_MAX_SUPER
],
10750 /* Supertype of file */
10751 type
[MIME_MAX_TYPE
];
10752 /* Subtype of file */
10753 cupsd_printer_t
*printer
; /* Printer */
10756 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10757 con
->http
.fd
, uri
->values
[0].string
.text
);
10760 * OK, see if the client is sending the document compressed - CUPS
10761 * doesn't support compression yet...
10764 if ((attr
= ippFindAttribute(con
->request
, "compression",
10765 IPP_TAG_KEYWORD
)) != NULL
)
10767 if (strcmp(attr
->values
[0].string
.text
, "none")
10769 && strcmp(attr
->values
[0].string
.text
, "gzip")
10770 #endif /* HAVE_LIBZ */
10773 send_ipp_status(con
, IPP_ATTRIBUTES
,
10774 _("Unsupported 'compression' value \"%s\"."),
10775 attr
->values
[0].string
.text
);
10776 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10777 "compression", NULL
, attr
->values
[0].string
.text
);
10783 * Is it a format we support?
10786 if ((format
= ippFindAttribute(con
->request
, "document-format",
10787 IPP_TAG_MIMETYPE
)) != NULL
)
10789 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
10792 send_ipp_status(con
, IPP_BAD_REQUEST
,
10793 _("Bad 'document-format' value \"%s\"."),
10794 format
->values
[0].string
.text
);
10798 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10799 !mimeType(MimeDatabase
, super
, type
))
10801 cupsdLogMessage(CUPSD_LOG_INFO
,
10802 "Hint: Do you have the raw file printing rules enabled?");
10803 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10804 _("Unsupported 'document-format' value \"%s\"."),
10805 format
->values
[0].string
.text
);
10806 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10807 "document-format", NULL
, format
->values
[0].string
.text
);
10813 * Is the job-name valid?
10816 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
10818 int bad_name
= 0; /* Is the job-name value bad? */
10820 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
10821 name
->num_values
!= 1)
10828 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
10829 * IPP Everywhere requirements for "name" values...
10832 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
10834 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
10838 if (*nameptr
< ' ' && *nameptr
!= '\t')
10840 else if (*nameptr
== 0x7f)
10842 else if ((*nameptr
& 0xe0) == 0xc0)
10844 if ((nameptr
[1] & 0xc0) != 0x80)
10849 else if ((*nameptr
& 0xf0) == 0xe0)
10851 if ((nameptr
[1] & 0xc0) != 0x80 ||
10852 (nameptr
[2] & 0xc0) != 0x80)
10857 else if ((*nameptr
& 0xf8) == 0xf0)
10859 if ((nameptr
[1] & 0xc0) != 0x80 ||
10860 (nameptr
[2] & 0xc0) != 0x80 ||
10861 (nameptr
[3] & 0xc0) != 0x80)
10866 else if (*nameptr
& 0x80)
10876 if (StrictConformance
)
10878 send_ipp_status(con
, IPP_ATTRIBUTES
,
10879 _("Unsupported 'job-name' value."));
10880 ippCopyAttribute(con
->response
, name
, 0);
10885 cupsdLogMessage(CUPSD_LOG_WARN
,
10886 "Unsupported 'job-name' value, deleting from request.");
10887 ippDeleteAttribute(con
->request
, name
);
10893 * Is the destination valid?
10896 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10902 send_ipp_status(con
, IPP_NOT_FOUND
,
10903 _("The printer or class does not exist."));
10911 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
10913 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10915 send_http_error(con
, status
, printer
);
10918 else if (printer
->num_auth_info_required
== 1 &&
10919 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10922 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
10926 else if (auth_info
&& !con
->http
.tls
&&
10927 !httpAddrLocalhost(con
->http
.hostaddr
))
10930 * Require encryption of auth-info over non-local connections...
10933 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
10936 #endif /* HAVE_SSL */
10939 * Everything was ok, so return OK status...
10942 con
->response
->request
.status
.status_code
= IPP_OK
;
10947 * 'validate_name()' - Make sure the printer name only contains valid chars.
10950 static int /* O - 0 if name is no good, 1 if good */
10951 validate_name(const char *name
) /* I - Name to check */
10953 const char *ptr
; /* Pointer into name */
10957 * Scan the whole name...
10960 for (ptr
= name
; *ptr
; ptr
++)
10961 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
10965 * All the characters are good; validate the length, too...
10968 return ((ptr
- name
) < 128);
10973 * 'validate_user()' - Validate the user for the request.
10976 static int /* O - 1 if permitted, 0 otherwise */
10977 validate_user(cupsd_job_t
*job
, /* I - Job */
10978 cupsd_client_t
*con
, /* I - Client connection */
10979 const char *owner
, /* I - Owner of job/resource */
10980 char *username
, /* O - Authenticated username */
10981 int userlen
) /* I - Length of username */
10983 cupsd_printer_t
*printer
; /* Printer for job */
10986 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
10987 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
10989 job
->id
, con
? con
->http
.fd
: 0,
10990 owner
? owner
: "(null)", username
, userlen
);
10993 * Validate input...
10996 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11000 * Get the best authenticated username that is available.
11003 strlcpy(username
, get_username(con
), userlen
);
11006 * Check the username against the owner...
11009 printer
= cupsdFindDest(job
->dest
);
11011 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11012 con
, owner
) == HTTP_OK
);
11017 * End of "$Id: ipp.c 11734 2014-03-25 18:01:47Z msweet $".