4 * IPP routines for the CUPS scheduler.
6 * Copyright 2007-2015 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
, mode_t mode
);
74 static int copy_model(cupsd_client_t
*con
, const char *from
,
76 static void copy_job_attrs(cupsd_client_t
*con
,
78 cups_array_t
*ra
, cups_array_t
*exclude
);
79 static void copy_printer_attrs(cupsd_client_t
*con
,
80 cupsd_printer_t
*printer
,
82 static void copy_subscription_attrs(cupsd_client_t
*con
,
83 cupsd_subscription_t
*sub
,
85 cups_array_t
*exclude
);
86 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
87 static cups_array_t
*create_requested_array(ipp_t
*request
);
88 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
90 static void get_default(cupsd_client_t
*con
);
91 static void get_devices(cupsd_client_t
*con
);
92 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
93 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
94 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
95 static void get_notifications(cupsd_client_t
*con
);
96 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
97 static void get_ppds(cupsd_client_t
*con
);
98 static void get_printers(cupsd_client_t
*con
, int type
);
99 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
100 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
101 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
102 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
103 static const char *get_username(cupsd_client_t
*con
);
104 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
105 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
107 static int ppd_parse_line(const char *line
, char *option
, int olen
,
108 char *choice
, int clen
);
109 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
110 static void read_job_ticket(cupsd_client_t
*con
);
111 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
112 static void release_held_new_jobs(cupsd_client_t
*con
,
113 ipp_attribute_t
*uri
);
114 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
115 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
116 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
117 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
118 ipp_attribute_t
*auth_info
);
119 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
120 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
121 cupsd_printer_t
*printer
);
122 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
123 const char *message
, ...)
124 __attribute__((__format__(__printf__
, 3, 4)));
125 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
126 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
127 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
128 static void set_printer_defaults(cupsd_client_t
*con
,
129 cupsd_printer_t
*printer
);
130 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
132 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
133 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
134 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
135 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
136 static int validate_name(const char *name
);
137 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
141 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
144 int /* O - 1 on success, 0 on failure */
145 cupsdProcessIPPRequest(
146 cupsd_client_t
*con
) /* I - Client connection */
148 ipp_tag_t group
; /* Current group tag */
149 ipp_attribute_t
*attr
; /* Current attribute */
150 ipp_attribute_t
*charset
; /* Character set attribute */
151 ipp_attribute_t
*language
; /* Language attribute */
152 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
153 ipp_attribute_t
*username
; /* requesting-user-name attr */
154 int sub_id
; /* Subscription ID */
157 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
158 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
159 con
, con
->number
, con
->request
->request
.op
.operation_id
);
162 * First build an empty response message for this request...
165 con
->response
= ippNew();
167 con
->response
->request
.status
.version
[0] =
168 con
->request
->request
.op
.version
[0];
169 con
->response
->request
.status
.version
[1] =
170 con
->request
->request
.op
.version
[1];
171 con
->response
->request
.status
.request_id
=
172 con
->request
->request
.op
.request_id
;
175 * Then validate the request header and required attributes...
178 if (con
->request
->request
.any
.version
[0] != 1 &&
179 con
->request
->request
.any
.version
[0] != 2)
182 * Return an error, since we only support IPP 1.x and 2.x.
185 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
186 "%04X %s Bad request version number %d.%d",
187 IPP_VERSION_NOT_SUPPORTED
, con
->http
->hostname
,
188 con
->request
->request
.any
.version
[0],
189 con
->request
->request
.any
.version
[1]);
191 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
192 _("Bad request version number %d.%d."),
193 con
->request
->request
.any
.version
[0],
194 con
->request
->request
.any
.version
[1]);
196 else if (con
->request
->request
.any
.request_id
< 1)
199 * Return an error, since request IDs must be between 1 and 2^31-1
202 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
203 "%04X %s Bad request ID %d",
204 IPP_BAD_REQUEST
, con
->http
->hostname
,
205 con
->request
->request
.any
.request_id
);
207 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad request ID %d."),
208 con
->request
->request
.any
.request_id
);
210 else if (!con
->request
->attrs
)
212 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
213 "%04X %s No attributes in request",
214 IPP_BAD_REQUEST
, con
->http
->hostname
);
216 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request."));
221 * Make sure that the attributes are provided in the correct order and
222 * don't repeat groups...
225 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
228 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
231 * Out of order; return an error...
234 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
235 "%04X %s Attribute groups are out of order",
236 IPP_BAD_REQUEST
, con
->http
->hostname
);
238 send_ipp_status(con
, IPP_BAD_REQUEST
,
239 _("Attribute groups are out of order (%x < %x)."),
240 attr
->group_tag
, group
);
244 group
= attr
->group_tag
;
249 * Then make sure that the first three attributes are:
252 * attributes-natural-language
253 * printer-uri/job-uri
256 attr
= con
->request
->attrs
;
257 if (attr
&& attr
->name
&&
258 !strcmp(attr
->name
, "attributes-charset") &&
259 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
267 if (attr
&& attr
->name
&&
268 !strcmp(attr
->name
, "attributes-natural-language") &&
269 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
274 * Reset language for this request if different from Accept-Language.
277 if (!con
->language
||
278 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
280 cupsLangFree(con
->language
);
281 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
287 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
288 IPP_TAG_URI
)) != NULL
)
290 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
291 IPP_TAG_URI
)) != NULL
)
293 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
)
294 uri
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
);
299 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
300 "attributes-charset", NULL
,
301 charset
->values
[0].string
.text
);
303 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
304 "attributes-charset", NULL
, "utf-8");
307 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
308 "attributes-natural-language", NULL
,
309 language
->values
[0].string
.text
);
311 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
312 "attributes-natural-language", NULL
, DefaultLanguage
);
315 _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") &&
316 _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
319 * Bad character set...
322 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
323 charset
->values
[0].string
.text
);
324 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
325 "%04X %s Unsupported attributes-charset value \"%s\"",
326 IPP_CHARSET
, con
->http
->hostname
,
327 charset
->values
[0].string
.text
);
328 send_ipp_status(con
, IPP_BAD_REQUEST
,
329 _("Unsupported character set \"%s\"."),
330 charset
->values
[0].string
.text
);
332 else if (!charset
|| !language
||
334 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
335 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
336 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
337 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
338 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
341 * Return an error, since attributes-charset,
342 * attributes-natural-language, and printer-uri/job-uri are required
343 * for all operations.
348 cupsdLogMessage(CUPSD_LOG_ERROR
,
349 "Missing attributes-charset attribute");
351 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
352 "%04X %s Missing attributes-charset attribute",
353 IPP_BAD_REQUEST
, con
->http
->hostname
);
358 cupsdLogMessage(CUPSD_LOG_ERROR
,
359 "Missing attributes-natural-language attribute");
361 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
362 "%04X %s Missing attributes-natural-language attribute",
363 IPP_BAD_REQUEST
, con
->http
->hostname
);
368 cupsdLogMessage(CUPSD_LOG_ERROR
,
369 "Missing printer-uri, job-uri, or ppd-name "
372 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
373 "%04X %s Missing printer-uri, job-uri, or ppd-name "
374 "attribute", IPP_BAD_REQUEST
, con
->http
->hostname
);
377 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
379 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
380 cupsdLogMessage(CUPSD_LOG_DEBUG
,
381 "attr \"%s\": group_tag = %x, value_tag = %x",
382 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
385 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
387 send_ipp_status(con
, IPP_BAD_REQUEST
,
388 _("Missing required attributes."));
393 * OK, all the checks pass so far; make sure requesting-user-name is
394 * not "root" from a remote host...
397 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
398 IPP_TAG_NAME
)) != NULL
)
401 * Check for root user...
404 if (!strcmp(username
->values
[0].string
.text
, "root") &&
405 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
406 strcmp(con
->username
, "root"))
409 * Remote unauthenticated user masquerading as local root...
412 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
416 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
417 IPP_TAG_INTEGER
)) != NULL
)
418 sub_id
= attr
->values
[0].integer
;
423 * Then try processing the operation...
427 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
428 ippOpString(con
->request
->request
.op
.operation_id
),
429 uri
->values
[0].string
.text
);
431 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
432 ippOpString(con
->request
->request
.op
.operation_id
));
434 switch (con
->request
->request
.op
.operation_id
)
436 case IPP_OP_PRINT_JOB
:
440 case IPP_OP_VALIDATE_JOB
:
441 validate_job(con
, uri
);
444 case IPP_OP_CREATE_JOB
:
445 create_job(con
, uri
);
448 case IPP_OP_SEND_DOCUMENT
:
449 send_document(con
, uri
);
452 case IPP_OP_CANCEL_JOB
:
453 cancel_job(con
, uri
);
456 case IPP_OP_GET_JOB_ATTRIBUTES
:
457 get_job_attrs(con
, uri
);
460 case IPP_OP_GET_JOBS
:
464 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
465 get_printer_attrs(con
, uri
);
468 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
469 get_printer_supported(con
, uri
);
472 case IPP_OP_HOLD_JOB
:
476 case IPP_OP_RELEASE_JOB
:
477 release_job(con
, uri
);
480 case IPP_OP_RESTART_JOB
:
481 restart_job(con
, uri
);
484 case IPP_OP_PAUSE_PRINTER
:
485 stop_printer(con
, uri
);
488 case IPP_OP_RESUME_PRINTER
:
489 start_printer(con
, uri
);
492 case IPP_OP_PURGE_JOBS
:
493 case IPP_OP_CANCEL_JOBS
:
494 case IPP_OP_CANCEL_MY_JOBS
:
495 cancel_all_jobs(con
, uri
);
498 case IPP_OP_SET_JOB_ATTRIBUTES
:
499 set_job_attrs(con
, uri
);
502 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
503 set_printer_attrs(con
, uri
);
506 case IPP_OP_HOLD_NEW_JOBS
:
507 hold_new_jobs(con
, uri
);
510 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
511 release_held_new_jobs(con
, uri
);
514 case IPP_OP_CLOSE_JOB
:
518 case IPP_OP_CUPS_GET_DEFAULT
:
522 case IPP_OP_CUPS_GET_PRINTERS
:
523 get_printers(con
, 0);
526 case IPP_OP_CUPS_GET_CLASSES
:
527 get_printers(con
, CUPS_PRINTER_CLASS
);
530 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
531 add_printer(con
, uri
);
534 case IPP_OP_CUPS_DELETE_PRINTER
:
535 delete_printer(con
, uri
);
538 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
542 case IPP_OP_CUPS_DELETE_CLASS
:
543 delete_printer(con
, uri
);
546 case IPP_OP_CUPS_ACCEPT_JOBS
:
547 case IPP_OP_ENABLE_PRINTER
:
548 accept_jobs(con
, uri
);
551 case IPP_OP_CUPS_REJECT_JOBS
:
552 case IPP_OP_DISABLE_PRINTER
:
553 reject_jobs(con
, uri
);
556 case IPP_OP_CUPS_SET_DEFAULT
:
557 set_default(con
, uri
);
560 case IPP_OP_CUPS_GET_DEVICES
:
564 case IPP_OP_CUPS_GET_DOCUMENT
:
565 get_document(con
, uri
);
568 case IPP_OP_CUPS_GET_PPD
:
572 case IPP_OP_CUPS_GET_PPDS
:
576 case IPP_OP_CUPS_MOVE_JOB
:
580 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
581 authenticate_job(con
, uri
);
584 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
585 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
586 create_subscriptions(con
, uri
);
589 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
590 get_subscription_attrs(con
, sub_id
);
593 case IPP_OP_GET_SUBSCRIPTIONS
:
594 get_subscriptions(con
, uri
);
597 case IPP_OP_RENEW_SUBSCRIPTION
:
598 renew_subscription(con
, sub_id
);
601 case IPP_OP_CANCEL_SUBSCRIPTION
:
602 cancel_subscription(con
, sub_id
);
605 case IPP_OP_GET_NOTIFICATIONS
:
606 get_notifications(con
);
610 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
611 "%04X %s Operation %04X (%s) not supported",
612 IPP_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
,
613 con
->request
->request
.op
.operation_id
,
614 ippOpString(con
->request
->request
.op
.operation_id
));
616 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
617 _("%s not supported."),
619 con
->request
->request
.op
.operation_id
));
629 * Sending data from the scheduler...
632 cupsdLogMessage(con
->response
->request
.status
.status_code
633 >= IPP_BAD_REQUEST
&&
634 con
->response
->request
.status
.status_code
635 != IPP_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
636 "[Client %d] Returning IPP %s for %s (%s) from %s",
638 ippErrorString(con
->response
->request
.status
.status_code
),
639 ippOpString(con
->request
->request
.op
.operation_id
),
640 uri
? uri
->values
[0].string
.text
: "no URI",
641 con
->http
->hostname
);
643 httpClearFields(con
->http
);
645 #ifdef CUPSD_USE_CHUNKING
647 * Because older versions of CUPS (1.1.17 and older) and some IPP
648 * clients do not implement chunking properly, we cannot use
649 * chunking by default. This may become the default in future
650 * CUPS releases, or we might add a configuration directive for
654 if (con
->http
->version
== HTTP_1_1
)
656 cupsdLogMessage(CUPSD_LOG_DEBUG
,
657 "[Client %d] Transfer-Encoding: chunked",
660 cupsdSetLength(con
->http
, 0);
663 #endif /* CUPSD_USE_CHUNKING */
665 size_t length
; /* Length of response */
668 length
= ippLength(con
->response
);
670 if (con
->file
>= 0 && !con
->pipe_pid
)
672 struct stat fileinfo
; /* File information */
674 if (!fstat(con
->file
, &fileinfo
))
675 length
+= (size_t)fileinfo
.st_size
;
678 cupsdLogMessage(CUPSD_LOG_DEBUG
,
679 "[Client %d] Content-Length: " CUPS_LLFMT
,
680 con
->number
, CUPS_LLCAST length
);
681 httpSetLength(con
->http
, length
);
684 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
687 * Tell the caller the response header was sent successfully...
690 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
,
691 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
698 * Tell the caller the response header could not be sent...
707 * Sending data from a subprocess like cups-deviced; tell the caller
708 * everything is A-OK so far...
717 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
720 int /* O - 0 on success, -1 on error */
721 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
723 cupsd_printer_t
*printer
; /* Destination printer or class */
724 ipp_attribute_t
*attr
; /* job-sheets attribute */
725 int kbytes
; /* Kilobytes in banner */
728 job
->pending_timeout
= 0;
731 * See if we need to add the ending sheet...
734 if (!cupsdLoadJob(job
))
737 printer
= cupsdFindDest(job
->dest
);
738 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
740 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
741 attr
&& attr
->num_values
> 1)
747 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
748 attr
->values
[1].string
.text
);
750 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
753 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
761 * 'accept_jobs()' - Accept print jobs to a printer.
765 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
766 ipp_attribute_t
*uri
) /* I - Printer or class URI */
768 http_status_t status
; /* Policy status */
769 cups_ptype_t dtype
; /* Destination type (printer/class) */
770 cupsd_printer_t
*printer
; /* Printer data */
773 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
774 con
->number
, uri
->values
[0].string
.text
);
777 * Is the destination valid?
780 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
786 send_ipp_status(con
, IPP_NOT_FOUND
,
787 _("The printer or class does not exist."));
795 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
797 send_http_error(con
, status
, printer
);
802 * Accept jobs sent to the printer...
805 printer
->accepting
= 1;
806 printer
->state_message
[0] = '\0';
808 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
809 "Now accepting jobs.");
811 if (dtype
& CUPS_PRINTER_CLASS
)
813 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
815 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
816 printer
->name
, get_username(con
));
820 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
822 cupsdLogMessage(CUPSD_LOG_INFO
,
823 "Printer \"%s\" now accepting jobs (\"%s\").",
824 printer
->name
, get_username(con
));
828 * Everything was ok, so return OK status...
831 con
->response
->request
.status
.status_code
= IPP_OK
;
836 * 'add_class()' - Add a class to the system.
840 add_class(cupsd_client_t
*con
, /* I - Client connection */
841 ipp_attribute_t
*uri
) /* I - URI of class */
843 http_status_t status
; /* Policy status */
844 int i
; /* Looping var */
845 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
846 username
[HTTP_MAX_URI
], /* Username portion of URI */
847 host
[HTTP_MAX_URI
], /* Host portion of URI */
848 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
849 int port
; /* Port portion of URI */
850 cupsd_printer_t
*pclass
, /* Class */
851 *member
; /* Member printer/class */
852 cups_ptype_t dtype
; /* Destination type */
853 ipp_attribute_t
*attr
; /* Printer attribute */
854 int modify
; /* Non-zero if we just modified */
855 int need_restart_job
; /* Need to restart job? */
858 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
859 con
->number
, uri
->values
[0].string
.text
);
862 * Do we have a valid URI?
865 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
866 sizeof(scheme
), username
, sizeof(username
), host
,
867 sizeof(host
), &port
, resource
, sizeof(resource
));
870 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
873 * No, return an error...
876 send_ipp_status(con
, IPP_BAD_REQUEST
,
877 _("The printer-uri must be of the form "
878 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
883 * Do we have a valid printer name?
886 if (!validate_name(resource
+ 9))
889 * No, return an error...
892 send_ipp_status(con
, IPP_BAD_REQUEST
,
893 _("The printer-uri \"%s\" contains invalid characters."),
894 uri
->values
[0].string
.text
);
899 * See if the class already exists; if not, create a new class...
902 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
905 * Class doesn't exist; see if we have a printer of the same name...
908 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
911 * Yes, return an error...
914 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
915 _("A printer named \"%s\" already exists."),
921 * No, check the default policy and then add the class...
924 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
926 send_http_error(con
, status
, NULL
);
930 pclass
= cupsdAddClass(resource
+ 9);
933 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
936 send_http_error(con
, status
, pclass
);
943 * Look for attributes and copy them over as needed...
946 need_restart_job
= 0;
948 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
949 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
951 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
952 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
954 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
955 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
957 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
958 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
960 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
961 IPP_TAG_TEXT
)) != NULL
)
962 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
964 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
965 IPP_TAG_BOOLEAN
)) != NULL
&&
966 attr
->values
[0].boolean
!= pclass
->accepting
)
968 cupsdLogMessage(CUPSD_LOG_INFO
,
969 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
970 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
972 pclass
->accepting
= attr
->values
[0].boolean
;
974 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
975 pclass
->accepting
? "Now" : "No longer");
978 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
979 IPP_TAG_BOOLEAN
)) != NULL
)
981 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
984 * Cannot re-share remote printers.
987 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
991 if (pclass
->shared
&& !attr
->values
[0].boolean
)
992 cupsdDeregisterPrinter(pclass
, 1);
994 cupsdLogMessage(CUPSD_LOG_INFO
,
995 "Setting %s printer-is-shared to %d (was %d.)",
996 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
998 pclass
->shared
= attr
->values
[0].boolean
;
1001 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1002 IPP_TAG_ENUM
)) != NULL
)
1004 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1005 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1007 send_ipp_status(con
, IPP_BAD_REQUEST
,
1008 _("Attempt to set %s printer-state to bad value %d."),
1009 pclass
->name
, attr
->values
[0].integer
);
1013 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1014 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1016 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1017 cupsdStopPrinter(pclass
, 0);
1020 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1021 need_restart_job
= 1;
1024 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1025 IPP_TAG_TEXT
)) != NULL
)
1027 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1028 sizeof(pclass
->state_message
));
1030 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1031 pclass
->state_message
);
1033 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1034 IPP_TAG_URI
)) != NULL
)
1037 * Clear the printer array as needed...
1040 need_restart_job
= 1;
1042 if (pclass
->num_printers
> 0)
1044 free(pclass
->printers
);
1045 pclass
->num_printers
= 0;
1049 * Add each printer or class that is listed...
1052 for (i
= 0; i
< attr
->num_values
; i
++)
1055 * Search for the printer or class URI...
1058 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1064 send_ipp_status(con
, IPP_NOT_FOUND
,
1065 _("The printer or class does not exist."));
1068 else if (dtype
& CUPS_PRINTER_CLASS
)
1070 send_ipp_status(con
, IPP_BAD_REQUEST
,
1071 _("Nested classes are not allowed."));
1076 * Add it to the class...
1079 cupsdAddPrinterToClass(pclass
, member
);
1083 set_printer_defaults(con
, pclass
);
1085 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1086 IPP_TAG_KEYWORD
)) != NULL
)
1087 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1089 pclass
->config_time
= time(NULL
);
1092 * Update the printer class attributes and return...
1095 cupsdSetPrinterAttrs(pclass
);
1096 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1098 if (need_restart_job
&& pclass
->job
)
1101 * Reset the current job to a "pending" status...
1104 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1105 "Job restarted because the class was modified.");
1108 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1112 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1113 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1114 pclass
->name
, get_username(con
));
1116 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1117 pclass
->name
, get_username(con
));
1121 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1122 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1123 pclass
->name
, get_username(con
));
1125 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1126 pclass
->name
, get_username(con
));
1129 con
->response
->request
.status
.status_code
= IPP_OK
;
1134 * 'add_file()' - Add a file to a job.
1137 static int /* O - 0 on success, -1 on error */
1138 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1139 cupsd_job_t
*job
, /* I - Job to add to */
1140 mime_type_t
*filetype
, /* I - Type of file */
1141 int compression
) /* I - Compression */
1143 mime_type_t
**filetypes
; /* New filetypes array... */
1144 int *compressions
; /* New compressions array... */
1147 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1148 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1149 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1150 filetype
->super
, filetype
->type
, compression
);
1153 * Add the file to the job...
1156 if (job
->num_files
== 0)
1158 compressions
= (int *)malloc(sizeof(int));
1159 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1163 compressions
= (int *)realloc(job
->compressions
,
1164 (size_t)(job
->num_files
+ 1) * sizeof(int));
1165 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1166 (size_t)(job
->num_files
+ 1) *
1167 sizeof(mime_type_t
*));
1171 job
->compressions
= compressions
;
1174 job
->filetypes
= filetypes
;
1176 if (!compressions
|| !filetypes
)
1178 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1179 "Job aborted because the scheduler ran out of memory.");
1182 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1183 _("Unable to allocate memory for file types."));
1188 job
->compressions
[job
->num_files
] = compression
;
1189 job
->filetypes
[job
->num_files
] = filetype
;
1194 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1201 * 'add_job()' - Add a job to a print queue.
1204 static cupsd_job_t
* /* O - Job object */
1205 add_job(cupsd_client_t
*con
, /* I - Client connection */
1206 cupsd_printer_t
*printer
, /* I - Destination printer */
1207 mime_type_t
*filetype
) /* I - First print file type, if any */
1209 http_status_t status
; /* Policy status */
1210 ipp_attribute_t
*attr
, /* Current attribute */
1211 *auth_info
; /* auth-info attribute */
1212 const char *mandatory
; /* Current mandatory job attribute */
1213 const char *val
; /* Default option value */
1214 int priority
; /* Job priority */
1215 cupsd_job_t
*job
; /* Current job */
1216 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1217 int kbytes
; /* Size of print file */
1218 int i
; /* Looping var */
1219 int lowerpagerange
; /* Page range bound */
1220 int exact
; /* Did we have an exact match? */
1221 ipp_attribute_t
*media_col
, /* media-col attribute */
1222 *media_margin
; /* media-*-margin attribute */
1223 ipp_t
*unsup_col
; /* media-col in unsupported response */
1224 static const char * const readonly
[] =/* List of read-only attributes */
1226 "date-time-at-completed",
1227 "date-time-at-creation",
1228 "date-time-at-processing",
1229 "job-detailed-status-messages",
1230 "job-document-access-errors",
1232 "job-impressions-completed",
1233 "job-k-octets-completed",
1234 "job-media-sheets-completed",
1235 "job-pages-completed",
1236 "job-printer-up-time",
1239 "job-state-message",
1240 "job-state-reasons",
1242 "number-of-documents",
1243 "number-of-intervening-jobs",
1244 "output-device-assigned",
1245 "time-at-completed",
1247 "time-at-processing"
1251 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1252 con
, con
->number
, printer
, printer
->name
,
1253 filetype
, filetype
? filetype
->super
: "none",
1254 filetype
? filetype
->type
: "none");
1257 * Check remote printing to non-shared printer...
1260 if (!printer
->shared
&&
1261 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1262 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1264 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1265 _("The printer or class is not shared."));
1273 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1275 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1277 send_http_error(con
, status
, printer
);
1280 else if (printer
->num_auth_info_required
== 1 &&
1281 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1284 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1288 else if (auth_info
&& !con
->http
->tls
&&
1289 !httpAddrLocalhost(con
->http
->hostaddr
))
1292 * Require encryption of auth-info over non-local connections...
1295 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1298 #endif /* HAVE_SSL */
1301 * See if the printer is accepting jobs...
1304 if (!printer
->accepting
)
1306 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1307 _("Destination \"%s\" is not accepting jobs."),
1313 * Validate job template attributes; for now just document-format,
1314 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1318 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1320 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1322 ippDeleteAttribute(con
->request
, attr
);
1324 if (StrictConformance
)
1326 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1330 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1336 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1338 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1340 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1343 * Missing a required attribute...
1346 send_ipp_status(con
, IPP_CONFLICT
,
1347 _("The \"%s\" attribute is required for print jobs."),
1354 if (filetype
&& printer
->filetypes
&&
1355 !cupsArrayFind(printer
->filetypes
, filetype
))
1357 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1358 /* MIME media type string */
1361 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1364 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1365 _("Unsupported format \"%s\"."), mimetype
);
1367 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1368 "document-format", NULL
, mimetype
);
1373 if ((attr
= ippFindAttribute(con
->request
, "copies",
1374 IPP_TAG_INTEGER
)) != NULL
)
1376 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1378 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1379 attr
->values
[0].integer
);
1380 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1381 "copies", attr
->values
[0].integer
);
1386 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1387 IPP_TAG_ZERO
)) != NULL
)
1389 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1390 attr
->value_tag
!= IPP_TAG_NAME
)
1392 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1396 if (attr
->num_values
> 2)
1398 send_ipp_status(con
, IPP_BAD_REQUEST
,
1399 _("Too many job-sheets values (%d > 2)."),
1404 for (i
= 0; i
< attr
->num_values
; i
++)
1405 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1406 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1408 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1409 attr
->values
[i
].string
.text
);
1414 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1415 IPP_TAG_INTEGER
)) != NULL
)
1417 if (attr
->values
[0].integer
!= 1 &&
1418 attr
->values
[0].integer
!= 2 &&
1419 attr
->values
[0].integer
!= 4 &&
1420 attr
->values
[0].integer
!= 6 &&
1421 attr
->values
[0].integer
!= 9 &&
1422 attr
->values
[0].integer
!= 16)
1424 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1425 attr
->values
[0].integer
);
1426 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1427 "number-up", attr
->values
[0].integer
);
1432 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1433 IPP_TAG_RANGE
)) != NULL
)
1435 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1437 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1438 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1440 send_ipp_status(con
, IPP_BAD_REQUEST
,
1441 _("Bad page-ranges values %d-%d."),
1442 attr
->values
[i
].range
.lower
,
1443 attr
->values
[i
].range
.upper
);
1447 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1452 * Do media selection as needed...
1455 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1456 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1457 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1460 (media_col
= ippFindAttribute(con
->request
, "media-col",
1461 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1463 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1465 unsup_col
= ippNew();
1466 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1467 "media-bottom-margin",
1468 IPP_TAG_INTEGER
)) != NULL
)
1469 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1470 "media-bottom-margin", media_margin
->values
[0].integer
);
1472 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1473 "media-left-margin",
1474 IPP_TAG_INTEGER
)) != NULL
)
1475 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1476 "media-left-margin", media_margin
->values
[0].integer
);
1478 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1479 "media-right-margin",
1480 IPP_TAG_INTEGER
)) != NULL
)
1481 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1482 "media-right-margin", media_margin
->values
[0].integer
);
1484 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1486 IPP_TAG_INTEGER
)) != NULL
)
1487 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1488 "media-top-margin", media_margin
->values
[0].integer
);
1490 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1492 ippDelete(unsup_col
);
1497 * Make sure we aren't over our limit...
1500 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1503 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1505 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1509 if ((i
= check_quotas(con
, printer
)) < 0)
1511 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1516 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1521 * Create the job and set things up...
1524 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1525 IPP_TAG_INTEGER
)) != NULL
)
1526 priority
= attr
->values
[0].integer
;
1529 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1530 printer
->options
)) != NULL
)
1531 priority
= atoi(val
);
1535 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1539 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1540 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1541 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1542 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1543 attr
->num_values
!= 1)
1545 send_ipp_status(con
, IPP_ATTRIBUTES
,
1546 _("Bad job-name value: Wrong type or count."));
1547 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1548 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1551 else if (!ippValidateAttribute(attr
))
1553 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1554 cupsLastErrorString());
1555 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1556 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1560 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1562 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1563 _("Unable to add job for destination \"%s\"."),
1568 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1569 job
->attrs
= con
->request
;
1571 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1573 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1576 apply_printer_defaults(printer
, job
);
1578 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1580 if (con
->username
[0])
1582 cupsdSetString(&job
->username
, con
->username
);
1585 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1589 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1590 "add_job: requesting-user-name=\"%s\"",
1591 attr
->values
[0].string
.text
);
1593 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1596 cupsdSetString(&job
->username
, "anonymous");
1599 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1600 "job-originating-user-name", NULL
, job
->username
);
1603 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1604 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1607 if (con
->username
[0] || auth_info
)
1609 save_auth_info(con
, job
, auth_info
);
1612 * Remove the auth-info attribute from the attribute data...
1616 ippDeleteAttribute(job
->attrs
, auth_info
);
1619 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1620 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1622 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1623 IPP_TAG_ZERO
)) != NULL
)
1626 * Request contains a job-originating-host-name attribute; validate it...
1629 if (attr
->value_tag
!= IPP_TAG_NAME
||
1630 attr
->num_values
!= 1 ||
1631 strcmp(con
->http
->hostname
, "localhost"))
1634 * Can't override the value if we aren't connected via localhost.
1635 * Also, we can only have 1 value and it must be a name value.
1638 ippDeleteAttribute(job
->attrs
, attr
);
1639 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1642 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1647 * No job-originating-host-name attribute, so use the hostname from
1651 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1652 "job-originating-host-name", NULL
, con
->http
->hostname
);
1655 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1656 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1657 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1658 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1659 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1660 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1663 * Add remaining job attributes...
1666 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1667 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1668 "job-state", IPP_JOB_STOPPED
);
1669 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1670 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1671 "job-state-reasons", NULL
, "job-incoming");
1672 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1673 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1674 "job-media-sheets-completed", 0);
1675 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1678 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1679 attr
->values
[0].integer
= 0;
1681 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1683 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1684 IPP_TAG_KEYWORD
)) == NULL
)
1685 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1688 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1689 printer
->options
)) == NULL
)
1692 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1693 "job-hold-until", NULL
, val
);
1695 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1698 * Hold job until specified time...
1701 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1703 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1704 job
->state_value
= IPP_JOB_HELD
;
1706 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1708 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1710 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1711 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1712 job
->state_value
= IPP_JOB_HELD
;
1716 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1717 job
->state_value
= IPP_JOB_PENDING
;
1719 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1722 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1725 * Add job sheets options...
1728 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1729 IPP_TAG_ZERO
)) == NULL
)
1731 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1732 "Adding default job-sheets values \"%s,%s\"...",
1733 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1735 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1737 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1738 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1741 job
->job_sheets
= attr
;
1744 * Enforce classification level if set...
1749 cupsdLogMessage(CUPSD_LOG_INFO
,
1750 "Classification=\"%s\", ClassifyOverride=%d",
1751 Classification
? Classification
: "(null)",
1754 if (ClassifyOverride
)
1756 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1757 (attr
->num_values
== 1 ||
1758 !strcmp(attr
->values
[1].string
.text
, "none")))
1761 * Force the leading banner to have the classification on it...
1764 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1766 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1767 "job-sheets=\"%s,none\", "
1768 "job-originating-user-name=\"%s\"",
1769 Classification
, job
->username
);
1771 else if (attr
->num_values
== 2 &&
1772 strcmp(attr
->values
[0].string
.text
,
1773 attr
->values
[1].string
.text
) &&
1774 strcmp(attr
->values
[0].string
.text
, "none") &&
1775 strcmp(attr
->values
[1].string
.text
, "none"))
1778 * Can't put two different security markings on the same document!
1781 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1783 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1784 "job-sheets=\"%s,%s\", "
1785 "job-originating-user-name=\"%s\"",
1786 attr
->values
[0].string
.text
,
1787 attr
->values
[1].string
.text
, job
->username
);
1789 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1790 strcmp(attr
->values
[0].string
.text
, "none") &&
1791 (attr
->num_values
== 1 ||
1792 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1793 strcmp(attr
->values
[1].string
.text
, "none"))))
1795 if (attr
->num_values
== 1)
1796 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1797 "CLASSIFICATION OVERRIDDEN "
1798 "job-sheets=\"%s\", "
1799 "job-originating-user-name=\"%s\"",
1800 attr
->values
[0].string
.text
, job
->username
);
1802 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1803 "CLASSIFICATION OVERRIDDEN "
1804 "job-sheets=\"%s,%s\",fffff "
1805 "job-originating-user-name=\"%s\"",
1806 attr
->values
[0].string
.text
,
1807 attr
->values
[1].string
.text
, job
->username
);
1810 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1811 (attr
->num_values
== 1 ||
1812 strcmp(attr
->values
[1].string
.text
, Classification
)))
1815 * Force the banner to have the classification on it...
1818 if (attr
->num_values
> 1 &&
1819 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1821 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1822 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1826 if (attr
->num_values
== 1 ||
1827 strcmp(attr
->values
[0].string
.text
, "none"))
1828 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1830 if (attr
->num_values
> 1 &&
1831 strcmp(attr
->values
[1].string
.text
, "none"))
1832 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1835 if (attr
->num_values
> 1)
1836 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1837 "CLASSIFICATION FORCED "
1838 "job-sheets=\"%s,%s\", "
1839 "job-originating-user-name=\"%s\"",
1840 attr
->values
[0].string
.text
,
1841 attr
->values
[1].string
.text
, job
->username
);
1843 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1844 "CLASSIFICATION FORCED "
1845 "job-sheets=\"%s\", "
1846 "job-originating-user-name=\"%s\"",
1847 Classification
, job
->username
);
1852 * See if we need to add the starting sheet...
1855 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1857 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1858 attr
->values
[0].string
.text
);
1860 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1862 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1863 "Aborting job because the start banner could not be "
1868 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1871 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1872 IPP_TAG_ZERO
)) != NULL
)
1873 job
->job_sheets
= attr
;
1876 * Fill in the response info...
1879 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1880 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1881 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1884 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1886 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1888 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1889 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1890 NULL
, job
->reasons
->values
[0].string
.text
);
1892 con
->response
->request
.status
.status_code
= IPP_OK
;
1895 * Add any job subscriptions...
1898 add_job_subscriptions(con
, job
);
1901 * Set all but the first two attributes to the job attributes group...
1904 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1905 attr
->group_tag
= IPP_TAG_JOB
;
1908 * Fire the "job created" event...
1911 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1914 * Return the new job...
1922 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1926 add_job_subscriptions(
1927 cupsd_client_t
*con
, /* I - Client connection */
1928 cupsd_job_t
*job
) /* I - Newly created job */
1930 int i
; /* Looping var */
1931 ipp_attribute_t
*prev
, /* Previous attribute */
1932 *next
, /* Next attribute */
1933 *attr
; /* Current attribute */
1934 cupsd_subscription_t
*sub
; /* Subscription object */
1935 const char *recipient
, /* notify-recipient-uri */
1936 *pullmethod
; /* notify-pull-method */
1937 ipp_attribute_t
*user_data
; /* notify-user-data */
1938 int interval
; /* notify-time-interval */
1939 unsigned mask
; /* notify-events */
1943 * Find the first subscription group attribute; return if we have
1947 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1948 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1955 * Process the subscription attributes in the request...
1964 mask
= CUPSD_EVENT_NONE
;
1966 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1968 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1969 attr
->value_tag
== IPP_TAG_URI
)
1972 * Validate the recipient scheme against the ServerBin/notifier
1976 char notifier
[1024], /* Notifier filename */
1977 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
1978 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
1979 host
[HTTP_MAX_URI
], /* Host portion of URI */
1980 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1981 int port
; /* Port portion of URI */
1984 recipient
= attr
->values
[0].string
.text
;
1986 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
1987 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
1988 host
, sizeof(host
), &port
,
1989 resource
, sizeof(resource
)) < HTTP_URI_OK
)
1991 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1992 _("Bad notify-recipient-uri \"%s\"."), recipient
);
1993 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
1994 "notify-status-code", IPP_URI_SCHEME
);
1998 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
2000 if (access(notifier
, X_OK
))
2002 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2003 _("notify-recipient-uri URI \"%s\" uses unknown "
2004 "scheme."), recipient
);
2005 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2006 "notify-status-code", IPP_URI_SCHEME
);
2010 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2012 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2013 _("notify-recipient-uri URI \"%s\" is already used."),
2015 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2016 "notify-status-code", IPP_ATTRIBUTES
);
2020 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2021 attr
->value_tag
== IPP_TAG_KEYWORD
)
2023 pullmethod
= attr
->values
[0].string
.text
;
2025 if (strcmp(pullmethod
, "ippget"))
2027 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2028 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2029 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2030 "notify-status-code", IPP_ATTRIBUTES
);
2034 else if (!strcmp(attr
->name
, "notify-charset") &&
2035 attr
->value_tag
== IPP_TAG_CHARSET
&&
2036 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2037 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2039 send_ipp_status(con
, IPP_CHARSET
,
2040 _("Character set \"%s\" not supported."),
2041 attr
->values
[0].string
.text
);
2044 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2045 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2046 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2048 send_ipp_status(con
, IPP_CHARSET
,
2049 _("Language \"%s\" not supported."),
2050 attr
->values
[0].string
.text
);
2053 else if (!strcmp(attr
->name
, "notify-user-data") &&
2054 attr
->value_tag
== IPP_TAG_STRING
)
2056 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2058 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2059 _("The notify-user-data value is too large "
2060 "(%d > 63 octets)."),
2061 attr
->values
[0].unknown
.length
);
2067 else if (!strcmp(attr
->name
, "notify-events") &&
2068 attr
->value_tag
== IPP_TAG_KEYWORD
)
2070 for (i
= 0; i
< attr
->num_values
; i
++)
2071 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2073 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2075 send_ipp_status(con
, IPP_BAD_REQUEST
,
2076 _("The notify-lease-duration attribute cannot be "
2077 "used with job subscriptions."));
2080 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2081 attr
->value_tag
== IPP_TAG_INTEGER
)
2082 interval
= attr
->values
[0].integer
;
2087 if (!recipient
&& !pullmethod
)
2090 if (mask
== CUPSD_EVENT_NONE
)
2091 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2093 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2094 recipient
, 0)) != NULL
)
2096 sub
->interval
= interval
;
2098 cupsdSetString(&sub
->owner
, job
->username
);
2102 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2103 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2104 (size_t)sub
->user_data_len
);
2107 ippAddSeparator(con
->response
);
2108 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2109 "notify-subscription-id", sub
->id
);
2111 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2119 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2122 * Remove all of the subscription attributes from the job request...
2124 * TODO: Optimize this since subscription groups have to come at the
2125 * end of the request...
2128 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2132 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2133 attr
->group_tag
== IPP_TAG_ZERO
)
2136 * Free and remove this attribute...
2139 ippDeleteAttribute(NULL
, attr
);
2144 job
->attrs
->attrs
= next
;
2150 job
->attrs
->last
= prev
;
2151 job
->attrs
->current
= prev
;
2156 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2158 * See RFC 4122 for the definition of UUIDs and the format.
2162 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2164 char uuid
[64]; /* job-uuid string */
2168 * Add a job-uuid attribute if none exists...
2171 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2172 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2173 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2174 uuid
, sizeof(uuid
)));
2179 * 'add_printer()' - Add a printer to the system.
2183 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2184 ipp_attribute_t
*uri
) /* I - URI of printer */
2186 http_status_t status
; /* Policy status */
2187 int i
; /* Looping var */
2188 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2189 username
[HTTP_MAX_URI
], /* Username portion of URI */
2190 host
[HTTP_MAX_URI
], /* Host portion of URI */
2191 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2192 int port
; /* Port portion of URI */
2193 cupsd_printer_t
*printer
; /* Printer/class */
2194 ipp_attribute_t
*attr
; /* Printer attribute */
2195 cups_file_t
*fp
; /* Script/PPD file */
2196 char line
[1024]; /* Line from file... */
2197 char srcfile
[1024], /* Source Script/PPD file */
2198 dstfile
[1024]; /* Destination Script/PPD file */
2199 int modify
; /* Non-zero if we are modifying */
2200 int changed_driver
, /* Changed the PPD? */
2201 need_restart_job
, /* Need to restart job? */
2202 set_device_uri
, /* Did we set the device URI? */
2203 set_port_monitor
; /* Did we set the port monitor? */
2206 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2207 con
->number
, uri
->values
[0].string
.text
);
2210 * Do we have a valid URI?
2213 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2214 sizeof(scheme
), username
, sizeof(username
), host
,
2215 sizeof(host
), &port
, resource
, sizeof(resource
));
2217 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2220 * No, return an error...
2223 send_ipp_status(con
, IPP_BAD_REQUEST
,
2224 _("The printer-uri must be of the form "
2225 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2230 * Do we have a valid printer name?
2233 if (!validate_name(resource
+ 10))
2236 * No, return an error...
2239 send_ipp_status(con
, IPP_BAD_REQUEST
,
2240 _("The printer-uri \"%s\" contains invalid characters."),
2241 uri
->values
[0].string
.text
);
2246 * See if the printer already exists; if not, create a new printer...
2249 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2252 * Printer doesn't exist; see if we have a class of the same name...
2255 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2258 * Yes, return an error...
2261 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2262 _("A class named \"%s\" already exists."),
2268 * No, check the default policy then add the printer...
2271 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2273 send_http_error(con
, status
, NULL
);
2277 printer
= cupsdAddPrinter(resource
+ 10);
2280 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2283 send_http_error(con
, status
, printer
);
2290 * Look for attributes and copy them over as needed...
2294 need_restart_job
= 0;
2296 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2297 IPP_TAG_TEXT
)) != NULL
)
2298 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2300 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2301 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2303 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2304 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2306 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2307 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2309 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2310 IPP_TAG_TEXT
)) != NULL
)
2311 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2315 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2316 IPP_TAG_URI
)) != NULL
)
2319 * Do we have a valid device URI?
2322 http_uri_status_t uri_status
; /* URI separation status */
2323 char old_device_uri
[1024];
2324 /* Old device URI */
2325 static const char * const uri_status_strings
[] =
2328 "Bad arguments to function.",
2329 "Bad resource path.",
2331 "Bad hostname/address.",
2332 "Bad username/password.",
2336 "Missing URI scheme.",
2337 "Unknown URI scheme",
2338 "Missing resource path."
2342 need_restart_job
= 1;
2344 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2345 attr
->values
[0].string
.text
,
2346 scheme
, sizeof(scheme
),
2347 username
, sizeof(username
),
2348 host
, sizeof(host
), &port
,
2349 resource
, sizeof(resource
));
2351 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2352 "%s device-uri: %s", printer
->name
,
2353 uri_status_strings
[uri_status
- HTTP_URI_STATUS_OVERFLOW
]);
2355 if (uri_status
< HTTP_URI_OK
)
2357 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2358 attr
->values
[0].string
.text
);
2362 if (!strcmp(scheme
, "file"))
2365 * See if the administrator has enabled file devices...
2368 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2371 * File devices are disabled and the URL is not file:/dev/null...
2374 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2375 _("File device URIs have been disabled. "
2376 "To enable, see the FileDevice directive in "
2377 "\"%s/cups-files.conf\"."),
2385 * See if the backend exists and is executable...
2388 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2389 if (access(srcfile
, X_OK
))
2392 * Could not find device in list!
2395 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2396 _("Bad device-uri scheme \"%s\"."), scheme
);
2401 if (printer
->sanitized_device_uri
)
2402 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2403 sizeof(old_device_uri
));
2405 old_device_uri
[0] = '\0';
2407 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2409 cupsdLogMessage(CUPSD_LOG_INFO
,
2410 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2411 printer
->name
, printer
->sanitized_device_uri
,
2417 set_port_monitor
= 0;
2419 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2420 IPP_TAG_NAME
)) != NULL
)
2422 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2425 need_restart_job
= 1;
2427 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2431 for (i
= 0; i
< supported
->num_values
; i
++)
2432 if (!strcmp(supported
->values
[i
].string
.text
,
2433 attr
->values
[0].string
.text
))
2437 if (!supported
|| i
>= supported
->num_values
)
2439 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2440 attr
->values
[0].string
.text
);
2444 cupsdLogMessage(CUPSD_LOG_INFO
,
2445 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2446 printer
->name
, attr
->values
[0].string
.text
,
2447 printer
->port_monitor
? printer
->port_monitor
: "none");
2449 if (strcmp(attr
->values
[0].string
.text
, "none"))
2450 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2452 cupsdClearString(&printer
->port_monitor
);
2454 set_port_monitor
= 1;
2457 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2458 IPP_TAG_BOOLEAN
)) != NULL
&&
2459 attr
->values
[0].boolean
!= printer
->accepting
)
2461 cupsdLogMessage(CUPSD_LOG_INFO
,
2462 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2463 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2465 printer
->accepting
= attr
->values
[0].boolean
;
2467 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2468 "%s accepting jobs.",
2469 printer
->accepting
? "Now" : "No longer");
2472 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2473 IPP_TAG_BOOLEAN
)) != NULL
)
2475 if (attr
->values
[0].boolean
&&
2476 printer
->num_auth_info_required
== 1 &&
2477 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2479 send_ipp_status(con
, IPP_BAD_REQUEST
,
2480 _("Cannot share a remote Kerberized printer."));
2484 if (printer
->type
& CUPS_PRINTER_REMOTE
)
2487 * Cannot re-share remote printers.
2490 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
2494 if (printer
->shared
&& !attr
->values
[0].boolean
)
2495 cupsdDeregisterPrinter(printer
, 1);
2497 cupsdLogMessage(CUPSD_LOG_INFO
,
2498 "Setting %s printer-is-shared to %d (was %d.)",
2499 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2501 printer
->shared
= attr
->values
[0].boolean
;
2504 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2505 IPP_TAG_ENUM
)) != NULL
)
2507 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2508 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2510 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2511 attr
->values
[0].integer
);
2515 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2516 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2518 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2519 cupsdStopPrinter(printer
, 0);
2522 need_restart_job
= 1;
2523 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2527 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2528 IPP_TAG_TEXT
)) != NULL
)
2530 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2531 sizeof(printer
->state_message
));
2533 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2534 printer
->state_message
);
2537 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2538 IPP_TAG_KEYWORD
)) != NULL
)
2540 if (attr
->num_values
>
2541 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2543 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2544 _("Too many printer-state-reasons values (%d > %d)."),
2546 (int)(sizeof(printer
->reasons
) /
2547 sizeof(printer
->reasons
[0])));
2551 for (i
= 0; i
< printer
->num_reasons
; i
++)
2552 _cupsStrFree(printer
->reasons
[i
]);
2554 printer
->num_reasons
= 0;
2555 for (i
= 0; i
< attr
->num_values
; i
++)
2557 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2560 printer
->reasons
[printer
->num_reasons
] =
2561 _cupsStrRetain(attr
->values
[i
].string
.text
);
2562 printer
->num_reasons
++;
2564 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2565 printer
->state
!= IPP_PRINTER_STOPPED
)
2567 cupsdLogMessage(CUPSD_LOG_INFO
,
2568 "Setting %s printer-state to %d (was %d.)",
2569 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2570 cupsdStopPrinter(printer
, 0);
2574 if (PrintcapFormat
== PRINTCAP_PLIST
)
2575 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2577 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2578 "Printer \"%s\" state changed.", printer
->name
);
2581 set_printer_defaults(con
, printer
);
2583 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2584 IPP_TAG_KEYWORD
)) != NULL
)
2585 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2588 * See if we have all required attributes...
2591 if (!printer
->device_uri
)
2592 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2595 * See if we have a PPD file attached to the request...
2600 need_restart_job
= 1;
2603 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2605 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2608 * Yes; get the first line from it...
2612 cupsFileGets(fp
, line
, sizeof(line
));
2616 * Then see what kind of file it is...
2619 if (strncmp(line
, "*PPD-Adobe", 10))
2621 send_ipp_status(con
, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED
, _("Bad PPD file."));
2625 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2629 * The new file is a PPD file, so move the file over to the ppd
2633 if (copy_file(srcfile
, dstfile
, ConfigFilePerm
))
2635 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file - %s"), strerror(errno
));
2639 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2642 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
)
2644 const char *ppd_name
= ippGetString(attr
, 0, NULL
);
2645 /* ppd-name value */
2647 need_restart_job
= 1;
2650 if (!strcmp(ppd_name
, "raw"))
2653 * Raw driver, remove any existing PPD file.
2656 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2659 else if (strstr(ppd_name
, "../"))
2661 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
2670 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2672 if (copy_model(con
, ppd_name
, dstfile
))
2674 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2678 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2685 * If we changed the PPD, then remove the printer's cache file and clear the
2686 * printer-state-reasons...
2689 char cache_name
[1024]; /* Cache filename for printer attrs */
2691 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
,
2695 cupsdSetPrinterReasons(printer
, "none");
2698 * (Re)register color profiles...
2701 cupsdRegisterColor(printer
);
2705 * If we set the device URI but not the port monitor, check which port
2706 * monitor to use by default...
2709 if (set_device_uri
&& !set_port_monitor
)
2711 ppd_file_t
*ppd
; /* PPD file */
2712 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2715 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2716 sizeof(scheme
), username
, sizeof(username
), host
,
2717 sizeof(host
), &port
, resource
, sizeof(resource
));
2719 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2721 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2723 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2725 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2726 if (!strcmp(scheme
, ppdattr
->spec
))
2728 cupsdLogMessage(CUPSD_LOG_INFO
,
2729 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2730 printer
->name
, ppdattr
->value
,
2731 printer
->port_monitor
? printer
->port_monitor
2734 if (strcmp(ppdattr
->value
, "none"))
2735 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2737 cupsdClearString(&printer
->port_monitor
);
2746 printer
->config_time
= time(NULL
);
2749 * Update the printer attributes and return...
2752 cupsdSetPrinterAttrs(printer
);
2753 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2755 if (need_restart_job
&& printer
->job
)
2758 * Restart the current job...
2761 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2762 "Job restarted because the printer was modified.");
2765 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2769 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2770 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2771 printer
->name
, get_username(con
));
2773 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2774 printer
->name
, get_username(con
));
2778 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2779 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2780 printer
->name
, get_username(con
));
2782 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2783 printer
->name
, get_username(con
));
2786 con
->response
->request
.status
.status_code
= IPP_OK
;
2791 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2792 * based upon the printer state...
2796 add_printer_state_reasons(
2797 cupsd_client_t
*con
, /* I - Client connection */
2798 cupsd_printer_t
*p
) /* I - Printer info */
2800 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2801 "add_printer_state_reasons(%p[%d], %p[%s])",
2802 con
, con
->number
, p
, p
->name
);
2804 if (p
->num_reasons
== 0)
2805 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2806 "printer-state-reasons", NULL
, "none");
2808 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2809 "printer-state-reasons", p
->num_reasons
, NULL
,
2810 (const char * const *)p
->reasons
);
2815 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2816 * the specified printer or class.
2820 add_queued_job_count(
2821 cupsd_client_t
*con
, /* I - Client connection */
2822 cupsd_printer_t
*p
) /* I - Printer or class */
2824 int count
; /* Number of jobs on destination */
2827 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2828 con
, con
->number
, p
, p
->name
);
2830 count
= cupsdGetPrinterJobCount(p
->name
);
2832 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2833 "queued-job-count", count
);
2838 * 'apply_printer_defaults()' - Apply printer default options to a job.
2842 apply_printer_defaults(
2843 cupsd_printer_t
*printer
, /* I - Printer */
2844 cupsd_job_t
*job
) /* I - Job */
2846 int i
, /* Looping var */
2847 num_options
; /* Number of default options */
2848 cups_option_t
*options
, /* Default options */
2849 *option
; /* Current option */
2853 * Collect all of the default options and add the missing ones to the
2857 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2858 option
= printer
->options
;
2861 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2863 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2868 * Encode these options as attributes in the job object...
2871 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2872 cupsFreeOptions(num_options
, options
);
2877 * 'authenticate_job()' - Set job authentication info.
2881 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2882 ipp_attribute_t
*uri
) /* I - Job URI */
2884 ipp_attribute_t
*attr
, /* job-id attribute */
2885 *auth_info
; /* auth-info attribute */
2886 int jobid
; /* Job ID */
2887 cupsd_job_t
*job
; /* Current job */
2888 char scheme
[HTTP_MAX_URI
],
2889 /* Method portion of URI */
2890 username
[HTTP_MAX_URI
],
2891 /* Username portion of URI */
2893 /* Host portion of URI */
2894 resource
[HTTP_MAX_URI
];
2895 /* Resource portion of URI */
2896 int port
; /* Port portion of URI */
2899 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2900 con
, con
->number
, uri
->values
[0].string
.text
);
2903 * Start with "everything is OK" status...
2906 con
->response
->request
.status
.status_code
= IPP_OK
;
2909 * See if we have a job URI or a printer URI...
2912 if (!strcmp(uri
->name
, "printer-uri"))
2915 * Got a printer URI; see if we also have a job-id attribute...
2918 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2919 IPP_TAG_INTEGER
)) == NULL
)
2921 send_ipp_status(con
, IPP_BAD_REQUEST
,
2922 _("Got a printer-uri attribute but no job-id."));
2926 jobid
= attr
->values
[0].integer
;
2931 * Got a job URI; parse it to get the job ID...
2934 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2935 sizeof(scheme
), username
, sizeof(username
), host
,
2936 sizeof(host
), &port
, resource
, sizeof(resource
));
2938 if (strncmp(resource
, "/jobs/", 6))
2944 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
2945 uri
->values
[0].string
.text
);
2949 jobid
= atoi(resource
+ 6);
2953 * See if the job exists...
2956 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2959 * Nope - return a "not found" error...
2962 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
2967 * See if the job has been completed...
2970 if (job
->state_value
!= IPP_JOB_HELD
)
2973 * Return a "not-possible" error...
2976 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2977 _("Job #%d is not held for authentication."),
2983 * See if we have already authenticated...
2986 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
2988 if (!con
->username
[0] && !auth_info
)
2990 cupsd_printer_t
*printer
; /* Job destination */
2993 * No auth data. If we need to authenticate via Kerberos, send a
2994 * HTTP auth challenge, otherwise just return an IPP error...
2997 printer
= cupsdFindDest(job
->dest
);
2999 if (printer
&& printer
->num_auth_info_required
> 0 &&
3000 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3001 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3003 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3004 _("No authentication information provided."));
3009 * See if the job is owned by the requesting user...
3012 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3014 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3015 cupsdFindDest(job
->dest
));
3020 * Save the authentication information for this job...
3023 save_auth_info(con
, job
, auth_info
);
3026 * Reset the job-hold-until value to "no-hold"...
3029 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3030 IPP_TAG_KEYWORD
)) == NULL
)
3031 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3035 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3036 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3040 * Release the job and return...
3043 cupsdReleaseJob(job
);
3045 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3047 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3054 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3058 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3059 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3061 int i
; /* Looping var */
3062 http_status_t status
; /* Policy status */
3063 cups_ptype_t dtype
; /* Destination type */
3064 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3065 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3066 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3067 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3068 int port
; /* Port portion of URI */
3069 ipp_attribute_t
*attr
; /* Attribute in request */
3070 const char *username
= NULL
; /* Username */
3071 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3073 cupsd_printer_t
*printer
; /* Printer */
3074 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3075 cupsd_job_t
*job
; /* Job */
3078 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3079 con
->number
, uri
->values
[0].string
.text
);
3082 * Get the jobs to cancel/purge...
3085 switch (con
->request
->request
.op
.operation_id
)
3087 case IPP_PURGE_JOBS
:
3089 * Get the username (if any) for the jobs we want to cancel (only if
3090 * "my-jobs" is specified...
3093 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3094 IPP_TAG_BOOLEAN
)) != NULL
&&
3095 attr
->values
[0].boolean
)
3097 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3098 IPP_TAG_NAME
)) != NULL
)
3099 username
= attr
->values
[0].string
.text
;
3102 send_ipp_status(con
, IPP_BAD_REQUEST
,
3103 _("Missing requesting-user-name attribute."));
3109 * Look for the "purge-jobs" attribute...
3112 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3113 IPP_TAG_BOOLEAN
)) != NULL
)
3114 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3116 purge
= CUPSD_JOB_PURGE
;
3119 case IPP_CANCEL_MY_JOBS
:
3120 if (con
->username
[0])
3121 username
= con
->username
;
3122 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3123 IPP_TAG_NAME
)) != NULL
)
3124 username
= attr
->values
[0].string
.text
;
3127 send_ipp_status(con
, IPP_BAD_REQUEST
,
3128 _("Missing requesting-user-name attribute."));
3136 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3139 * See if we have a printer URI...
3142 if (strcmp(uri
->name
, "printer-uri"))
3144 send_ipp_status(con
, IPP_BAD_REQUEST
,
3145 _("The printer-uri attribute is required."));
3150 * And if the destination is valid...
3153 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3159 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3160 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3161 hostname
, sizeof(hostname
), &port
,
3162 resource
, sizeof(resource
));
3164 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3165 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3167 send_ipp_status(con
, IPP_NOT_FOUND
,
3168 _("The printer or class does not exist."));
3176 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3178 send_http_error(con
, status
, NULL
);
3184 for (i
= 0; i
< job_ids
->num_values
; i
++)
3186 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3189 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3190 _cups_strcasecmp(job
->username
, username
))
3194 if (i
< job_ids
->num_values
)
3196 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3197 job_ids
->values
[i
].integer
);
3201 for (i
= 0; i
< job_ids
->num_values
; i
++)
3203 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3205 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3206 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3207 "Job canceled by user.");
3210 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3211 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3217 * Cancel all jobs on all printers...
3220 cupsdCancelJobs(NULL
, username
, purge
);
3222 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3223 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3233 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3236 send_http_error(con
, status
, printer
);
3242 for (i
= 0; i
< job_ids
->num_values
; i
++)
3244 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3245 _cups_strcasecmp(job
->dest
, printer
->name
))
3248 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3249 _cups_strcasecmp(job
->username
, username
))
3253 if (i
< job_ids
->num_values
)
3255 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3256 job_ids
->values
[i
].integer
);
3260 for (i
= 0; i
< job_ids
->num_values
; i
++)
3262 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3264 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3265 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3266 "Job canceled by user.");
3269 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3270 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3276 * Cancel all of the jobs on the named printer...
3279 cupsdCancelJobs(printer
->name
, username
, purge
);
3281 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3283 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3288 con
->response
->request
.status
.status_code
= IPP_OK
;
3295 * 'cancel_job()' - Cancel a print job.
3299 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3300 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3302 ipp_attribute_t
*attr
; /* Current attribute */
3303 int jobid
; /* Job ID */
3304 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3305 username
[HTTP_MAX_URI
], /* Username portion of URI */
3306 host
[HTTP_MAX_URI
], /* Host portion of URI */
3307 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3308 int port
; /* Port portion of URI */
3309 cupsd_job_t
*job
; /* Job information */
3310 cups_ptype_t dtype
; /* Destination type (printer/class) */
3311 cupsd_printer_t
*printer
; /* Printer data */
3312 cupsd_jobaction_t purge
; /* Purge the job? */
3315 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3316 con
->number
, uri
->values
[0].string
.text
);
3319 * See if we have a job URI or a printer URI...
3322 if (!strcmp(uri
->name
, "printer-uri"))
3325 * Got a printer URI; see if we also have a job-id attribute...
3328 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3329 IPP_TAG_INTEGER
)) == NULL
)
3331 send_ipp_status(con
, IPP_BAD_REQUEST
,
3332 _("Got a printer-uri attribute but no job-id."));
3336 if ((jobid
= attr
->values
[0].integer
) == 0)
3339 * Find the current job on the specified printer...
3342 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3348 send_ipp_status(con
, IPP_NOT_FOUND
,
3349 _("The printer or class does not exist."));
3354 * See if there are any pending jobs...
3357 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3359 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3360 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3361 !_cups_strcasecmp(job
->dest
, printer
->name
))
3369 * No, try stopped jobs...
3372 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3374 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3375 if (job
->state_value
== IPP_JOB_STOPPED
&&
3376 !_cups_strcasecmp(job
->dest
, printer
->name
))
3383 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3393 * Got a job URI; parse it to get the job ID...
3396 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3397 sizeof(scheme
), username
, sizeof(username
), host
,
3398 sizeof(host
), &port
, resource
, sizeof(resource
));
3400 if (strncmp(resource
, "/jobs/", 6))
3406 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3407 uri
->values
[0].string
.text
);
3411 jobid
= atoi(resource
+ 6);
3415 * Look for the "purge-job" attribute...
3418 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3419 IPP_TAG_BOOLEAN
)) != NULL
)
3420 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3422 purge
= CUPSD_JOB_DEFAULT
;
3425 * See if the job exists...
3428 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3431 * Nope - return a "not found" error...
3434 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3439 * See if the job is owned by the requesting user...
3442 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3444 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3445 cupsdFindDest(job
->dest
));
3450 * See if the job is already completed, canceled, or aborted; if so,
3451 * we can't cancel...
3454 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3456 switch (job
->state_value
)
3458 case IPP_JOB_CANCELED
:
3459 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3460 _("Job #%d is already canceled - can\'t cancel."),
3464 case IPP_JOB_ABORTED
:
3465 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3466 _("Job #%d is already aborted - can\'t cancel."),
3471 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3472 _("Job #%d is already completed - can\'t cancel."),
3481 * Cancel the job and return...
3484 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3485 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3486 "Job canceled by \"%s\"",
3490 if (purge
== CUPSD_JOB_PURGE
)
3491 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3494 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3497 con
->response
->request
.status
.status_code
= IPP_OK
;
3502 * 'cancel_subscription()' - Cancel a subscription.
3506 cancel_subscription(
3507 cupsd_client_t
*con
, /* I - Client connection */
3508 int sub_id
) /* I - Subscription ID */
3510 http_status_t status
; /* Policy status */
3511 cupsd_subscription_t
*sub
; /* Subscription */
3514 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3515 "cancel_subscription(con=%p[%d], sub_id=%d)",
3516 con
, con
->number
, sub_id
);
3519 * Is the subscription ID valid?
3522 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3525 * Bad subscription ID...
3528 send_ipp_status(con
, IPP_NOT_FOUND
,
3529 _("Subscription #%d does not exist."), sub_id
);
3537 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3539 con
, sub
->owner
)) != HTTP_OK
)
3541 send_http_error(con
, status
, sub
->dest
);
3546 * Cancel the subscription...
3549 cupsdDeleteSubscription(sub
, 1);
3551 con
->response
->request
.status
.status_code
= IPP_OK
;
3556 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3559 static int /* O - 1 if OK, 0 if not */
3560 check_rss_recipient(
3561 const char *recipient
) /* I - Recipient URI */
3563 cupsd_subscription_t
*sub
; /* Current subscription */
3566 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3568 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3572 * Compare the URIs up to the first ?...
3575 const char *r1
, *r2
;
3577 for (r1
= recipient
, r2
= sub
->recipient
;
3578 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3590 * 'check_quotas()' - Check quotas for a printer and user.
3593 static int /* O - 1 if OK, 0 if forbidden,
3594 -1 if limit reached */
3595 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3596 cupsd_printer_t
*p
) /* I - Printer or class */
3598 char username
[33], /* Username */
3599 *name
; /* Current user name */
3600 cupsd_quota_t
*q
; /* Quota data */
3601 #ifdef HAVE_MBR_UID_TO_UUID
3603 * Use Apple membership APIs which require that all names represent
3604 * valid user account or group records accessible by the server.
3607 uuid_t usr_uuid
; /* UUID for job requesting user */
3608 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3609 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3610 int mbr_err
; /* Error from membership function */
3611 int is_member
; /* Is this user a member? */
3614 * Use standard POSIX APIs for checking users and groups...
3617 struct passwd
*pw
; /* User password data */
3618 #endif /* HAVE_MBR_UID_TO_UUID */
3621 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3622 con
, con
->number
, p
, p
->name
);
3625 * Figure out who is printing...
3628 strlcpy(username
, get_username(con
), sizeof(username
));
3630 if ((name
= strchr(username
, '@')) != NULL
)
3631 *name
= '\0'; /* Strip @REALM */
3634 * Check global active job limits for printers and users...
3637 if (MaxJobsPerPrinter
)
3640 * Check if there are too many pending jobs on this printer...
3643 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3645 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3654 * Check if there are too many pending jobs for this user...
3657 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3659 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3666 * Check against users...
3669 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3672 if (cupsArrayCount(p
->users
))
3674 #ifdef HAVE_MBR_UID_TO_UUID
3676 * Get UUID for job requesting user...
3679 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3685 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3686 "check_quotas: UUID lookup failed for user \"%s\"",
3688 cupsdLogMessage(CUPSD_LOG_INFO
,
3689 "Denying user \"%s\" access to printer \"%s\" "
3690 "(unknown user)...",
3696 * Get UID and GID of requesting user...
3699 pw
= getpwnam(username
);
3701 #endif /* HAVE_MBR_UID_TO_UUID */
3703 for (name
= (char *)cupsArrayFirst(p
->users
);
3705 name
= (char *)cupsArrayNext(p
->users
))
3709 * Check group membership...
3712 #ifdef HAVE_MBR_UID_TO_UUID
3715 if (uuid_parse(name
+ 2, grp_uuid
))
3716 uuid_clear(grp_uuid
);
3718 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3721 * Invalid ACL entries are ignored for matching; just record a
3722 * warning in the log...
3725 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3726 "check_quotas: UUID lookup failed for ACL entry "
3727 "\"%s\" (err=%d)", name
, mbr_err
);
3728 cupsdLogMessage(CUPSD_LOG_WARN
,
3729 "Access control entry \"%s\" not a valid group name; "
3730 "entry ignored", name
);
3733 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3737 * At this point, there should be no errors, but check anyways...
3740 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3741 "check_quotas: group \"%s\" membership check "
3742 "failed (err=%d)", name
+ 1, mbr_err
);
3747 * Stop if we found a match...
3754 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3756 #endif /* HAVE_MBR_UID_TO_UUID */
3758 #ifdef HAVE_MBR_UID_TO_UUID
3763 if (uuid_parse(name
+ 1, usr2_uuid
))
3764 uuid_clear(usr2_uuid
);
3766 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3769 * Invalid ACL entries are ignored for matching; just record a
3770 * warning in the log...
3773 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3774 "check_quotas: UUID lookup failed for ACL entry "
3775 "\"%s\" (err=%d)", name
, mbr_err
);
3776 cupsdLogMessage(CUPSD_LOG_WARN
,
3777 "Access control entry \"%s\" not a valid user name; "
3778 "entry ignored", name
);
3781 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3785 else if (!_cups_strcasecmp(username
, name
))
3787 #endif /* HAVE_MBR_UID_TO_UUID */
3789 if ((name
!= NULL
) == p
->deny_users
)
3791 cupsdLogMessage(CUPSD_LOG_INFO
,
3792 "Denying user \"%s\" access to printer \"%s\"...",
3802 if (p
->k_limit
|| p
->page_limit
)
3804 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3806 cupsdLogMessage(CUPSD_LOG_ERROR
,
3807 "Unable to allocate quota data for user \"%s\"",
3812 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3813 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3815 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3822 * If we have gotten this far, we're done!
3830 * 'close_job()' - Close a multi-file job.
3834 close_job(cupsd_client_t
*con
, /* I - Client connection */
3835 ipp_attribute_t
*uri
) /* I - Printer URI */
3837 cupsd_job_t
*job
; /* Job */
3838 ipp_attribute_t
*attr
; /* Attribute */
3839 char job_uri
[HTTP_MAX_URI
],
3841 username
[256]; /* User name */
3844 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3845 con
->number
, uri
->values
[0].string
.text
);
3848 * See if we have a job URI or a printer URI...
3851 if (strcmp(uri
->name
, "printer-uri"))
3854 * job-uri is not supported by Close-Job!
3857 send_ipp_status(con
, IPP_BAD_REQUEST
,
3858 _("Close-Job doesn't support the job-uri attribute."));
3863 * Got a printer URI; see if we also have a job-id attribute...
3866 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3867 IPP_TAG_INTEGER
)) == NULL
)
3869 send_ipp_status(con
, IPP_BAD_REQUEST
,
3870 _("Got a printer-uri attribute but no job-id."));
3874 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3877 * Nope - return a "not found" error...
3880 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3881 attr
->values
[0].integer
);
3886 * See if the job is owned by the requesting user...
3889 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3891 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3892 cupsdFindDest(job
->dest
));
3897 * Add any ending sheet...
3900 if (cupsdTimeoutJob(job
))
3903 if (job
->state_value
== IPP_JOB_STOPPED
)
3905 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3906 job
->state_value
= IPP_JOB_PENDING
;
3908 else if (job
->state_value
== IPP_JOB_HELD
)
3910 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3911 IPP_TAG_KEYWORD
)) == NULL
)
3912 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3914 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3916 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3917 job
->state_value
= IPP_JOB_PENDING
;
3922 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3925 * Fill in the response info...
3928 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3929 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
3930 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
3933 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
3935 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
3938 con
->response
->request
.status
.status_code
= IPP_OK
;
3941 * Start the job if necessary...
3949 * 'copy_attrs()' - Copy attributes from one request to another.
3953 copy_attrs(ipp_t
*to
, /* I - Destination request */
3954 ipp_t
*from
, /* I - Source request */
3955 cups_array_t
*ra
, /* I - Requested attributes */
3956 ipp_tag_t group
, /* I - Group to copy */
3957 int quickcopy
, /* I - Do a quick copy? */
3958 cups_array_t
*exclude
) /* I - Attributes to exclude? */
3960 ipp_attribute_t
*fromattr
; /* Source attribute */
3963 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3964 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
3965 to
, from
, ra
, group
, quickcopy
);
3970 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
3973 * Filter attributes as needed...
3976 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
3977 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
3980 if (!strcmp(fromattr
->name
, "document-password") ||
3981 !strcmp(fromattr
->name
, "job-authorization-uri") ||
3982 !strcmp(fromattr
->name
, "job-password") ||
3983 !strcmp(fromattr
->name
, "job-password-encryption") ||
3984 !strcmp(fromattr
->name
, "job-printer-uri"))
3988 (cupsArrayFind(exclude
, fromattr
->name
) ||
3989 cupsArrayFind(exclude
, "all")))
3992 * We need to exclude this attribute for security reasons; we require the
3993 * job-id attribute regardless of the security settings for IPP
3996 * The job-printer-uri attribute is handled by copy_job_attrs().
3998 * Subscription attribute security is handled by copy_subscription_attrs().
4001 if (strcmp(fromattr
->name
, "job-id"))
4005 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4008 * Don't send collection attributes by default to IPP/1.x clients
4009 * since many do not support collections. Also don't send
4010 * media-col-database unless specifically requested by the client.
4013 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4015 (to
->request
.status
.version
[0] == 1 ||
4016 !strcmp(fromattr
->name
, "media-col-database")))
4019 ippCopyAttribute(to
, fromattr
, quickcopy
);
4026 * 'copy_banner()' - Copy a banner file to the requests directory for the
4030 static int /* O - Size of banner file in kbytes */
4031 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4032 cupsd_job_t
*job
, /* I - Job information */
4033 const char *name
) /* I - Name of banner */
4035 int i
; /* Looping var */
4036 int kbytes
; /* Size of banner file in kbytes */
4037 char filename
[1024]; /* Job filename */
4038 cupsd_banner_t
*banner
; /* Pointer to banner */
4039 cups_file_t
*in
; /* Input file */
4040 cups_file_t
*out
; /* Output file */
4041 int ch
; /* Character from file */
4042 char attrname
[255], /* Name of attribute */
4043 *s
; /* Pointer into name */
4044 ipp_attribute_t
*attr
; /* Attribute */
4047 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4048 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4049 con
, con
? con
->number
: -1, job
, job
->id
,
4050 name
? name
: "(null)");
4053 * Find the banner; return if not found or "none"...
4056 if (!name
|| !strcmp(name
, "none") ||
4057 (banner
= cupsdFindBanner(name
)) == NULL
)
4061 * Open the banner and job files...
4064 if (add_file(con
, job
, banner
->filetype
, 0))
4067 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4069 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4071 cupsdLogMessage(CUPSD_LOG_ERROR
,
4072 "Unable to create banner job file %s - %s",
4073 filename
, strerror(errno
));
4078 fchmod(cupsFileNumber(out
), 0640);
4079 fchown(cupsFileNumber(out
), RunUser
, Group
);
4082 * Try the localized banner file under the subdirectory...
4085 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4087 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4090 * Convert ll-cc to ll_CC...
4094 attrname
[3] = (char)toupper(attrname
[3] & 255);
4095 attrname
[4] = (char)toupper(attrname
[4] & 255);
4098 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4101 if (access(filename
, 0) && strlen(attrname
) > 2)
4104 * Wasn't able to find "ll_CC" locale file; try the non-national
4105 * localization banner directory.
4110 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4114 if (access(filename
, 0))
4117 * Use the non-localized banner file.
4120 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4123 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4127 cupsdLogMessage(CUPSD_LOG_ERROR
,
4128 "Unable to open banner template file %s - %s",
4129 filename
, strerror(errno
));
4135 * Parse the file to the end...
4138 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4142 * Get an attribute name...
4145 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4146 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4148 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4158 * Ignore { followed by stuff that is not an attribute name...
4161 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4166 * See if it is defined...
4169 if (attrname
[0] == '?')
4174 if (!strcmp(s
, "printer-name"))
4176 cupsFilePuts(out
, job
->dest
);
4179 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4182 * See if we have a leading question mark...
4185 if (attrname
[0] != '?')
4188 * Nope, write to file as-is; probably a PostScript procedure...
4191 cupsFilePrintf(out
, "{%s}", attrname
);
4198 * Output value(s)...
4201 for (i
= 0; i
< attr
->num_values
; i
++)
4204 cupsFilePutChar(out
, ',');
4206 switch (attr
->value_tag
)
4208 case IPP_TAG_INTEGER
:
4210 if (!strncmp(s
, "time-at-", 8))
4212 struct timeval tv
; /* Time value */
4214 tv
.tv_sec
= attr
->values
[i
].integer
;
4217 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4220 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4223 case IPP_TAG_BOOLEAN
:
4224 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4227 case IPP_TAG_NOVALUE
:
4228 cupsFilePuts(out
, "novalue");
4231 case IPP_TAG_RANGE
:
4232 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4233 attr
->values
[i
].range
.upper
);
4236 case IPP_TAG_RESOLUTION
:
4237 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4238 attr
->values
[i
].resolution
.yres
,
4239 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4244 case IPP_TAG_STRING
:
4247 case IPP_TAG_KEYWORD
:
4248 case IPP_TAG_CHARSET
:
4249 case IPP_TAG_LANGUAGE
:
4250 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4253 * Need to quote strings for PS banners...
4258 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4260 if (*p
== '(' || *p
== ')' || *p
== '\\')
4262 cupsFilePutChar(out
, '\\');
4263 cupsFilePutChar(out
, *p
);
4265 else if (*p
< 32 || *p
> 126)
4266 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4268 cupsFilePutChar(out
, *p
);
4272 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4276 break; /* anti-compiler-warning-code */
4280 else if (ch
== '\\') /* Quoted char */
4282 ch
= cupsFileGetChar(in
);
4284 if (ch
!= '{') /* Only do special handling for \{ */
4285 cupsFilePutChar(out
, '\\');
4287 cupsFilePutChar(out
, ch
);
4290 cupsFilePutChar(out
, ch
);
4294 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4296 job
->koctets
+= kbytes
;
4298 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4299 attr
->values
[0].integer
+= kbytes
;
4308 * 'copy_file()' - Copy a PPD file...
4311 static int /* O - 0 = success, -1 = error */
4312 copy_file(const char *from
, /* I - Source file */
4313 const char *to
, /* I - Destination file */
4314 mode_t mode
) /* I - Permissions */
4316 cups_file_t
*src
, /* Source file */
4317 *dst
; /* Destination file */
4318 int bytes
; /* Bytes to read/write */
4319 char buffer
[2048]; /* Copy buffer */
4322 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4325 * Open the source and destination file for a copy...
4328 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4331 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4338 * Copy the source file to the destination...
4341 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4342 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4350 * Close both files and return...
4355 return (cupsdCloseCreatedConfFile(dst
, to
));
4360 * 'copy_model()' - Copy a PPD model file, substituting default values
4364 static int /* O - 0 = success, -1 = error */
4365 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4366 const char *from
, /* I - Source file */
4367 const char *to
) /* I - Destination file */
4369 fd_set input
; /* select() input set */
4370 struct timeval timeout
; /* select() timeout */
4371 int maxfd
; /* Max file descriptor for select() */
4372 char tempfile
[1024]; /* Temporary PPD file */
4373 int tempfd
; /* Temporary PPD file descriptor */
4374 int temppid
; /* Process ID of cups-driverd */
4375 int temppipe
[2]; /* Temporary pipes */
4376 char *argv
[4], /* Command-line arguments */
4377 *envp
[MAX_ENV
]; /* Environment */
4378 cups_file_t
*src
, /* Source file */
4379 *dst
; /* Destination file */
4380 ppd_file_t
*ppd
; /* PPD file */
4381 int bytes
, /* Bytes from pipe */
4382 total
; /* Total bytes from pipe */
4383 char buffer
[2048]; /* Copy buffer */
4384 int i
; /* Looping var */
4385 char option
[PPD_MAX_NAME
], /* Option name */
4386 choice
[PPD_MAX_NAME
]; /* Choice name */
4387 ppd_size_t
*size
; /* Default size */
4388 int num_defaults
; /* Number of default options */
4389 cups_option_t
*defaults
; /* Default options */
4390 char cups_protocol
[PPD_MAX_LINE
];
4391 /* cupsProtocol attribute */
4394 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4397 * Run cups-driverd to get the PPD file...
4400 argv
[0] = "cups-driverd";
4402 argv
[2] = (char *)from
;
4405 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4407 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4408 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4409 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4410 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4413 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4414 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4416 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4417 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4428 * Wait up to 30 seconds for the PPD file to be copied...
4433 if (temppipe
[0] > CGIPipes
[0])
4434 maxfd
= temppipe
[0] + 1;
4436 maxfd
= CGIPipes
[0] + 1;
4441 * See if we have data ready...
4445 FD_SET(temppipe
[0], &input
);
4446 FD_SET(CGIPipes
[0], &input
);
4448 timeout
.tv_sec
= 30;
4449 timeout
.tv_usec
= 0;
4451 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4461 * We have timed out...
4467 if (FD_ISSET(temppipe
[0], &input
))
4470 * Read the PPD file from the pipe, and write it to the PPD file.
4473 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4475 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4484 if (FD_ISSET(CGIPipes
[0], &input
))
4494 * No data from cups-deviced...
4497 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4503 * Open the source file for a copy...
4506 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4513 * Read the source file and see what page sizes are supported...
4516 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4524 * Open the destination (if possible) and set the default options...
4529 cups_protocol
[0] = '\0';
4531 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4534 * Read all of the default lines from the old PPD...
4537 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4538 if (!strncmp(buffer
, "*Default", 8))
4541 * Add the default option...
4544 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4545 choice
, sizeof(choice
)))
4547 ppd_option_t
*ppdo
; /* PPD option */
4551 * Only add the default if the default hasn't already been
4552 * set and the choice exists in the new PPD...
4555 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4556 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4557 ppdFindChoice(ppdo
, choice
))
4558 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4562 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4563 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4567 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4570 * Add the default media sizes...
4573 num_defaults
= cupsAddOption("PageSize", size
->name
,
4574 num_defaults
, &defaults
);
4575 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4576 num_defaults
, &defaults
);
4577 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4578 num_defaults
, &defaults
);
4579 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4580 num_defaults
, &defaults
);
4586 * Open the destination file for a copy...
4589 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4591 cupsFreeOptions(num_defaults
, defaults
);
4598 * Copy the source file to the destination...
4601 cupsFileRewind(src
);
4603 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4605 if (!strncmp(buffer
, "*Default", 8))
4608 * Check for an previous default option choice...
4611 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4612 choice
, sizeof(choice
)))
4614 const char *val
; /* Default option value */
4617 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4620 * Substitute the previous choice...
4623 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4628 cupsFilePrintf(dst
, "%s\n", buffer
);
4631 if (cups_protocol
[0])
4632 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4634 cupsFreeOptions(num_defaults
, defaults
);
4637 * Close both files and return...
4644 return (cupsdCloseCreatedConfFile(dst
, to
));
4649 * 'copy_job_attrs()' - Copy job attributes.
4653 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4654 cupsd_job_t
*job
, /* I - Job */
4655 cups_array_t
*ra
, /* I - Requested attributes array */
4656 cups_array_t
*exclude
) /* I - Private attributes array */
4658 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4662 * Send the requested attributes for each job...
4665 if (!cupsArrayFind(exclude
, "all"))
4667 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4668 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4669 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4670 "number-of-documents", job
->num_files
);
4672 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4673 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4674 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4675 "job-media-progress", job
->progress
);
4677 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4678 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4680 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4681 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4683 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4684 "job-more-info", NULL
, job_uri
);
4687 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4688 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4689 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4690 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4691 job
->num_files
> 0);
4693 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4694 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4695 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4696 "job-printer-up-time", time(NULL
));
4699 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4701 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4702 con
->clientname
, con
->clientport
,
4703 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4706 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4707 "job-printer-uri", NULL
, job_uri
);
4710 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4712 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4713 con
->clientname
, con
->clientport
, "/jobs/%d",
4715 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4716 "job-uri", NULL
, job_uri
);
4721 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4726 * Generate attributes from the job structure...
4729 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4730 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4732 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4733 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4735 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4736 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4738 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4739 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4741 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4742 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-name", NULL
, job
->name
);
4744 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4745 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_CONST_TAG(IPP_TAG_NAME
), "job-originating-user-name", NULL
, job
->username
);
4747 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4748 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4750 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4752 switch (job
->state_value
)
4754 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4756 case IPP_JSTATE_ABORTED
:
4757 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4759 case IPP_JSTATE_CANCELED
:
4760 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4762 case IPP_JSTATE_COMPLETED
:
4763 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4768 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4769 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4771 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4772 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4778 * 'copy_printer_attrs()' - Copy printer attributes.
4783 cupsd_client_t
*con
, /* I - Client connection */
4784 cupsd_printer_t
*printer
, /* I - Printer */
4785 cups_array_t
*ra
) /* I - Requested attributes array */
4787 char printer_uri
[HTTP_MAX_URI
];
4789 char printer_icons
[HTTP_MAX_URI
];
4791 time_t curtime
; /* Current time */
4792 int i
; /* Looping var */
4796 * Copy the printer attributes to the response using requested-attributes
4797 * and document-format attributes that may be provided by the client.
4800 curtime
= time(NULL
);
4802 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4803 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4804 "marker-change-time", printer
->marker_time
);
4806 if (printer
->num_printers
> 0 &&
4807 (!ra
|| cupsArrayFind(ra
, "member-uris")))
4809 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4810 cupsd_printer_t
*p2
; /* Printer in class */
4811 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4814 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
,
4815 IPP_TAG_URI
, "member-uris",
4816 printer
->num_printers
, NULL
,
4819 for (i
= 0; i
< printer
->num_printers
; i
++)
4821 p2
= printer
->printers
[i
];
4823 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported",
4824 IPP_TAG_URI
)) != NULL
)
4825 member_uris
->values
[i
].string
.text
=
4826 _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4829 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
,
4830 sizeof(printer_uri
), "ipp", NULL
, con
->clientname
,
4832 (p2
->type
& CUPS_PRINTER_CLASS
) ?
4833 "/classes/%s" : "/printers/%s", p2
->name
);
4834 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(printer_uri
);
4840 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4841 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
,
4842 "printer-alert", NULL
, printer
->alert
);
4844 if (printer
->alert_description
&&
4845 (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4846 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4847 "printer-alert-description", NULL
,
4848 printer
->alert_description
);
4850 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4851 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4853 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4854 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4855 "printer-config-change-time", printer
->config_time
);
4857 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4858 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4859 ippTimeToDate(curtime
));
4861 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4862 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4864 if (printer
->reg_name
)
4865 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4866 "printer-dns-sd-name", NULL
, printer
->reg_name
);
4868 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
4869 "printer-dns-sd-name", 0);
4871 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4873 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4874 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4875 "printer-error-policy", NULL
, printer
->error_policy
);
4877 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4879 static const char * const errors
[] =/* printer-error-policy-supported values */
4882 "retry-current-job",
4887 if (printer
->type
& CUPS_PRINTER_CLASS
)
4888 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4889 "printer-error-policy-supported", NULL
, "retry-current-job");
4891 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
4892 "printer-error-policy-supported",
4893 sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4896 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4898 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_icons
, sizeof(printer_icons
),
4899 "http", NULL
, con
->clientname
, con
->clientport
,
4900 "/icons/%s.png", printer
->name
);
4901 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons",
4902 NULL
, printer_icons
);
4903 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", printer_icons
);
4906 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4907 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4909 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4910 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4912 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4914 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4915 "http", NULL
, con
->clientname
, con
->clientport
,
4916 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4917 "/classes/%s" : "/printers/%s", printer
->name
);
4918 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4919 "printer-more-info", NULL
, printer_uri
);
4922 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4923 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4924 "printer-op-policy", NULL
, printer
->op_policy
);
4926 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4927 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4930 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
4931 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
4933 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4934 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4935 "printer-state-change-time", printer
->state_time
);
4937 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4938 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4939 "printer-state-message", NULL
, printer
->state_message
);
4941 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4942 add_printer_state_reasons(con
, printer
);
4944 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4946 cups_ptype_t type
; /* printer-type value */
4949 * Add the CUPS-specific printer-type attribute...
4952 type
= printer
->type
;
4954 if (printer
== DefaultPrinter
)
4955 type
|= CUPS_PRINTER_DEFAULT
;
4957 if (!printer
->accepting
)
4958 type
|= CUPS_PRINTER_REJECTING
;
4960 if (!printer
->shared
)
4961 type
|= CUPS_PRINTER_NOT_SHARED
;
4963 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
4966 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4967 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4968 "printer-up-time", curtime
);
4970 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
4972 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4973 "ipp", NULL
, con
->clientname
, con
->clientport
,
4974 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4975 "/classes/%s" : "/printers/%s", printer
->name
);
4976 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4977 "printer-uri-supported", NULL
, printer_uri
);
4978 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4982 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4983 add_queued_job_count(con
, printer
);
4985 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4986 if (printer
->ppd_attrs
)
4987 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
4988 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
4993 * 'copy_subscription_attrs()' - Copy subscription attributes.
4997 copy_subscription_attrs(
4998 cupsd_client_t
*con
, /* I - Client connection */
4999 cupsd_subscription_t
*sub
, /* I - Subscription */
5000 cups_array_t
*ra
, /* I - Requested attributes array */
5001 cups_array_t
*exclude
) /* I - Private attributes array */
5003 ipp_attribute_t
*attr
; /* Current attribute */
5004 char printer_uri
[HTTP_MAX_URI
];
5006 int count
; /* Number of events */
5007 unsigned mask
; /* Current event mask */
5008 const char *name
; /* Current event name */
5011 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5012 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5013 con
, sub
, ra
, exclude
);
5016 * Copy the subscription attributes to the response using the
5017 * requested-attributes attribute that may be provided by the client.
5020 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5022 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5023 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5025 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5027 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5030 * Simple event list...
5033 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
5034 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5035 "notify-events", NULL
, name
);
5040 * Complex event list...
5043 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5044 if (sub
->mask
& mask
)
5047 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
5048 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
5049 "notify-events", count
, NULL
, NULL
);
5051 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5052 if (sub
->mask
& mask
)
5054 attr
->values
[count
].string
.text
=
5055 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5062 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5063 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5064 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5065 "notify-lease-duration", sub
->lease
);
5067 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5068 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5069 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5070 "notify-recipient-uri", NULL
, sub
->recipient
);
5071 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5072 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5073 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5074 "notify-pull-method", NULL
, "ippget");
5076 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5077 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5078 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5079 "notify-subscriber-user-name", NULL
, sub
->owner
);
5081 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5082 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5083 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5084 "notify-time-interval", sub
->interval
);
5086 if (sub
->user_data_len
> 0 &&
5087 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5088 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5089 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5090 sub
->user_data
, sub
->user_data_len
);
5093 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5094 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5095 "notify-job-id", sub
->job
->id
);
5097 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5099 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5100 "ipp", NULL
, con
->clientname
, con
->clientport
,
5101 "/printers/%s", sub
->dest
->name
);
5102 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5103 "notify-printer-uri", NULL
, printer_uri
);
5106 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5107 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5108 "notify-subscription-id", sub
->id
);
5113 * 'create_job()' - Print a file to a printer or class.
5117 create_job(cupsd_client_t
*con
, /* I - Client connection */
5118 ipp_attribute_t
*uri
) /* I - Printer URI */
5120 int i
; /* Looping var */
5121 cupsd_printer_t
*printer
; /* Printer */
5122 cupsd_job_t
*job
; /* New job */
5123 static const char * const forbidden_attrs
[] =
5124 { /* List of forbidden attributes */
5128 "document-natural-language"
5132 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5133 con
->number
, uri
->values
[0].string
.text
);
5136 * Is the destination valid?
5139 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5145 send_ipp_status(con
, IPP_NOT_FOUND
,
5146 _("The printer or class does not exist."));
5151 * Check for invalid Create-Job attributes and log a warning or error depending
5152 * on whether cupsd is running in "strict conformance" mode...
5156 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5158 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5160 if (StrictConformance
)
5162 send_ipp_status(con
, IPP_BAD_REQUEST
,
5163 _("The '%s' operation attribute cannot be supplied in a "
5164 "Create-Job request."), forbidden_attrs
[i
]);
5168 cupsdLogMessage(CUPSD_LOG_WARN
,
5169 "Unexpected '%s' operation attribute in a Create-Job "
5170 "request.", forbidden_attrs
[i
]);
5174 * Create the job object...
5177 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5180 job
->pending_timeout
= 1;
5183 * Save and log the job...
5186 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5187 job
->dest
, job
->username
);
5192 * 'create_requested_array()' - Create an array for the requested-attributes.
5195 static cups_array_t
* /* O - Array of attributes or NULL */
5196 create_requested_array(ipp_t
*request
) /* I - IPP request */
5198 cups_array_t
*ra
; /* Requested attributes array */
5202 * Create the array for standard attributes...
5205 ra
= ippCreateRequestedArray(request
);
5208 * Add CUPS defaults as needed...
5211 if (cupsArrayFind(ra
, "printer-defaults"))
5214 * Include user-set defaults...
5217 char *name
; /* Option name */
5219 cupsArrayRemove(ra
, "printer-defaults");
5221 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5223 name
= (char *)cupsArrayNext(CommonDefaults
))
5224 if (!cupsArrayFind(ra
, name
))
5225 cupsArrayAdd(ra
, name
);
5233 * 'create_subscriptions()' - Create one or more notification subscriptions.
5237 create_subscriptions(
5238 cupsd_client_t
*con
, /* I - Client connection */
5239 ipp_attribute_t
*uri
) /* I - Printer URI */
5241 http_status_t status
; /* Policy status */
5242 int i
; /* Looping var */
5243 ipp_attribute_t
*attr
; /* Current attribute */
5244 cups_ptype_t dtype
; /* Destination type (printer/class) */
5245 char scheme
[HTTP_MAX_URI
],
5246 /* Scheme portion of URI */
5247 userpass
[HTTP_MAX_URI
],
5248 /* Username portion of URI */
5250 /* Host portion of URI */
5251 resource
[HTTP_MAX_URI
];
5252 /* Resource portion of URI */
5253 int port
; /* Port portion of URI */
5254 cupsd_printer_t
*printer
; /* Printer/class */
5255 cupsd_job_t
*job
; /* Job */
5256 int jobid
; /* Job ID */
5257 cupsd_subscription_t
*sub
; /* Subscription object */
5258 const char *username
, /* requesting-user-name or
5259 authenticated username */
5260 *recipient
, /* notify-recipient-uri */
5261 *pullmethod
; /* notify-pull-method */
5262 ipp_attribute_t
*user_data
; /* notify-user-data */
5263 int interval
, /* notify-time-interval */
5264 lease
; /* notify-lease-duration */
5265 unsigned mask
; /* notify-events */
5266 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5267 *notify_lease
; /* notify-lease-duration(-default) */
5271 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5273 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5274 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5275 attr
->value_tag
, attr
->name
);
5277 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5282 * Is the destination valid?
5285 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5287 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5288 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5289 sizeof(host
), &port
, resource
, sizeof(resource
));
5291 if (!strcmp(resource
, "/"))
5293 dtype
= (cups_ptype_t
)0;
5296 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5298 dtype
= (cups_ptype_t
)0;
5301 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5303 dtype
= CUPS_PRINTER_CLASS
;
5306 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5312 send_ipp_status(con
, IPP_NOT_FOUND
,
5313 _("The printer or class does not exist."));
5323 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5326 send_http_error(con
, status
, printer
);
5330 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5332 send_http_error(con
, status
, NULL
);
5337 * Get the user that is requesting the subscription...
5340 username
= get_username(con
);
5343 * Find the first subscription group attribute; return if we have
5347 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5348 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5353 send_ipp_status(con
, IPP_BAD_REQUEST
,
5354 _("No subscription attributes in request."));
5359 * Process the subscription attributes in the request...
5362 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5370 lease
= DefaultLeaseDuration
;
5372 mask
= CUPSD_EVENT_NONE
;
5376 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5378 notify_lease
= ippFindAttribute(printer
->attrs
,
5379 "notify-lease-duration-default",
5383 lease
= notify_lease
->values
[0].integer
;
5387 notify_events
= NULL
;
5388 notify_lease
= NULL
;
5391 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5393 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5394 attr
->value_tag
== IPP_TAG_URI
)
5397 * Validate the recipient scheme against the ServerBin/notifier
5401 char notifier
[1024]; /* Notifier filename */
5404 recipient
= attr
->values
[0].string
.text
;
5406 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5407 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5408 host
, sizeof(host
), &port
,
5409 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5411 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5412 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5413 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5414 "notify-status-code", IPP_URI_SCHEME
);
5418 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5420 if (access(notifier
, X_OK
))
5422 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5423 _("notify-recipient-uri URI \"%s\" uses unknown "
5424 "scheme."), recipient
);
5425 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5426 "notify-status-code", IPP_URI_SCHEME
);
5430 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5432 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5433 _("notify-recipient-uri URI \"%s\" is already used."),
5435 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5436 "notify-status-code", IPP_ATTRIBUTES
);
5440 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5441 attr
->value_tag
== IPP_TAG_KEYWORD
)
5443 pullmethod
= attr
->values
[0].string
.text
;
5445 if (strcmp(pullmethod
, "ippget"))
5447 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5448 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5449 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5450 "notify-status-code", IPP_ATTRIBUTES
);
5454 else if (!strcmp(attr
->name
, "notify-charset") &&
5455 attr
->value_tag
== IPP_TAG_CHARSET
&&
5456 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5457 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5459 send_ipp_status(con
, IPP_CHARSET
,
5460 _("Character set \"%s\" not supported."),
5461 attr
->values
[0].string
.text
);
5464 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5465 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5466 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5468 send_ipp_status(con
, IPP_CHARSET
,
5469 _("Language \"%s\" not supported."),
5470 attr
->values
[0].string
.text
);
5473 else if (!strcmp(attr
->name
, "notify-user-data") &&
5474 attr
->value_tag
== IPP_TAG_STRING
)
5476 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5478 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5479 _("The notify-user-data value is too large "
5480 "(%d > 63 octets)."),
5481 attr
->values
[0].unknown
.length
);
5487 else if (!strcmp(attr
->name
, "notify-events") &&
5488 attr
->value_tag
== IPP_TAG_KEYWORD
)
5489 notify_events
= attr
;
5490 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5491 attr
->value_tag
== IPP_TAG_INTEGER
)
5492 lease
= attr
->values
[0].integer
;
5493 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5494 attr
->value_tag
== IPP_TAG_INTEGER
)
5495 interval
= attr
->values
[0].integer
;
5496 else if (!strcmp(attr
->name
, "notify-job-id") &&
5497 attr
->value_tag
== IPP_TAG_INTEGER
)
5498 jobid
= attr
->values
[0].integer
;
5505 for (i
= 0; i
< notify_events
->num_values
; i
++)
5506 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5510 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5512 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5513 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5514 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5516 if (!recipient
&& !pullmethod
)
5519 if (mask
== CUPSD_EVENT_NONE
)
5522 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5524 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5527 send_ipp_status(con
, IPP_BAD_REQUEST
,
5528 _("notify-events not specified."));
5533 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5535 cupsdLogMessage(CUPSD_LOG_INFO
,
5536 "create_subscriptions: Limiting notify-lease-duration to "
5539 lease
= MaxLeaseDuration
;
5544 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5546 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5554 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5556 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5557 _("There are too many subscriptions."));
5562 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5565 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5566 "Added subscription #%d for printer \"%s\".",
5567 sub
->id
, printer
->name
);
5569 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5572 sub
->interval
= interval
;
5574 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5576 cupsdSetString(&sub
->owner
, username
);
5580 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5581 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5582 (size_t)sub
->user_data_len
);
5585 ippAddSeparator(con
->response
);
5586 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5587 "notify-subscription-id", sub
->id
);
5589 con
->response
->request
.status
.status_code
= IPP_OK
;
5595 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5600 * 'delete_printer()' - Remove a printer or class from the system.
5604 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5605 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5607 http_status_t status
; /* Policy status */
5608 cups_ptype_t dtype
; /* Destination type (printer/class) */
5609 cupsd_printer_t
*printer
; /* Printer/class */
5610 char filename
[1024]; /* Script/PPD filename */
5613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5614 con
->number
, uri
->values
[0].string
.text
);
5617 * Do we have a valid URI?
5620 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5626 send_ipp_status(con
, IPP_NOT_FOUND
,
5627 _("The printer or class does not exist."));
5635 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5637 send_http_error(con
, status
, NULL
);
5642 * Remove old jobs...
5645 cupsdCancelJobs(printer
->name
, NULL
, 1);
5648 * Remove old subscriptions and send a "deleted printer" event...
5651 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5652 "%s \"%s\" deleted by \"%s\".",
5653 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5654 printer
->name
, get_username(con
));
5656 cupsdExpireSubscriptions(printer
, NULL
);
5659 * Remove any old PPD or script files...
5662 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5665 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
5669 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
5672 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
5676 * Unregister color profiles...
5679 cupsdUnregisterColor(printer
);
5681 if (dtype
& CUPS_PRINTER_CLASS
)
5683 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5684 printer
->name
, get_username(con
));
5686 cupsdDeletePrinter(printer
, 0);
5687 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5691 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5692 printer
->name
, get_username(con
));
5694 if (cupsdDeletePrinter(printer
, 0))
5695 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
5697 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
5700 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
5703 * Return with no errors...
5706 con
->response
->request
.status
.status_code
= IPP_OK
;
5711 * 'get_default()' - Get the default destination.
5715 get_default(cupsd_client_t
*con
) /* I - Client connection */
5717 http_status_t status
; /* Policy status */
5718 cups_array_t
*ra
; /* Requested attributes array */
5721 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
5727 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5729 send_http_error(con
, status
, NULL
);
5735 ra
= create_requested_array(con
->request
);
5737 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5739 cupsArrayDelete(ra
);
5741 con
->response
->request
.status
.status_code
= IPP_OK
;
5744 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
5749 * 'get_devices()' - Get the list of available devices on the local system.
5753 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5755 http_status_t status
; /* Policy status */
5756 ipp_attribute_t
*limit
, /* limit attribute */
5757 *timeout
, /* timeout attribute */
5758 *requested
, /* requested-attributes attribute */
5759 *exclude
, /* exclude-schemes attribute */
5760 *include
; /* include-schemes attribute */
5761 char command
[1024], /* cups-deviced command */
5762 options
[2048], /* Options to pass to command */
5764 /* String for requested attributes */
5766 /* String for excluded schemes */
5768 /* String for included schemes */
5771 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
5777 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5779 send_http_error(con
, status
, NULL
);
5784 * Run cups-deviced command with the given options...
5787 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5788 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
5789 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5791 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
5792 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
5795 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5797 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5800 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
5802 exclude_str
[0] = '\0';
5805 url_encode_attr(include
, include_str
, sizeof(include_str
));
5807 include_str
[0] = '\0';
5809 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5810 snprintf(options
, sizeof(options
),
5811 "%d+%d+%d+%d+%s%s%s%s%s",
5812 con
->request
->request
.op
.request_id
,
5813 limit
? limit
->values
[0].integer
: 0,
5814 timeout
? timeout
->values
[0].integer
: 15,
5817 exclude_str
[0] ? "%20" : "", exclude_str
,
5818 include_str
[0] ? "%20" : "", include_str
);
5820 if (cupsdSendCommand(con
, command
, options
, 1))
5823 * Command started successfully, don't send an IPP response here...
5826 ippDelete(con
->response
);
5827 con
->response
= NULL
;
5832 * Command failed, return "internal error" so the user knows something
5836 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5837 _("cups-deviced failed to execute."));
5843 * 'get_document()' - Get a copy of a job file.
5847 get_document(cupsd_client_t
*con
, /* I - Client connection */
5848 ipp_attribute_t
*uri
) /* I - Job URI */
5850 http_status_t status
; /* Policy status */
5851 ipp_attribute_t
*attr
; /* Current attribute */
5852 int jobid
; /* Job ID */
5853 int docnum
; /* Document number */
5854 cupsd_job_t
*job
; /* Current job */
5855 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
5856 username
[HTTP_MAX_URI
], /* Username portion of URI */
5857 host
[HTTP_MAX_URI
], /* Host portion of URI */
5858 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5859 int port
; /* Port portion of URI */
5860 char filename
[1024], /* Filename for document */
5861 format
[1024]; /* Format for document */
5864 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
5865 con
->number
, uri
->values
[0].string
.text
);
5868 * See if we have a job URI or a printer URI...
5871 if (!strcmp(uri
->name
, "printer-uri"))
5874 * Got a printer URI; see if we also have a job-id attribute...
5877 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5878 IPP_TAG_INTEGER
)) == NULL
)
5880 send_ipp_status(con
, IPP_BAD_REQUEST
,
5881 _("Got a printer-uri attribute but no job-id."));
5885 jobid
= attr
->values
[0].integer
;
5890 * Got a job URI; parse it to get the job ID...
5893 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5894 sizeof(scheme
), username
, sizeof(username
), host
,
5895 sizeof(host
), &port
, resource
, sizeof(resource
));
5897 if (strncmp(resource
, "/jobs/", 6))
5903 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
5904 uri
->values
[0].string
.text
);
5908 jobid
= atoi(resource
+ 6);
5912 * See if the job exists...
5915 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5918 * Nope - return a "not found" error...
5921 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
5929 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
5930 job
->username
)) != HTTP_OK
)
5932 send_http_error(con
, status
, NULL
);
5937 * Get the document number...
5940 if ((attr
= ippFindAttribute(con
->request
, "document-number",
5941 IPP_TAG_INTEGER
)) == NULL
)
5943 send_ipp_status(con
, IPP_BAD_REQUEST
,
5944 _("Missing document-number attribute."));
5948 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
5949 attr
->num_values
> 1)
5951 send_ipp_status(con
, IPP_NOT_FOUND
,
5952 _("Document #%d does not exist in job #%d."), docnum
,
5957 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
5959 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
5961 cupsdLogMessage(CUPSD_LOG_ERROR
,
5962 "Unable to open document %d in job %d - %s", docnum
, jobid
,
5964 send_ipp_status(con
, IPP_NOT_FOUND
,
5965 _("Unable to open document #%d in job #%d."), docnum
,
5970 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
5974 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
5975 job
->filetypes
[docnum
- 1]->type
);
5977 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
5979 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
5981 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
5982 IPP_TAG_NAME
)) != NULL
)
5983 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
5984 NULL
, attr
->values
[0].string
.text
);
5989 * 'get_job_attrs()' - Get job attributes.
5993 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5994 ipp_attribute_t
*uri
) /* I - Job URI */
5996 http_status_t status
; /* Policy status */
5997 ipp_attribute_t
*attr
; /* Current attribute */
5998 int jobid
; /* Job ID */
5999 cupsd_job_t
*job
; /* Current job */
6000 cupsd_printer_t
*printer
; /* Current printer */
6001 cupsd_policy_t
*policy
; /* Current security policy */
6002 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6003 username
[HTTP_MAX_URI
], /* Username portion of URI */
6004 host
[HTTP_MAX_URI
], /* Host portion of URI */
6005 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6006 int port
; /* Port portion of URI */
6007 cups_array_t
*ra
, /* Requested attributes array */
6008 *exclude
; /* Private attributes array */
6011 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6012 con
->number
, uri
->values
[0].string
.text
);
6015 * See if we have a job URI or a printer URI...
6018 if (!strcmp(uri
->name
, "printer-uri"))
6021 * Got a printer URI; see if we also have a job-id attribute...
6024 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6025 IPP_TAG_INTEGER
)) == NULL
)
6027 send_ipp_status(con
, IPP_BAD_REQUEST
,
6028 _("Got a printer-uri attribute but no job-id."));
6032 jobid
= attr
->values
[0].integer
;
6037 * Got a job URI; parse it to get the job ID...
6040 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6041 sizeof(scheme
), username
, sizeof(username
), host
,
6042 sizeof(host
), &port
, resource
, sizeof(resource
));
6044 if (strncmp(resource
, "/jobs/", 6))
6050 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6051 uri
->values
[0].string
.text
);
6055 jobid
= atoi(resource
+ 6);
6059 * See if the job exists...
6062 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6065 * Nope - return a "not found" error...
6068 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6076 if ((printer
= job
->printer
) == NULL
)
6077 printer
= cupsdFindDest(job
->dest
);
6080 policy
= printer
->op_policy_ptr
;
6082 policy
= DefaultPolicyPtr
;
6084 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6086 send_http_error(con
, status
, NULL
);
6090 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6093 * Copy attributes...
6098 ra
= create_requested_array(con
->request
);
6099 copy_job_attrs(con
, job
, ra
, exclude
);
6100 cupsArrayDelete(ra
);
6102 con
->response
->request
.status
.status_code
= IPP_OK
;
6107 * 'get_jobs()' - Get a list of jobs for the specified printer.
6111 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6112 ipp_attribute_t
*uri
) /* I - Printer URI */
6114 http_status_t status
; /* Policy status */
6115 ipp_attribute_t
*attr
; /* Current attribute */
6116 const char *dest
; /* Destination */
6117 cups_ptype_t dtype
; /* Destination type (printer/class) */
6118 cups_ptype_t dmask
; /* Destination type mask */
6119 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6120 username
[HTTP_MAX_URI
], /* Username portion of URI */
6121 host
[HTTP_MAX_URI
], /* Host portion of URI */
6122 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6123 int port
; /* Port portion of URI */
6124 int job_comparison
; /* Job comparison */
6125 ipp_jstate_t job_state
; /* job-state value */
6126 int first_job_id
= 1, /* First job ID */
6127 first_index
= 1, /* First index */
6128 current_index
= 0; /* Current index */
6129 int limit
= 0; /* Maximum number of jobs to return */
6130 int count
; /* Number of jobs that match */
6131 int need_load_job
= 0; /* Do we need to load the job? */
6132 const char *job_attr
; /* Job attribute requested */
6133 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6134 cupsd_job_t
*job
; /* Current job pointer */
6135 cupsd_printer_t
*printer
; /* Printer */
6136 cups_array_t
*list
; /* Which job list... */
6137 int delete_list
= 0; /* Delete the list afterwards? */
6138 cups_array_t
*ra
, /* Requested attributes array */
6139 *exclude
; /* Private attributes array */
6140 cupsd_policy_t
*policy
; /* Current policy */
6143 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6144 uri
->values
[0].string
.text
);
6147 * Is the destination valid?
6150 if (strcmp(uri
->name
, "printer-uri"))
6152 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6156 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6157 sizeof(scheme
), username
, sizeof(username
), host
,
6158 sizeof(host
), &port
, resource
, sizeof(resource
));
6160 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6163 dtype
= (cups_ptype_t
)0;
6164 dmask
= (cups_ptype_t
)0;
6167 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6170 dtype
= (cups_ptype_t
)0;
6171 dmask
= CUPS_PRINTER_CLASS
;
6174 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6177 dtype
= CUPS_PRINTER_CLASS
;
6178 dmask
= CUPS_PRINTER_CLASS
;
6181 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6188 send_ipp_status(con
, IPP_NOT_FOUND
,
6189 _("The printer or class does not exist."));
6194 dtype
&= CUPS_PRINTER_CLASS
;
6195 dmask
= CUPS_PRINTER_CLASS
;
6203 policy
= printer
->op_policy_ptr
;
6205 policy
= DefaultPolicyPtr
;
6207 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6209 send_http_error(con
, status
, NULL
);
6213 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6216 * See if the "which-jobs" attribute have been specified...
6219 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6220 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6222 send_ipp_status(con
, IPP_CONFLICT
,
6223 _("The %s attribute cannot be provided with job-ids."),
6227 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6229 job_comparison
= -1;
6230 job_state
= IPP_JOB_STOPPED
;
6233 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6236 job_state
= IPP_JOB_CANCELED
;
6237 list
= cupsdGetCompletedJobs(printer
);
6240 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6243 job_state
= IPP_JOB_ABORTED
;
6244 list
= cupsdGetCompletedJobs(printer
);
6247 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6250 job_state
= IPP_JOB_PENDING
;
6253 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6256 job_state
= IPP_JOB_CANCELED
;
6257 list
= cupsdGetCompletedJobs(printer
);
6260 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6263 job_state
= IPP_JOB_PENDING
;
6266 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6269 job_state
= IPP_JOB_HELD
;
6272 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6275 job_state
= IPP_JOB_PROCESSING
;
6276 list
= PrintingJobs
;
6278 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6281 job_state
= IPP_JOB_STOPPED
;
6286 send_ipp_status(con
, IPP_ATTRIBUTES
,
6287 _("The which-jobs value \"%s\" is not supported."),
6288 attr
->values
[0].string
.text
);
6289 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6290 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6295 * See if they want to limit the number of jobs reported...
6298 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6302 send_ipp_status(con
, IPP_CONFLICT
,
6303 _("The %s attribute cannot be provided with job-ids."),
6308 limit
= attr
->values
[0].integer
;
6311 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6315 send_ipp_status(con
, IPP_CONFLICT
,
6316 _("The %s attribute cannot be provided with job-ids."),
6321 first_index
= attr
->values
[0].integer
;
6323 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6327 send_ipp_status(con
, IPP_CONFLICT
,
6328 _("The %s attribute cannot be provided with job-ids."),
6333 first_job_id
= attr
->values
[0].integer
;
6337 * See if we only want to see jobs for a specific user...
6340 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6342 send_ipp_status(con
, IPP_CONFLICT
,
6343 _("The %s attribute cannot be provided with job-ids."),
6347 else if (attr
&& attr
->values
[0].boolean
)
6348 strlcpy(username
, get_username(con
), sizeof(username
));
6352 ra
= create_requested_array(con
->request
);
6353 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6354 if (strcmp(job_attr
, "job-id") &&
6355 strcmp(job_attr
, "job-k-octets") &&
6356 strcmp(job_attr
, "job-media-progress") &&
6357 strcmp(job_attr
, "job-more-info") &&
6358 strcmp(job_attr
, "job-name") &&
6359 strcmp(job_attr
, "job-originating-user-name") &&
6360 strcmp(job_attr
, "job-preserved") &&
6361 strcmp(job_attr
, "job-printer-up-time") &&
6362 strcmp(job_attr
, "job-printer-uri") &&
6363 strcmp(job_attr
, "job-state") &&
6364 strcmp(job_attr
, "job-state-reasons") &&
6365 strcmp(job_attr
, "job-uri") &&
6366 strcmp(job_attr
, "time-at-completed") &&
6367 strcmp(job_attr
, "time-at-creation") &&
6368 strcmp(job_attr
, "number-of-documents"))
6374 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6377 * Limit expensive Get-Jobs for job history to 500 jobs...
6380 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6383 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6387 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6391 * OK, build a list of jobs for this printer...
6396 int i
; /* Looping var */
6398 for (i
= 0; i
< job_ids
->num_values
; i
++)
6400 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6404 if (i
< job_ids
->num_values
)
6406 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6407 job_ids
->values
[i
].integer
);
6411 for (i
= 0; i
< job_ids
->num_values
; i
++)
6413 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6415 if (need_load_job
&& !job
->attrs
)
6421 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6427 ippAddSeparator(con
->response
);
6429 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6430 job
->printer
->op_policy_ptr
:
6431 policy
, con
, job
->printer
,
6434 copy_job_attrs(con
, job
, ra
, exclude
);
6439 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6440 (limit
<= 0 || count
< limit
) && job
;
6441 job
= (cupsd_job_t
*)cupsArrayNext(list
))
6444 * Filter out jobs that don't match...
6447 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6448 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6449 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6450 job
->username
, job
->state_value
, job
->attrs
);
6452 if (!job
->dest
|| !job
->username
)
6455 if (!job
->dest
|| !job
->username
)
6458 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6459 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6461 if ((job
->dtype
& dmask
) != dtype
&&
6462 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6465 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6466 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6467 (job_comparison
> 0 && job
->state_value
< job_state
))
6470 if (job
->id
< first_job_id
)
6474 if (current_index
< first_index
)
6477 if (need_load_job
&& !job
->attrs
)
6483 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6488 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6492 ippAddSeparator(con
->response
);
6496 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6497 job
->printer
->op_policy_ptr
:
6498 policy
, con
, job
->printer
,
6501 copy_job_attrs(con
, job
, ra
, exclude
);
6504 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6507 cupsArrayDelete(ra
);
6510 cupsArrayDelete(list
);
6512 con
->response
->request
.status
.status_code
= IPP_OK
;
6517 * 'get_notifications()' - Get events for a subscription.
6521 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6523 int i
, j
; /* Looping vars */
6524 http_status_t status
; /* Policy status */
6525 cupsd_subscription_t
*sub
; /* Subscription */
6526 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6527 *sequences
; /* notify-sequence-numbers */
6528 int min_seq
; /* Minimum sequence number */
6529 int interval
; /* Poll interval */
6532 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6536 * Get subscription attributes...
6539 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6541 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6546 send_ipp_status(con
, IPP_BAD_REQUEST
,
6547 _("Missing notify-subscription-ids attribute."));
6552 * Are the subscription IDs valid?
6555 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6557 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6560 * Bad subscription ID...
6563 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6564 ids
->values
[i
].integer
);
6572 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6574 con
, sub
->owner
)) != HTTP_OK
)
6576 send_http_error(con
, status
, sub
->dest
);
6581 * Check the subscription type and update the interval accordingly.
6584 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6587 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6589 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6595 * Tell the client to poll again in N seconds...
6599 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6600 "notify-get-interval", interval
);
6602 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6603 "printer-up-time", time(NULL
));
6606 * Copy the subscription event attributes to the response.
6609 con
->response
->request
.status
.status_code
=
6610 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6612 for (i
= 0; i
< ids
->num_values
; i
++)
6615 * Get the subscription and sequence number...
6618 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6620 if (sequences
&& i
< sequences
->num_values
)
6621 min_seq
= sequences
->values
[i
].integer
;
6626 * If we don't have any new events, nothing to do here...
6629 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6633 * Otherwise copy all of the new events...
6636 if (sub
->first_event_id
> min_seq
)
6639 j
= min_seq
- sub
->first_event_id
;
6641 for (; j
< cupsArrayCount(sub
->events
); j
++)
6643 ippAddSeparator(con
->response
);
6645 copy_attrs(con
->response
,
6646 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
6647 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
6654 * 'get_ppd()' - Get a named PPD from the local system.
6658 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
6659 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
6661 http_status_t status
; /* Policy status */
6662 cupsd_printer_t
*dest
; /* Destination */
6663 cups_ptype_t dtype
; /* Destination type */
6666 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
6667 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
6669 if (!strcmp(ippGetName(uri
), "ppd-name"))
6672 * Return a PPD file from cups-driverd...
6675 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
6676 /* ppd-name value */
6677 char command
[1024], /* cups-driverd command */
6678 options
[1024], /* Options to pass to command */
6679 oppd_name
[1024]; /* Escaped ppd-name */
6685 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6687 send_http_error(con
, status
, NULL
);
6692 * Check ppd-name value...
6695 if (strstr(ppd_name
, "../"))
6697 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
6702 * Run cups-driverd command with the given options...
6705 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6706 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
6707 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
6709 if (cupsdSendCommand(con
, command
, options
, 0))
6712 * Command started successfully, don't send an IPP response here...
6715 ippDelete(con
->response
);
6716 con
->response
= NULL
;
6721 * Command failed, return "internal error" so the user knows something
6725 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
6728 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
6730 int i
; /* Looping var */
6731 char filename
[1024]; /* PPD filename */
6737 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6739 send_http_error(con
, status
, dest
);
6744 * See if we need the PPD for a class or remote printer...
6747 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
6749 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
6751 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
6752 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
6755 else if (dtype
& CUPS_PRINTER_CLASS
)
6757 for (i
= 0; i
< dest
->num_printers
; i
++)
6758 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
6760 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
6762 if (!access(filename
, 0))
6766 if (i
< dest
->num_printers
)
6767 dest
= dest
->printers
[i
];
6770 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
6771 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
6777 * Found the printer with the PPD file, now see if there is one...
6780 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
6782 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
6786 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6790 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
6793 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
6798 * 'get_ppds()' - Get the list of PPD files on the local system.
6802 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
6804 http_status_t status
; /* Policy status */
6805 ipp_attribute_t
*limit
, /* Limit attribute */
6806 *device
, /* ppd-device-id attribute */
6807 *language
, /* ppd-natural-language attribute */
6808 *make
, /* ppd-make attribute */
6809 *model
, /* ppd-make-and-model attribute */
6810 *model_number
, /* ppd-model-number attribute */
6811 *product
, /* ppd-product attribute */
6812 *psversion
, /* ppd-psverion attribute */
6813 *type
, /* ppd-type attribute */
6814 *requested
, /* requested-attributes attribute */
6815 *exclude
, /* exclude-schemes attribute */
6816 *include
; /* include-schemes attribute */
6817 char command
[1024], /* cups-driverd command */
6818 options
[4096], /* Options to pass to command */
6819 device_str
[256],/* Escaped ppd-device-id string */
6821 /* Escaped ppd-natural-language */
6822 make_str
[256], /* Escaped ppd-make string */
6823 model_str
[256], /* Escaped ppd-make-and-model string */
6824 model_number_str
[256],
6825 /* ppd-model-number string */
6827 /* Escaped ppd-product string */
6829 /* Escaped ppd-psversion string */
6830 type_str
[256], /* Escaped ppd-type string */
6832 /* String for requested attributes */
6834 /* String for excluded schemes */
6836 /* String for included schemes */
6839 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
6845 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6847 send_http_error(con
, status
, NULL
);
6852 * Run cups-driverd command with the given options...
6855 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6856 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
6857 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
6859 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
6860 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
6862 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
6864 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
6865 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
6866 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
6867 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6869 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
6871 include
= ippFindAttribute(con
->request
, "include-schemes",
6875 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6877 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6880 url_encode_attr(device
, device_str
, sizeof(device_str
));
6882 device_str
[0] = '\0';
6885 url_encode_attr(language
, language_str
, sizeof(language_str
));
6887 language_str
[0] = '\0';
6890 url_encode_attr(make
, make_str
, sizeof(make_str
));
6895 url_encode_attr(model
, model_str
, sizeof(model_str
));
6897 model_str
[0] = '\0';
6900 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
6901 model_number
->values
[0].integer
);
6903 model_number_str
[0] = '\0';
6906 url_encode_attr(product
, product_str
, sizeof(product_str
));
6908 product_str
[0] = '\0';
6911 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
6913 psversion_str
[0] = '\0';
6916 url_encode_attr(type
, type_str
, sizeof(type_str
));
6921 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6923 exclude_str
[0] = '\0';
6926 url_encode_attr(include
, include_str
, sizeof(include_str
));
6928 include_str
[0] = '\0';
6930 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
6931 snprintf(options
, sizeof(options
),
6932 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
6933 con
->request
->request
.op
.request_id
,
6934 limit
? limit
->values
[0].integer
: 0,
6936 device
? "%20" : "", device_str
,
6937 language
? "%20" : "", language_str
,
6938 make
? "%20" : "", make_str
,
6939 model
? "%20" : "", model_str
,
6940 model_number
? "%20" : "", model_number_str
,
6941 product
? "%20" : "", product_str
,
6942 psversion
? "%20" : "", psversion_str
,
6943 type
? "%20" : "", type_str
,
6944 exclude_str
[0] ? "%20" : "", exclude_str
,
6945 include_str
[0] ? "%20" : "", include_str
);
6947 if (cupsdSendCommand(con
, command
, options
, 0))
6950 * Command started successfully, don't send an IPP response here...
6953 ippDelete(con
->response
);
6954 con
->response
= NULL
;
6959 * Command failed, return "internal error" so the user knows something
6963 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6964 _("cups-driverd failed to execute."));
6970 * 'get_printer_attrs()' - Get printer attributes.
6974 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
6975 ipp_attribute_t
*uri
) /* I - Printer URI */
6977 http_status_t status
; /* Policy status */
6978 cups_ptype_t dtype
; /* Destination type (printer/class) */
6979 cupsd_printer_t
*printer
; /* Printer/class */
6980 cups_array_t
*ra
; /* Requested attributes array */
6983 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
6984 con
->number
, uri
->values
[0].string
.text
);
6987 * Is the destination valid?
6990 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6996 send_ipp_status(con
, IPP_NOT_FOUND
,
6997 _("The printer or class does not exist."));
7005 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7007 send_http_error(con
, status
, printer
);
7012 * Send the attributes...
7015 ra
= create_requested_array(con
->request
);
7017 copy_printer_attrs(con
, printer
, ra
);
7019 cupsArrayDelete(ra
);
7021 con
->response
->request
.status
.status_code
= IPP_OK
;
7026 * 'get_printer_supported()' - Get printer supported values.
7030 get_printer_supported(
7031 cupsd_client_t
*con
, /* I - Client connection */
7032 ipp_attribute_t
*uri
) /* I - Printer URI */
7034 http_status_t status
; /* Policy status */
7035 cups_ptype_t dtype
; /* Destination type (printer/class) */
7036 cupsd_printer_t
*printer
; /* Printer/class */
7039 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7040 con
->number
, uri
->values
[0].string
.text
);
7043 * Is the destination valid?
7046 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7052 send_ipp_status(con
, IPP_NOT_FOUND
,
7053 _("The printer or class does not exist."));
7061 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7063 send_http_error(con
, status
, printer
);
7068 * Return a list of attributes that can be set via Set-Printer-Attributes.
7071 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7072 "printer-geo-location", 0);
7073 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7075 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7076 "printer-location", 0);
7077 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7078 "printer-organization", 0);
7079 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7080 "printer-organizational-unit", 0);
7082 con
->response
->request
.status
.status_code
= IPP_OK
;
7087 * 'get_printers()' - Get a list of printers or classes.
7091 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7092 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7094 http_status_t status
; /* Policy status */
7095 ipp_attribute_t
*attr
; /* Current attribute */
7096 int limit
; /* Max number of printers to return */
7097 int count
; /* Number of printers that match */
7098 cupsd_printer_t
*printer
; /* Current printer pointer */
7099 cups_ptype_t printer_type
, /* printer-type attribute */
7100 printer_mask
; /* printer-type-mask attribute */
7101 char *location
; /* Location string */
7102 const char *username
; /* Current user */
7103 char *first_printer_name
; /* first-printer-name attribute */
7104 cups_array_t
*ra
; /* Requested attributes array */
7105 int local
; /* Local connection? */
7108 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7115 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7117 send_http_error(con
, status
, NULL
);
7122 * Check for printers...
7125 if (!Printers
|| !cupsArrayCount(Printers
))
7127 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7132 * See if they want to limit the number of printers reported...
7135 if ((attr
= ippFindAttribute(con
->request
, "limit",
7136 IPP_TAG_INTEGER
)) != NULL
)
7137 limit
= attr
->values
[0].integer
;
7141 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7142 IPP_TAG_NAME
)) != NULL
)
7143 first_printer_name
= attr
->values
[0].string
.text
;
7145 first_printer_name
= NULL
;
7148 * Support filtering...
7151 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7152 IPP_TAG_ENUM
)) != NULL
)
7153 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7155 printer_type
= (cups_ptype_t
)0;
7157 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7158 IPP_TAG_ENUM
)) != NULL
)
7159 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7161 printer_mask
= (cups_ptype_t
)0;
7163 local
= httpAddrLocalhost(&(con
->clientaddr
));
7165 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7166 IPP_TAG_TEXT
)) != NULL
)
7167 location
= attr
->values
[0].string
.text
;
7171 if (con
->username
[0])
7172 username
= con
->username
;
7173 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7174 IPP_TAG_NAME
)) != NULL
)
7175 username
= attr
->values
[0].string
.text
;
7179 ra
= create_requested_array(con
->request
);
7182 * OK, build a list of printers for this printer...
7185 if (first_printer_name
)
7187 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7188 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7191 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7194 count
< limit
&& printer
;
7195 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7197 if (!local
&& !printer
->shared
)
7200 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7201 (printer
->type
& printer_mask
) == printer_type
&&
7203 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7206 * If a username is specified, see if it is allowed or denied
7210 if (cupsArrayCount(printer
->users
) && username
&&
7211 !user_allowed(printer
, username
))
7215 * Add the group separator as needed...
7219 ippAddSeparator(con
->response
);
7224 * Send the attributes...
7227 copy_printer_attrs(con
, printer
, ra
);
7231 cupsArrayDelete(ra
);
7233 con
->response
->request
.status
.status_code
= IPP_OK
;
7238 * 'get_subscription_attrs()' - Get subscription attributes.
7242 get_subscription_attrs(
7243 cupsd_client_t
*con
, /* I - Client connection */
7244 int sub_id
) /* I - Subscription ID */
7246 http_status_t status
; /* Policy status */
7247 cupsd_subscription_t
*sub
; /* Subscription */
7248 cupsd_policy_t
*policy
; /* Current security policy */
7249 cups_array_t
*ra
, /* Requested attributes array */
7250 *exclude
; /* Private attributes array */
7253 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7254 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7255 con
, con
->number
, sub_id
);
7258 * Is the subscription ID valid?
7261 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7264 * Bad subscription ID...
7267 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7277 policy
= sub
->dest
->op_policy_ptr
;
7279 policy
= DefaultPolicyPtr
;
7281 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7283 send_http_error(con
, status
, sub
->dest
);
7287 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7290 * Copy the subscription attributes to the response using the
7291 * requested-attributes attribute that may be provided by the client.
7294 ra
= create_requested_array(con
->request
);
7296 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7298 cupsArrayDelete(ra
);
7300 con
->response
->request
.status
.status_code
= IPP_OK
;
7305 * 'get_subscriptions()' - Get subscriptions.
7309 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7310 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7312 http_status_t status
; /* Policy status */
7313 int count
; /* Number of subscriptions */
7314 int limit
; /* Limit */
7315 cupsd_subscription_t
*sub
; /* Subscription */
7316 cups_array_t
*ra
; /* Requested attributes array */
7317 ipp_attribute_t
*attr
; /* Attribute */
7318 cups_ptype_t dtype
; /* Destination type (printer/class) */
7319 char scheme
[HTTP_MAX_URI
],
7320 /* Scheme portion of URI */
7321 username
[HTTP_MAX_URI
],
7322 /* Username portion of URI */
7324 /* Host portion of URI */
7325 resource
[HTTP_MAX_URI
];
7326 /* Resource portion of URI */
7327 int port
; /* Port portion of URI */
7328 cupsd_job_t
*job
; /* Job pointer */
7329 cupsd_printer_t
*printer
; /* Printer */
7330 cupsd_policy_t
*policy
; /* Policy */
7331 cups_array_t
*exclude
; /* Private attributes array */
7334 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7335 "get_subscriptions(con=%p[%d], uri=%s)",
7336 con
, con
->number
, uri
->values
[0].string
.text
);
7339 * Is the destination valid?
7342 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7343 sizeof(scheme
), username
, sizeof(username
), host
,
7344 sizeof(host
), &port
, resource
, sizeof(resource
));
7346 if (!strcmp(resource
, "/") ||
7347 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7348 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7349 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7354 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7357 job
= cupsdFindJob(atoi(resource
+ 6));
7361 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7362 atoi(resource
+ 6));
7366 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7372 send_ipp_status(con
, IPP_NOT_FOUND
,
7373 _("The printer or class does not exist."));
7376 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7377 IPP_TAG_INTEGER
)) != NULL
)
7379 job
= cupsdFindJob(attr
->values
[0].integer
);
7383 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7384 attr
->values
[0].integer
);
7396 policy
= printer
->op_policy_ptr
;
7398 policy
= DefaultPolicyPtr
;
7400 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7402 send_http_error(con
, status
, printer
);
7407 * Copy the subscription attributes to the response using the
7408 * requested-attributes attribute that may be provided by the client.
7411 ra
= create_requested_array(con
->request
);
7413 if ((attr
= ippFindAttribute(con
->request
, "limit",
7414 IPP_TAG_INTEGER
)) != NULL
)
7415 limit
= attr
->values
[0].integer
;
7420 * See if we only want to see subscriptions for a specific user...
7423 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7424 IPP_TAG_BOOLEAN
)) != NULL
&&
7425 attr
->values
[0].boolean
)
7426 strlcpy(username
, get_username(con
), sizeof(username
));
7430 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7432 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7433 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7434 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7436 ippAddSeparator(con
->response
);
7438 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7439 policy
, con
, sub
->dest
,
7442 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7445 if (limit
&& count
>= limit
)
7449 cupsArrayDelete(ra
);
7452 con
->response
->request
.status
.status_code
= IPP_OK
;
7454 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7459 * 'get_username()' - Get the username associated with a request.
7462 static const char * /* O - Username */
7463 get_username(cupsd_client_t
*con
) /* I - Connection */
7465 ipp_attribute_t
*attr
; /* Attribute */
7468 if (con
->username
[0])
7469 return (con
->username
);
7470 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7471 IPP_TAG_NAME
)) != NULL
)
7472 return (attr
->values
[0].string
.text
);
7474 return ("anonymous");
7479 * 'hold_job()' - Hold a print job.
7483 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7484 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7486 ipp_attribute_t
*attr
; /* Current job-hold-until */
7487 const char *when
; /* New value */
7488 int jobid
; /* Job ID */
7489 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7490 username
[HTTP_MAX_URI
], /* Username portion of URI */
7491 host
[HTTP_MAX_URI
], /* Host portion of URI */
7492 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7493 int port
; /* Port portion of URI */
7494 cupsd_job_t
*job
; /* Job information */
7497 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7498 uri
->values
[0].string
.text
);
7501 * See if we have a job URI or a printer URI...
7504 if (!strcmp(uri
->name
, "printer-uri"))
7507 * Got a printer URI; see if we also have a job-id attribute...
7510 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7511 IPP_TAG_INTEGER
)) == NULL
)
7513 send_ipp_status(con
, IPP_BAD_REQUEST
,
7514 _("Got a printer-uri attribute but no job-id."));
7518 jobid
= attr
->values
[0].integer
;
7523 * Got a job URI; parse it to get the job ID...
7526 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7527 sizeof(scheme
), username
, sizeof(username
), host
,
7528 sizeof(host
), &port
, resource
, sizeof(resource
));
7530 if (strncmp(resource
, "/jobs/", 6))
7536 send_ipp_status(con
, IPP_BAD_REQUEST
,
7537 _("Bad job-uri \"%s\"."),
7538 uri
->values
[0].string
.text
);
7542 jobid
= atoi(resource
+ 6);
7546 * See if the job exists...
7549 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7552 * Nope - return a "not found" error...
7555 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7560 * See if the job is owned by the requesting user...
7563 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7565 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7566 cupsdFindDest(job
->dest
));
7571 * See if the job is in a state that allows holding...
7574 if (job
->state_value
> IPP_JOB_STOPPED
)
7577 * Return a "not-possible" error...
7580 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7581 _("Job #%d is finished and cannot be altered."),
7587 * Hold the job and return...
7590 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
7591 IPP_TAG_KEYWORD
)) == NULL
)
7592 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
7596 when
= attr
->values
[0].string
.text
;
7598 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7599 "Job job-hold-until value changed by user.");
7602 when
= "indefinite";
7604 cupsdSetJobHoldUntil(job
, when
, 1);
7605 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7608 con
->response
->request
.status
.status_code
= IPP_OK
;
7613 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
7617 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
7618 ipp_attribute_t
*uri
) /* I - Printer URI */
7620 http_status_t status
; /* Policy status */
7621 cups_ptype_t dtype
; /* Destination type (printer/class) */
7622 cupsd_printer_t
*printer
; /* Printer data */
7625 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
7626 con
->number
, uri
->values
[0].string
.text
);
7629 * Is the destination valid?
7632 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7638 send_ipp_status(con
, IPP_NOT_FOUND
,
7639 _("The printer or class does not exist."));
7647 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7649 send_http_error(con
, status
, printer
);
7654 * Hold pending/new jobs sent to the printer...
7657 printer
->holding_new_jobs
= 1;
7659 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
7661 if (dtype
& CUPS_PRINTER_CLASS
)
7662 cupsdLogMessage(CUPSD_LOG_INFO
,
7663 "Class \"%s\" now holding pending/new jobs (\"%s\").",
7664 printer
->name
, get_username(con
));
7666 cupsdLogMessage(CUPSD_LOG_INFO
,
7667 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
7668 printer
->name
, get_username(con
));
7671 * Everything was ok, so return OK status...
7674 con
->response
->request
.status
.status_code
= IPP_OK
;
7679 * 'move_job()' - Move a job to a new destination.
7683 move_job(cupsd_client_t
*con
, /* I - Client connection */
7684 ipp_attribute_t
*uri
) /* I - Job URI */
7686 http_status_t status
; /* Policy status */
7687 ipp_attribute_t
*attr
; /* Current attribute */
7688 int jobid
; /* Job ID */
7689 cupsd_job_t
*job
; /* Current job */
7690 const char *src
; /* Source printer/class */
7691 cups_ptype_t stype
, /* Source type (printer or class) */
7692 dtype
; /* Destination type (printer/class) */
7693 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
7694 username
[HTTP_MAX_URI
], /* Username portion of URI */
7695 host
[HTTP_MAX_URI
], /* Host portion of URI */
7696 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7697 int port
; /* Port portion of URI */
7698 cupsd_printer_t
*sprinter
, /* Source printer */
7699 *dprinter
; /* Destination printer */
7702 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
7703 uri
->values
[0].string
.text
);
7706 * Get the new printer or class...
7709 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
7710 IPP_TAG_URI
)) == NULL
)
7713 * Need job-printer-uri...
7716 send_ipp_status(con
, IPP_BAD_REQUEST
,
7717 _("job-printer-uri attribute missing."));
7721 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
7727 send_ipp_status(con
, IPP_NOT_FOUND
,
7728 _("The printer or class does not exist."));
7733 * See if we have a job URI or a printer URI...
7736 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7737 sizeof(scheme
), username
, sizeof(username
), host
,
7738 sizeof(host
), &port
, resource
, sizeof(resource
));
7740 if (!strcmp(uri
->name
, "printer-uri"))
7743 * Got a printer URI; see if we also have a job-id attribute...
7746 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7747 IPP_TAG_INTEGER
)) == NULL
)
7753 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
7754 &sprinter
)) == NULL
)
7760 send_ipp_status(con
, IPP_NOT_FOUND
,
7761 _("The printer or class does not exist."));
7770 * Otherwise, just move a single job...
7773 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
7776 * Nope - return a "not found" error...
7779 send_ipp_status(con
, IPP_NOT_FOUND
,
7780 _("Job #%d does not exist."), attr
->values
[0].integer
);
7786 * Job found, initialize source pointers...
7797 * Got a job URI; parse it to get the job ID...
7800 if (strncmp(resource
, "/jobs/", 6))
7806 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
7807 uri
->values
[0].string
.text
);
7812 * See if the job exists...
7815 jobid
= atoi(resource
+ 6);
7817 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7820 * Nope - return a "not found" error...
7823 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7829 * Job found, initialize source pointers...
7838 * Check the policy of the destination printer...
7841 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
7842 job
? job
->username
: NULL
)) != HTTP_OK
)
7844 send_http_error(con
, status
, dprinter
);
7849 * Now move the job or jobs...
7855 * See if the job has been completed...
7858 if (job
->state_value
> IPP_JOB_STOPPED
)
7861 * Return a "not-possible" error...
7864 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7865 _("Job #%d is finished and cannot be altered."),
7871 * See if the job is owned by the requesting user...
7874 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7876 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7877 cupsdFindDest(job
->dest
));
7882 * Move the job to a different printer or class...
7885 cupsdMoveJob(job
, dprinter
);
7890 * Got the source printer, now look through the jobs...
7893 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
7895 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
7898 * See if the job is pointing at the source printer or has not been
7902 if (_cups_strcasecmp(job
->dest
, src
) ||
7903 job
->state_value
> IPP_JOB_STOPPED
)
7907 * See if the job can be moved by the requesting user...
7910 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7914 * Move the job to a different printer or class...
7917 cupsdMoveJob(job
, dprinter
);
7922 * Start jobs if possible...
7928 * Return with "everything is OK" status...
7931 con
->response
->request
.status
.status_code
= IPP_OK
;
7936 * 'ppd_parse_line()' - Parse a PPD default line.
7939 static int /* O - 0 on success, -1 on failure */
7940 ppd_parse_line(const char *line
, /* I - Line */
7941 char *option
, /* O - Option name */
7942 int olen
, /* I - Size of option name */
7943 char *choice
, /* O - Choice name */
7944 int clen
) /* I - Size of choice name */
7947 * Verify this is a default option line...
7950 if (strncmp(line
, "*Default", 8))
7954 * Read the option name...
7957 for (line
+= 8, olen
--;
7958 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7969 * Skip everything else up to the colon (:)...
7972 while (*line
&& *line
!= ':')
7981 * Now grab the option choice, skipping leading whitespace...
7984 while (isspace(*line
& 255))
7988 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
7999 * Return with no errors...
8007 * 'print_job()' - Print a file to a printer or class.
8011 print_job(cupsd_client_t
*con
, /* I - Client connection */
8012 ipp_attribute_t
*uri
) /* I - Printer URI */
8014 ipp_attribute_t
*attr
; /* Current attribute */
8015 ipp_attribute_t
*doc_name
; /* document-name attribute */
8016 ipp_attribute_t
*format
; /* Document-format attribute */
8017 const char *default_format
; /* document-format-default value */
8018 cupsd_job_t
*job
; /* New job */
8019 char filename
[1024]; /* Job filename */
8020 mime_type_t
*filetype
; /* Type of file */
8021 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8022 type
[MIME_MAX_TYPE
], /* Subtype of file */
8023 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8024 /* Textual name of mime type */
8025 cupsd_printer_t
*printer
; /* Printer data */
8026 struct stat fileinfo
; /* File information */
8027 int kbytes
; /* Size of file */
8028 int compression
; /* Document compression */
8031 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8032 uri
->values
[0].string
.text
);
8035 * Validate print file attributes, for now just document-format and
8036 * compression (CUPS only supports "none" and "gzip")...
8039 compression
= CUPS_FILE_NONE
;
8041 if ((attr
= ippFindAttribute(con
->request
, "compression",
8042 IPP_TAG_KEYWORD
)) != NULL
)
8044 if (strcmp(attr
->values
[0].string
.text
, "none")
8046 && strcmp(attr
->values
[0].string
.text
, "gzip")
8047 #endif /* HAVE_LIBZ */
8050 send_ipp_status(con
, IPP_ATTRIBUTES
,
8051 _("Unsupported compression \"%s\"."),
8052 attr
->values
[0].string
.text
);
8053 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8054 "compression", NULL
, attr
->values
[0].string
.text
);
8059 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8060 compression
= CUPS_FILE_GZIP
;
8061 #endif /* HAVE_LIBZ */
8065 * Do we have a file to print?
8070 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8075 * Is the destination valid?
8078 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8084 send_ipp_status(con
, IPP_NOT_FOUND
,
8085 _("The printer or class does not exist."));
8090 * Is it a format we support?
8093 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8095 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8097 if ((format
= ippFindAttribute(con
->request
, "document-format",
8098 IPP_TAG_MIMETYPE
)) != NULL
)
8101 * Grab format from client...
8104 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8107 send_ipp_status(con
, IPP_BAD_REQUEST
,
8108 _("Bad document-format \"%s\"."),
8109 format
->values
[0].string
.text
);
8113 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8115 else if ((default_format
= cupsGetOption("document-format",
8116 printer
->num_options
,
8117 printer
->options
)) != NULL
)
8120 * Use default document format...
8123 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8125 send_ipp_status(con
, IPP_BAD_REQUEST
,
8126 _("Bad document-format \"%s\"."),
8137 strlcpy(super
, "application", sizeof(super
));
8138 strlcpy(type
, "octet-stream", sizeof(type
));
8141 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8144 * Auto-type the file...
8147 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8150 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8151 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8155 filetype
= mimeType(MimeDatabase
, super
, type
);
8157 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8158 filetype
->super
, filetype
->type
);
8160 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8161 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8164 filetype
= mimeType(MimeDatabase
, super
, type
);
8168 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8171 * Replace the document-format attribute value with the auto-typed or
8175 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8179 ippSetString(con
->request
, &format
, 0, mimetype
);
8181 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8182 "document-format", NULL
, mimetype
);
8186 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8187 _("Unsupported document-format \"%s\"."),
8188 format
? format
->values
[0].string
.text
:
8189 "application/octet-stream");
8190 cupsdLogMessage(CUPSD_LOG_INFO
,
8191 "Hint: Do you have the raw file printing rules enabled?");
8194 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8195 "document-format", NULL
, format
->values
[0].string
.text
);
8201 * Read any embedded job ticket info from PS files...
8204 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8205 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8206 !_cups_strcasecmp(filetype
->type
, "pdf")))
8207 read_job_ticket(con
);
8210 * Create the job object...
8213 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8217 * Update quota data...
8220 if (stat(con
->filename
, &fileinfo
))
8223 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8225 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8227 job
->koctets
+= kbytes
;
8229 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8230 attr
->values
[0].integer
+= kbytes
;
8233 * Add the job file...
8236 if (add_file(con
, job
, filetype
, compression
))
8239 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8240 if (rename(con
->filename
, filename
))
8242 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8244 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8248 cupsdClearString(&con
->filename
);
8251 * See if we need to add the ending sheet...
8254 if (cupsdTimeoutJob(job
))
8258 * Log and save the job...
8261 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8262 "File of type %s/%s queued by \"%s\".",
8263 filetype
->super
, filetype
->type
, job
->username
);
8264 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8265 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8266 job
->dest
, job
->username
);
8269 * Start the job if possible...
8277 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8279 * This function only gets called when printing a single PDF or PostScript
8280 * file using the Print-Job operation. It doesn't work for Create-Job +
8281 * Send-File, since the job attributes need to be set at job creation
8282 * time for banners to work. The embedded job ticket stuff is here
8283 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8284 * options and IPP attributes which otherwise would be lost.
8286 * The format of a job ticket is simple:
8288 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8290 * %cupsJobTicket: attr1=value1
8291 * %cupsJobTicket: attr2=value2
8293 * %cupsJobTicket: attrN=valueN
8295 * Job ticket lines must appear immediately after the first line that
8296 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8297 * stops looking for job ticket info when it finds a line that does not begin
8298 * with "%cupsJobTicket:".
8300 * The maximum length of a job ticket line, including the prefix, is
8301 * 255 characters to conform with the Adobe DSC.
8303 * Read-only attributes are rejected with a notice to the error log in
8304 * case a malicious user tries anything. Since the job ticket is read
8305 * prior to attribute validation in print_job(), job ticket attributes
8306 * will go through the same validation as IPP attributes...
8310 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8312 cups_file_t
*fp
; /* File to read from */
8313 char line
[256]; /* Line data */
8314 int num_options
; /* Number of options */
8315 cups_option_t
*options
; /* Options */
8316 ipp_t
*ticket
; /* New attributes */
8317 ipp_attribute_t
*attr
, /* Current attribute */
8318 *attr2
, /* Job attribute */
8319 *prev2
; /* Previous job attribute */
8323 * First open the print file...
8326 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8328 cupsdLogMessage(CUPSD_LOG_ERROR
,
8329 "Unable to open print file for job ticket - %s",
8335 * Skip the first line...
8338 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8340 cupsdLogMessage(CUPSD_LOG_ERROR
,
8341 "Unable to read from print file for job ticket - %s",
8347 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8350 * Not a DSC-compliant file, so no job ticket info will be available...
8358 * Read job ticket info from the file...
8364 while (cupsFileGets(fp
, line
, sizeof(line
)))
8367 * Stop at the first non-ticket line...
8370 if (strncmp(line
, "%cupsJobTicket:", 15))
8374 * Add the options to the option array...
8377 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8381 * Done with the file; see if we have any options...
8386 if (num_options
== 0)
8390 * OK, convert the options to an attribute list, and apply them to
8395 cupsEncodeOptions(ticket
, num_options
, options
);
8398 * See what the user wants to change.
8401 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8403 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8406 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8407 !strcmp(attr
->name
, "job-impressions-completed") ||
8408 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8409 !strncmp(attr
->name
, "job-k-octets", 12) ||
8410 !strcmp(attr
->name
, "job-id") ||
8411 !strcmp(attr
->name
, "job-originating-host-name") ||
8412 !strcmp(attr
->name
, "job-originating-user-name") ||
8413 !strcmp(attr
->name
, "job-pages-completed") ||
8414 !strcmp(attr
->name
, "job-printer-uri") ||
8415 !strncmp(attr
->name
, "job-state", 9) ||
8416 !strcmp(attr
->name
, "job-uri") ||
8417 !strncmp(attr
->name
, "time-at-", 8))
8418 continue; /* Read-only attrs */
8420 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8421 IPP_TAG_ZERO
)) != NULL
)
8424 * Some other value; first free the old value...
8427 if (con
->request
->attrs
== attr2
)
8429 con
->request
->attrs
= attr2
->next
;
8434 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8435 if (prev2
->next
== attr2
)
8437 prev2
->next
= attr2
->next
;
8442 if (con
->request
->last
== attr2
)
8443 con
->request
->last
= prev2
;
8445 ippDeleteAttribute(NULL
, attr2
);
8449 * Add new option by copying it...
8452 ippCopyAttribute(con
->request
, attr
, 0);
8456 * Then free the attribute list and option array...
8460 cupsFreeOptions(num_options
, options
);
8465 * 'reject_jobs()' - Reject print jobs to a printer.
8469 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8470 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8472 http_status_t status
; /* Policy status */
8473 cups_ptype_t dtype
; /* Destination type (printer/class) */
8474 cupsd_printer_t
*printer
; /* Printer data */
8475 ipp_attribute_t
*attr
; /* printer-state-message text */
8478 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8479 con
->number
, uri
->values
[0].string
.text
);
8482 * Is the destination valid?
8485 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8491 send_ipp_status(con
, IPP_NOT_FOUND
,
8492 _("The printer or class does not exist."));
8500 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8502 send_http_error(con
, status
, printer
);
8507 * Reject jobs sent to the printer...
8510 printer
->accepting
= 0;
8512 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8513 IPP_TAG_TEXT
)) == NULL
)
8514 strlcpy(printer
->state_message
, "Rejecting Jobs",
8515 sizeof(printer
->state_message
));
8517 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8518 sizeof(printer
->state_message
));
8520 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8521 "No longer accepting jobs.");
8523 if (dtype
& CUPS_PRINTER_CLASS
)
8525 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8527 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8528 printer
->name
, get_username(con
));
8532 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8534 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8535 printer
->name
, get_username(con
));
8539 * Everything was ok, so return OK status...
8542 con
->response
->request
.status
.status_code
= IPP_OK
;
8547 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8551 release_held_new_jobs(
8552 cupsd_client_t
*con
, /* I - Connection */
8553 ipp_attribute_t
*uri
) /* I - Printer URI */
8555 http_status_t status
; /* Policy status */
8556 cups_ptype_t dtype
; /* Destination type (printer/class) */
8557 cupsd_printer_t
*printer
; /* Printer data */
8560 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8561 con
->number
, uri
->values
[0].string
.text
);
8564 * Is the destination valid?
8567 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8573 send_ipp_status(con
, IPP_NOT_FOUND
,
8574 _("The printer or class does not exist."));
8582 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8584 send_http_error(con
, status
, printer
);
8589 * Hold pending/new jobs sent to the printer...
8592 printer
->holding_new_jobs
= 0;
8594 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8596 if (dtype
& CUPS_PRINTER_CLASS
)
8597 cupsdLogMessage(CUPSD_LOG_INFO
,
8598 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8599 printer
->name
, get_username(con
));
8601 cupsdLogMessage(CUPSD_LOG_INFO
,
8602 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8603 printer
->name
, get_username(con
));
8606 * Everything was ok, so return OK status...
8609 con
->response
->request
.status
.status_code
= IPP_OK
;
8614 * 'release_job()' - Release a held print job.
8618 release_job(cupsd_client_t
*con
, /* I - Client connection */
8619 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8621 ipp_attribute_t
*attr
; /* Current attribute */
8622 int jobid
; /* Job ID */
8623 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8624 username
[HTTP_MAX_URI
], /* Username portion of URI */
8625 host
[HTTP_MAX_URI
], /* Host portion of URI */
8626 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8627 int port
; /* Port portion of URI */
8628 cupsd_job_t
*job
; /* Job information */
8631 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
8632 con
->number
, uri
->values
[0].string
.text
);
8635 * See if we have a job URI or a printer URI...
8638 if (!strcmp(uri
->name
, "printer-uri"))
8641 * Got a printer URI; see if we also have a job-id attribute...
8644 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8645 IPP_TAG_INTEGER
)) == NULL
)
8647 send_ipp_status(con
, IPP_BAD_REQUEST
,
8648 _("Got a printer-uri attribute but no job-id."));
8652 jobid
= attr
->values
[0].integer
;
8657 * Got a job URI; parse it to get the job ID...
8660 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8661 sizeof(scheme
), username
, sizeof(username
), host
,
8662 sizeof(host
), &port
, resource
, sizeof(resource
));
8664 if (strncmp(resource
, "/jobs/", 6))
8670 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8671 uri
->values
[0].string
.text
);
8675 jobid
= atoi(resource
+ 6);
8679 * See if the job exists...
8682 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8685 * Nope - return a "not found" error...
8688 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8693 * See if job is "held"...
8696 if (job
->state_value
!= IPP_JOB_HELD
)
8699 * Nope - return a "not possible" error...
8702 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
8707 * See if the job is owned by the requesting user...
8710 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8712 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8713 cupsdFindDest(job
->dest
));
8718 * Reset the job-hold-until value to "no-hold"...
8721 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8722 IPP_TAG_KEYWORD
)) == NULL
)
8723 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8727 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
8728 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
8730 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
8731 "Job job-hold-until value changed by user.");
8732 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
8736 * Release the job and return...
8739 cupsdReleaseJob(job
);
8741 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
8742 "Job released by user.");
8744 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
8746 con
->response
->request
.status
.status_code
= IPP_OK
;
8753 * 'renew_subscription()' - Renew an existing subscription...
8758 cupsd_client_t
*con
, /* I - Client connection */
8759 int sub_id
) /* I - Subscription ID */
8761 http_status_t status
; /* Policy status */
8762 cupsd_subscription_t
*sub
; /* Subscription */
8763 ipp_attribute_t
*lease
; /* notify-lease-duration */
8766 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
8767 "renew_subscription(con=%p[%d], sub_id=%d)",
8768 con
, con
->number
, sub_id
);
8771 * Is the subscription ID valid?
8774 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
8777 * Bad subscription ID...
8780 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
8788 * Job subscriptions cannot be renewed...
8791 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8792 _("Job subscriptions cannot be renewed."));
8800 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
8802 con
, sub
->owner
)) != HTTP_OK
)
8804 send_http_error(con
, status
, sub
->dest
);
8809 * Renew the subscription...
8812 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
8815 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
8817 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
8819 cupsdLogMessage(CUPSD_LOG_INFO
,
8820 "renew_subscription: Limiting notify-lease-duration to "
8823 sub
->lease
= MaxLeaseDuration
;
8826 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
8828 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
8830 con
->response
->request
.status
.status_code
= IPP_OK
;
8832 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
8833 "notify-lease-duration", sub
->lease
);
8838 * 'restart_job()' - Restart an old print job.
8842 restart_job(cupsd_client_t
*con
, /* I - Client connection */
8843 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
8845 ipp_attribute_t
*attr
; /* Current attribute */
8846 int jobid
; /* Job ID */
8847 cupsd_job_t
*job
; /* Job information */
8848 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
8849 username
[HTTP_MAX_URI
], /* Username portion of URI */
8850 host
[HTTP_MAX_URI
], /* Host portion of URI */
8851 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8852 int port
; /* Port portion of URI */
8855 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
8856 con
->number
, uri
->values
[0].string
.text
);
8859 * See if we have a job URI or a printer URI...
8862 if (!strcmp(uri
->name
, "printer-uri"))
8865 * Got a printer URI; see if we also have a job-id attribute...
8868 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8869 IPP_TAG_INTEGER
)) == NULL
)
8871 send_ipp_status(con
, IPP_BAD_REQUEST
,
8872 _("Got a printer-uri attribute but no job-id."));
8876 jobid
= attr
->values
[0].integer
;
8881 * Got a job URI; parse it to get the job ID...
8884 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8885 sizeof(scheme
), username
, sizeof(username
), host
,
8886 sizeof(host
), &port
, resource
, sizeof(resource
));
8888 if (strncmp(resource
, "/jobs/", 6))
8894 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8895 uri
->values
[0].string
.text
);
8899 jobid
= atoi(resource
+ 6);
8903 * See if the job exists...
8906 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8909 * Nope - return a "not found" error...
8912 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8917 * See if job is in any of the "completed" states...
8920 if (job
->state_value
<= IPP_JOB_PROCESSING
)
8923 * Nope - return a "not possible" error...
8926 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
8932 * See if we have retained the job files...
8937 if (!job
->attrs
|| job
->num_files
== 0)
8940 * Nope - return a "not possible" error...
8943 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8944 _("Job #%d cannot be restarted - no files."), jobid
);
8949 * See if the job is owned by the requesting user...
8952 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8954 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8955 cupsdFindDest(job
->dest
));
8960 * See if the job-hold-until attribute is specified...
8963 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
8964 IPP_TAG_KEYWORD
)) == NULL
)
8965 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
8967 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
8970 * Return the job to a held state...
8973 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
8974 "Restarted by \"%s\" with job-hold-until=%s.",
8975 username
, attr
->values
[0].string
.text
);
8976 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
8978 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
8979 NULL
, job
, "Job restarted by user with job-hold-until=%s",
8980 attr
->values
[0].string
.text
);
8985 * Restart the job...
8988 cupsdRestartJob(job
);
8992 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
8994 con
->response
->request
.status
.status_code
= IPP_OK
;
8999 * 'save_auth_info()' - Save authentication information for a job.
9004 cupsd_client_t
*con
, /* I - Client connection */
9005 cupsd_job_t
*job
, /* I - Job */
9006 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9008 int i
; /* Looping var */
9009 char filename
[1024]; /* Job authentication filename */
9010 cups_file_t
*fp
; /* Job authentication file */
9011 char line
[65536]; /* Line for file */
9012 cupsd_printer_t
*dest
; /* Destination printer/class */
9016 * This function saves the in-memory authentication information for
9017 * a job so that it can be used to authenticate with a remote host.
9018 * The information is stored in a file that is readable only by the
9019 * root user. The fields are Base-64 encoded, each on a separate line,
9020 * followed by random number (up to 1024) of newlines to limit the
9021 * amount of information that is exposed.
9023 * Because of the potential for exposing of authentication information,
9024 * this functionality is only enabled when running cupsd as root.
9026 * This caching only works for the Basic and BasicDigest authentication
9027 * types. Digest authentication cannot be cached this way, and in
9028 * the future Kerberos authentication may make all of this obsolete.
9030 * Authentication information is saved whenever an authenticated
9031 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9034 * This information is deleted after a job is completed or canceled,
9035 * so reprints may require subsequent re-authentication.
9041 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9045 * Create the authentication file and change permissions...
9048 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9049 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9051 cupsdLogMessage(CUPSD_LOG_ERROR
,
9052 "Unable to save authentication info to \"%s\" - %s",
9053 filename
, strerror(errno
));
9057 fchown(cupsFileNumber(fp
), 0, 0);
9058 fchmod(cupsFileNumber(fp
), 0400);
9060 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9063 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9065 cupsdClearString(job
->auth_env
+ i
);
9067 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9070 * Write 1 to 3 auth values...
9074 i
< auth_info
->num_values
&&
9075 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9078 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9080 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9081 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9084 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9085 auth_info
->values
[i
].string
.text
);
9087 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9088 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9089 auth_info
->values
[i
].string
.text
);
9090 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9091 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9092 auth_info
->values
[i
].string
.text
);
9093 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9094 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9095 auth_info
->values
[i
].string
.text
);
9096 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9097 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9098 auth_info
->values
[i
].string
.text
);
9103 else if (auth_info
&& auth_info
->num_values
== 2 &&
9104 dest
->num_auth_info_required
== 1 &&
9105 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9108 * Allow fallback to username+password for Kerberized queues...
9111 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9112 cupsFilePutConf(fp
, "username", line
);
9114 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9115 auth_info
->values
[0].string
.text
);
9117 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9118 cupsFilePutConf(fp
, "password", line
);
9120 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9121 auth_info
->values
[1].string
.text
);
9123 else if (con
->username
[0])
9126 * Write the authenticated username...
9129 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9130 cupsFilePutConf(fp
, "username", line
);
9132 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9135 * Write the authenticated password...
9138 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9139 cupsFilePutConf(fp
, "password", line
);
9141 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9145 if (con
->gss_uid
> 0)
9147 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9148 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9150 #endif /* HAVE_GSSAPI */
9153 * Write a random number of newlines to the end of the file...
9156 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9157 cupsFilePutChar(fp
, '\n');
9160 * Close the file and return...
9168 * 'send_document()' - Send a file to a printer or class.
9172 send_document(cupsd_client_t
*con
, /* I - Client connection */
9173 ipp_attribute_t
*uri
) /* I - Printer URI */
9175 ipp_attribute_t
*attr
; /* Current attribute */
9176 ipp_attribute_t
*format
; /* Request's document-format attribute */
9177 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9178 const char *default_format
;/* document-format-default value */
9179 int jobid
; /* Job ID number */
9180 cupsd_job_t
*job
; /* Current job */
9181 char job_uri
[HTTP_MAX_URI
],
9183 scheme
[HTTP_MAX_URI
],
9184 /* Method portion of URI */
9185 username
[HTTP_MAX_URI
],
9186 /* Username portion of URI */
9188 /* Host portion of URI */
9189 resource
[HTTP_MAX_URI
];
9190 /* Resource portion of URI */
9191 int port
; /* Port portion of URI */
9192 mime_type_t
*filetype
; /* Type of file */
9193 char super
[MIME_MAX_SUPER
],
9194 /* Supertype of file */
9195 type
[MIME_MAX_TYPE
],
9196 /* Subtype of file */
9197 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9198 /* Textual name of mime type */
9199 char filename
[1024]; /* Job filename */
9200 cupsd_printer_t
*printer
; /* Current printer */
9201 struct stat fileinfo
; /* File information */
9202 int kbytes
; /* Size of file */
9203 int compression
; /* Type of compression */
9204 int start_job
; /* Start the job? */
9207 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9208 con
->number
, uri
->values
[0].string
.text
);
9211 * See if we have a job URI or a printer URI...
9214 if (!strcmp(uri
->name
, "printer-uri"))
9217 * Got a printer URI; see if we also have a job-id attribute...
9220 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9221 IPP_TAG_INTEGER
)) == NULL
)
9223 send_ipp_status(con
, IPP_BAD_REQUEST
,
9224 _("Got a printer-uri attribute but no job-id."));
9228 jobid
= attr
->values
[0].integer
;
9233 * Got a job URI; parse it to get the job ID...
9236 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9237 sizeof(scheme
), username
, sizeof(username
), host
,
9238 sizeof(host
), &port
, resource
, sizeof(resource
));
9240 if (strncmp(resource
, "/jobs/", 6))
9246 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9247 uri
->values
[0].string
.text
);
9251 jobid
= atoi(resource
+ 6);
9255 * See if the job exists...
9258 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9261 * Nope - return a "not found" error...
9264 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9268 printer
= cupsdFindDest(job
->dest
);
9271 * See if the job is owned by the requesting user...
9274 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9276 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9277 cupsdFindDest(job
->dest
));
9282 * OK, see if the client is sending the document compressed - CUPS
9283 * only supports "none" and "gzip".
9286 compression
= CUPS_FILE_NONE
;
9288 if ((attr
= ippFindAttribute(con
->request
, "compression",
9289 IPP_TAG_KEYWORD
)) != NULL
)
9291 if (strcmp(attr
->values
[0].string
.text
, "none")
9293 && strcmp(attr
->values
[0].string
.text
, "gzip")
9294 #endif /* HAVE_LIBZ */
9297 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9298 attr
->values
[0].string
.text
);
9299 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9300 "compression", NULL
, attr
->values
[0].string
.text
);
9305 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9306 compression
= CUPS_FILE_GZIP
;
9307 #endif /* HAVE_LIBZ */
9311 * Do we have a file to print?
9314 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9315 IPP_TAG_BOOLEAN
)) == NULL
)
9317 send_ipp_status(con
, IPP_BAD_REQUEST
,
9318 _("Missing last-document attribute in request."));
9325 * Check for an empty request with "last-document" set to true, which is
9326 * used to close an "open" job by RFC 2911, section 3.3.2.
9329 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9332 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9337 * Is it a format we support?
9342 if ((format
= ippFindAttribute(con
->request
, "document-format",
9343 IPP_TAG_MIMETYPE
)) != NULL
)
9346 * Grab format from client...
9349 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9352 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9353 format
->values
[0].string
.text
);
9357 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9359 else if ((default_format
= cupsGetOption("document-format",
9360 printer
->num_options
,
9361 printer
->options
)) != NULL
)
9364 * Use default document format...
9367 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9369 send_ipp_status(con
, IPP_BAD_REQUEST
,
9370 _("Bad document-format-default \"%s\"."), default_format
);
9377 * No document format attribute? Auto-type it!
9380 strlcpy(super
, "application", sizeof(super
));
9381 strlcpy(type
, "octet-stream", sizeof(type
));
9384 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9387 * Auto-type the file...
9390 ipp_attribute_t
*doc_name
; /* document-name attribute */
9393 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9395 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9396 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9397 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9401 filetype
= mimeType(MimeDatabase
, super
, type
);
9404 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9405 filetype
->super
, filetype
->type
);
9407 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9408 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9411 filetype
= mimeType(MimeDatabase
, super
, type
);
9416 * Replace the document-format attribute value with the auto-typed or
9420 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9423 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9424 IPP_TAG_MIMETYPE
)) != NULL
)
9425 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9427 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9428 "document-format", NULL
, mimetype
);
9432 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9433 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9434 cupsdLogMessage(CUPSD_LOG_INFO
,
9435 "Hint: Do you have the raw file printing rules enabled?");
9438 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9439 "document-format", NULL
, format
->values
[0].string
.text
);
9444 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9446 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9449 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9450 _("Unsupported document-format \"%s\"."), mimetype
);
9452 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9453 "document-format", NULL
, mimetype
);
9459 * Add the file to the job...
9462 if (add_file(con
, job
, filetype
, compression
))
9465 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9466 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9468 if (stat(con
->filename
, &fileinfo
))
9471 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9473 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9475 job
->koctets
+= kbytes
;
9477 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9478 attr
->values
[0].integer
+= kbytes
;
9480 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9481 if (rename(con
->filename
, filename
))
9483 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9485 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9489 cupsdClearString(&con
->filename
);
9491 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9492 filetype
->super
, filetype
->type
, job
->username
);
9495 * Start the job if this is the last document...
9500 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9501 IPP_TAG_BOOLEAN
)) != NULL
&&
9502 attr
->values
[0].boolean
)
9505 * See if we need to add the ending sheet...
9508 if (cupsdTimeoutJob(job
))
9511 if (job
->state_value
== IPP_JOB_STOPPED
)
9513 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9514 job
->state_value
= IPP_JOB_PENDING
;
9516 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9518 else if (job
->state_value
== IPP_JOB_HELD
)
9520 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9521 IPP_TAG_KEYWORD
)) == NULL
)
9522 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9524 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9526 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9527 job
->state_value
= IPP_JOB_PENDING
;
9529 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9532 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9536 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9542 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9543 IPP_TAG_KEYWORD
)) == NULL
)
9544 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9546 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9548 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9549 job
->state_value
= IPP_JOB_HELD
;
9550 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9552 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9555 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9562 * Fill in the response info...
9565 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9566 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9567 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9570 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9572 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9574 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9575 NULL
, job
->reasons
->values
[0].string
.text
);
9577 con
->response
->request
.status
.status_code
= IPP_OK
;
9580 * Start the job if necessary...
9589 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9594 cupsd_client_t
*con
, /* I - Client connection */
9595 http_status_t status
, /* I - HTTP status code */
9596 cupsd_printer_t
*printer
) /* I - Printer, if any */
9598 ipp_attribute_t
*uri
; /* Request URI, if any */
9601 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9602 IPP_TAG_URI
)) == NULL
)
9603 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9605 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9606 "[Client %d] Returning HTTP %s for %s (%s) from %s",
9607 con
->number
, httpStatus(status
),
9609 ippOpString(con
->request
->request
.op
.operation_id
) :
9611 uri
? uri
->values
[0].string
.text
: "no URI",
9612 con
->http
->hostname
);
9616 int auth_type
; /* Type of authentication required */
9619 auth_type
= CUPSD_AUTH_NONE
;
9621 if (status
== HTTP_UNAUTHORIZED
&&
9622 printer
->num_auth_info_required
> 0 &&
9623 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
9625 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
9626 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
9627 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
9630 * Creating and authenticating jobs requires Kerberos...
9633 auth_type
= CUPSD_AUTH_NEGOTIATE
;
9638 * Use policy/location-defined authentication requirements...
9641 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9642 cupsd_location_t
*auth
; /* Pointer to authentication element */
9645 if (printer
->type
& CUPS_PRINTER_CLASS
)
9646 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
9648 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
9650 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
9651 auth
->type
== CUPSD_AUTH_NONE
)
9652 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
9654 con
->request
->request
.op
.operation_id
:
9659 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
9660 auth_type
= cupsdDefaultAuthType();
9662 auth_type
= auth
->type
;
9666 cupsdSendError(con
, status
, auth_type
);
9669 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
9671 ippDelete(con
->response
);
9672 con
->response
= NULL
;
9679 * 'send_ipp_status()' - Send a status back to the IPP client.
9683 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
9684 ipp_status_t status
, /* I - IPP status code */
9685 const char *message
,/* I - Status message */
9686 ...) /* I - Additional args as needed */
9688 va_list ap
; /* Pointer to additional args */
9689 char formatted
[1024]; /* Formatted errror message */
9692 va_start(ap
, message
);
9693 vsnprintf(formatted
, sizeof(formatted
),
9694 _cupsLangString(con
->language
, message
), ap
);
9697 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
9698 ippOpString(con
->request
->request
.op
.operation_id
),
9699 ippErrorString(status
), formatted
);
9701 con
->response
->request
.status
.status_code
= status
;
9703 if (ippFindAttribute(con
->response
, "attributes-charset",
9704 IPP_TAG_ZERO
) == NULL
)
9705 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
9706 "attributes-charset", NULL
, "utf-8");
9708 if (ippFindAttribute(con
->response
, "attributes-natural-language",
9709 IPP_TAG_ZERO
) == NULL
)
9710 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
9711 "attributes-natural-language", NULL
, DefaultLanguage
);
9713 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
9714 "status-message", NULL
, formatted
);
9719 * 'set_default()' - Set the default destination...
9723 set_default(cupsd_client_t
*con
, /* I - Client connection */
9724 ipp_attribute_t
*uri
) /* I - Printer URI */
9726 http_status_t status
; /* Policy status */
9727 cups_ptype_t dtype
; /* Destination type (printer/class) */
9728 cupsd_printer_t
*printer
, /* Printer */
9729 *oldprinter
; /* Old default printer */
9732 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
9733 con
->number
, uri
->values
[0].string
.text
);
9736 * Is the destination valid?
9739 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9745 send_ipp_status(con
, IPP_NOT_FOUND
,
9746 _("The printer or class does not exist."));
9754 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
9756 send_http_error(con
, status
, NULL
);
9761 * Set it as the default...
9764 oldprinter
= DefaultPrinter
;
9765 DefaultPrinter
= printer
;
9768 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
9769 "%s is no longer the default printer.", oldprinter
->name
);
9771 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
9772 "%s is now the default printer.", printer
->name
);
9774 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
9775 CUPSD_DIRTY_PRINTCAP
);
9777 cupsdLogMessage(CUPSD_LOG_INFO
,
9778 "Default destination set to \"%s\" by \"%s\".",
9779 printer
->name
, get_username(con
));
9782 * Everything was ok, so return OK status...
9785 con
->response
->request
.status
.status_code
= IPP_OK
;
9790 * 'set_job_attrs()' - Set job attributes.
9794 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
9795 ipp_attribute_t
*uri
) /* I - Job URI */
9797 ipp_attribute_t
*attr
, /* Current attribute */
9798 *attr2
; /* Job attribute */
9799 int jobid
; /* Job ID */
9800 cupsd_job_t
*job
; /* Current job */
9801 char scheme
[HTTP_MAX_URI
],
9802 /* Method portion of URI */
9803 username
[HTTP_MAX_URI
],
9804 /* Username portion of URI */
9806 /* Host portion of URI */
9807 resource
[HTTP_MAX_URI
];
9808 /* Resource portion of URI */
9809 int port
; /* Port portion of URI */
9810 int event
; /* Events? */
9811 int check_jobs
; /* Check jobs? */
9814 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
9815 con
->number
, uri
->values
[0].string
.text
);
9818 * Start with "everything is OK" status...
9821 con
->response
->request
.status
.status_code
= IPP_OK
;
9824 * See if we have a job URI or a printer URI...
9827 if (!strcmp(uri
->name
, "printer-uri"))
9830 * Got a printer URI; see if we also have a job-id attribute...
9833 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9834 IPP_TAG_INTEGER
)) == NULL
)
9836 send_ipp_status(con
, IPP_BAD_REQUEST
,
9837 _("Got a printer-uri attribute but no job-id."));
9841 jobid
= attr
->values
[0].integer
;
9846 * Got a job URI; parse it to get the job ID...
9849 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9850 sizeof(scheme
), username
, sizeof(username
), host
,
9851 sizeof(host
), &port
, resource
, sizeof(resource
));
9853 if (strncmp(resource
, "/jobs/", 6))
9859 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9860 uri
->values
[0].string
.text
);
9864 jobid
= atoi(resource
+ 6);
9868 * See if the job exists...
9871 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9874 * Nope - return a "not found" error...
9877 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9882 * See if the job has been completed...
9885 if (job
->state_value
> IPP_JOB_STOPPED
)
9888 * Return a "not-possible" error...
9891 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9892 _("Job #%d is finished and cannot be altered."), jobid
);
9897 * See if the job is owned by the requesting user...
9900 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9902 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9903 cupsdFindDest(job
->dest
));
9908 * See what the user wants to change.
9916 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
9918 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
9921 if (!strcmp(attr
->name
, "attributes-charset") ||
9922 !strcmp(attr
->name
, "attributes-natural-language") ||
9923 !strncmp(attr
->name
, "date-time-at-", 13) ||
9924 !strncmp(attr
->name
, "document-compression", 20) ||
9925 !strncmp(attr
->name
, "document-format", 15) ||
9926 !strcmp(attr
->name
, "job-detailed-status-messages") ||
9927 !strcmp(attr
->name
, "job-document-access-errors") ||
9928 !strcmp(attr
->name
, "job-id") ||
9929 !strcmp(attr
->name
, "job-impressions-completed") ||
9930 !strcmp(attr
->name
, "job-k-octets-completed") ||
9931 !strcmp(attr
->name
, "job-media-sheets-completed") ||
9932 !strcmp(attr
->name
, "job-originating-host-name") ||
9933 !strcmp(attr
->name
, "job-originating-user-name") ||
9934 !strcmp(attr
->name
, "job-pages-completed") ||
9935 !strcmp(attr
->name
, "job-printer-up-time") ||
9936 !strcmp(attr
->name
, "job-printer-uri") ||
9937 !strcmp(attr
->name
, "job-sheets") ||
9938 !strcmp(attr
->name
, "job-state-message") ||
9939 !strcmp(attr
->name
, "job-state-reasons") ||
9940 !strcmp(attr
->name
, "job-uri") ||
9941 !strcmp(attr
->name
, "number-of-documents") ||
9942 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
9943 !strcmp(attr
->name
, "output-device-assigned") ||
9944 !strncmp(attr
->name
, "time-at-", 8))
9950 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
9951 _("%s cannot be changed."), attr
->name
);
9953 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9954 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9958 if (!strcmp(attr
->name
, "job-priority"))
9961 * Change the job priority...
9964 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
9966 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
9968 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9969 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
9971 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
9973 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9974 _("Job is completed and cannot be changed."));
9977 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
9979 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
9980 attr
->values
[0].integer
);
9981 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
9984 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
9985 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
9988 else if (!strcmp(attr
->name
, "job-state"))
9991 * Change the job state...
9994 if (attr
->value_tag
!= IPP_TAG_ENUM
)
9996 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
9998 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
9999 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10003 switch (attr
->values
[0].integer
)
10005 case IPP_JOB_PENDING
:
10006 case IPP_JOB_HELD
:
10007 if (job
->state_value
> IPP_JOB_HELD
)
10009 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10010 _("Job state cannot be changed."));
10013 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10015 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10016 attr
->values
[0].integer
);
10017 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10022 case IPP_JOB_PROCESSING
:
10023 case IPP_JOB_STOPPED
:
10024 if (job
->state_value
!= attr
->values
[0].integer
)
10026 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10027 _("Job state cannot be changed."));
10032 case IPP_JOB_CANCELED
:
10033 case IPP_JOB_ABORTED
:
10034 case IPP_JOB_COMPLETED
:
10035 if (job
->state_value
> IPP_JOB_PROCESSING
)
10037 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10038 _("Job state cannot be changed."));
10041 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10043 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10044 attr
->values
[0].integer
);
10045 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10047 "Job state changed by \"%s\"", username
);
10054 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10056 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10057 IPP_TAG_ZERO
)) != NULL
)
10060 * Some other value; first free the old value...
10063 if (job
->attrs
->prev
)
10064 job
->attrs
->prev
->next
= attr2
->next
;
10066 job
->attrs
->attrs
= attr2
->next
;
10068 if (job
->attrs
->last
== attr2
)
10069 job
->attrs
->last
= job
->attrs
->prev
;
10071 ippDeleteAttribute(NULL
, attr2
);
10074 * Then copy the attribute...
10077 ippCopyAttribute(job
->attrs
, attr
, 0);
10080 * See if the job-name or job-hold-until is being changed.
10083 if (!strcmp(attr
->name
, "job-hold-until"))
10085 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s",
10086 attr
->values
[0].string
.text
);
10087 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
10089 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
10091 cupsdReleaseJob(job
);
10095 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
,
10096 "Job held by \"%s\".", username
);
10098 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10101 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10104 * Delete the attribute...
10107 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10108 IPP_TAG_ZERO
)) != NULL
)
10110 if (job
->attrs
->prev
)
10111 job
->attrs
->prev
->next
= attr2
->next
;
10113 job
->attrs
->attrs
= attr2
->next
;
10115 if (attr2
== job
->attrs
->last
)
10116 job
->attrs
->last
= job
->attrs
->prev
;
10118 ippDeleteAttribute(NULL
, attr2
);
10120 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10126 * Add new option by copying it...
10129 ippCopyAttribute(job
->attrs
, attr
, 0);
10131 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10140 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10143 * Send events as needed...
10146 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10147 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10148 cupsdFindDest(job
->dest
), job
,
10149 "Job priority changed by user.");
10151 if (event
& CUPSD_EVENT_JOB_STATE
)
10152 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10153 job
->state_value
== IPP_JOB_HELD
?
10154 "Job held by user." : "Job restarted by user.");
10156 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10157 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10158 "Job options changed by user.");
10161 * Start jobs if possible...
10170 * 'set_printer_attrs()' - Set printer attributes.
10174 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10175 ipp_attribute_t
*uri
) /* I - Printer */
10177 http_status_t status
; /* Policy status */
10178 cups_ptype_t dtype
; /* Destination type (printer/class) */
10179 cupsd_printer_t
*printer
; /* Printer/class */
10180 ipp_attribute_t
*attr
; /* Printer attribute */
10181 int changed
= 0; /* Was anything changed? */
10184 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10185 con
->number
, uri
->values
[0].string
.text
);
10188 * Is the destination valid?
10191 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10197 send_ipp_status(con
, IPP_NOT_FOUND
,
10198 _("The printer or class does not exist."));
10206 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10208 send_http_error(con
, status
, printer
);
10213 * Return a list of attributes that can be set via Set-Printer-Attributes.
10216 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10217 IPP_TAG_TEXT
)) != NULL
)
10219 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10223 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10225 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10229 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10231 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10235 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10237 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10241 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10242 IPP_TAG_TEXT
)) != NULL
)
10244 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10249 * Update the printer attributes and return...
10254 printer
->config_time
= time(NULL
);
10256 cupsdSetPrinterAttrs(printer
);
10257 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10259 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10260 "Printer \"%s\" description or location changed by \"%s\".",
10261 printer
->name
, get_username(con
));
10263 cupsdLogMessage(CUPSD_LOG_INFO
,
10264 "Printer \"%s\" description or location changed by \"%s\".",
10265 printer
->name
, get_username(con
));
10268 con
->response
->request
.status
.status_code
= IPP_OK
;
10273 * 'set_printer_defaults()' - Set printer default options from a request.
10277 set_printer_defaults(
10278 cupsd_client_t
*con
, /* I - Client connection */
10279 cupsd_printer_t
*printer
) /* I - Printer */
10281 int i
; /* Looping var */
10282 ipp_attribute_t
*attr
; /* Current attribute */
10283 size_t namelen
; /* Length of attribute name */
10284 char name
[256], /* New attribute name */
10285 value
[256]; /* String version of integer attrs */
10288 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10291 * Skip non-printer attributes...
10294 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10297 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10299 if (!strcmp(attr
->name
, "job-sheets-default"))
10302 * Only allow keywords and names...
10305 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10309 * Only allow job-sheets-default to be set when running without a
10310 * system high classification level...
10313 if (Classification
)
10316 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10318 if (attr
->num_values
> 1)
10319 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10321 cupsdSetString(&printer
->job_sheets
[1], "none");
10323 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10325 cupsdFreeStrings(&(printer
->users
));
10327 printer
->deny_users
= 0;
10329 if (attr
->value_tag
== IPP_TAG_NAME
&&
10330 (attr
->num_values
> 1 ||
10331 strcmp(attr
->values
[0].string
.text
, "all")))
10333 for (i
= 0; i
< attr
->num_values
; i
++)
10334 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10337 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10339 cupsdFreeStrings(&(printer
->users
));
10341 printer
->deny_users
= 1;
10343 if (attr
->value_tag
== IPP_TAG_NAME
&&
10344 (attr
->num_values
> 1 ||
10345 strcmp(attr
->values
[0].string
.text
, "none")))
10347 for (i
= 0; i
< attr
->num_values
; i
++)
10348 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10351 else if (!strcmp(attr
->name
, "job-quota-period"))
10353 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10356 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10357 attr
->values
[0].integer
);
10358 cupsdFreeQuotas(printer
);
10360 printer
->quota_period
= attr
->values
[0].integer
;
10362 else if (!strcmp(attr
->name
, "job-k-limit"))
10364 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10367 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10368 attr
->values
[0].integer
);
10369 cupsdFreeQuotas(printer
);
10371 printer
->k_limit
= attr
->values
[0].integer
;
10373 else if (!strcmp(attr
->name
, "job-page-limit"))
10375 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10378 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10379 attr
->values
[0].integer
);
10380 cupsdFreeQuotas(printer
);
10382 printer
->page_limit
= attr
->values
[0].integer
;
10384 else if (!strcmp(attr
->name
, "printer-op-policy"))
10386 cupsd_policy_t
*p
; /* Policy */
10389 if (attr
->value_tag
!= IPP_TAG_NAME
)
10392 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10394 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10395 "Setting printer-op-policy to \"%s\"...",
10396 attr
->values
[0].string
.text
);
10397 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10398 printer
->op_policy_ptr
= p
;
10402 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10403 _("Unknown printer-op-policy \"%s\"."),
10404 attr
->values
[0].string
.text
);
10408 else if (!strcmp(attr
->name
, "printer-error-policy"))
10410 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10413 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10414 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10415 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10416 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10417 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10419 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10420 _("Unknown printer-error-policy \"%s\"."),
10421 attr
->values
[0].string
.text
);
10425 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10426 "Setting printer-error-policy to \"%s\"...",
10427 attr
->values
[0].string
.text
);
10428 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10432 * Skip any other non-default attributes...
10435 namelen
= strlen(attr
->name
);
10436 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10437 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10441 * OK, anything else must be a user-defined default...
10444 strlcpy(name
, attr
->name
, sizeof(name
));
10445 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10447 switch (attr
->value_tag
)
10449 case IPP_TAG_DELETEATTR
:
10450 printer
->num_options
= cupsRemoveOption(name
,
10451 printer
->num_options
,
10452 &(printer
->options
));
10453 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10454 "Deleting %s", attr
->name
);
10457 case IPP_TAG_NAME
:
10458 case IPP_TAG_TEXT
:
10459 case IPP_TAG_KEYWORD
:
10461 printer
->num_options
= cupsAddOption(name
,
10462 attr
->values
[0].string
.text
,
10463 printer
->num_options
,
10464 &(printer
->options
));
10465 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10466 "Setting %s to \"%s\"...", attr
->name
,
10467 attr
->values
[0].string
.text
);
10470 case IPP_TAG_BOOLEAN
:
10471 printer
->num_options
= cupsAddOption(name
,
10472 attr
->values
[0].boolean
?
10474 printer
->num_options
,
10475 &(printer
->options
));
10476 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10477 "Setting %s to %s...", attr
->name
,
10478 attr
->values
[0].boolean
? "true" : "false");
10481 case IPP_TAG_INTEGER
:
10482 case IPP_TAG_ENUM
:
10483 sprintf(value
, "%d", attr
->values
[0].integer
);
10484 printer
->num_options
= cupsAddOption(name
, value
,
10485 printer
->num_options
,
10486 &(printer
->options
));
10487 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10488 "Setting %s to %s...", attr
->name
, value
);
10491 case IPP_TAG_RANGE
:
10492 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10493 attr
->values
[0].range
.upper
);
10494 printer
->num_options
= cupsAddOption(name
, value
,
10495 printer
->num_options
,
10496 &(printer
->options
));
10497 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10498 "Setting %s to %s...", attr
->name
, value
);
10501 case IPP_TAG_RESOLUTION
:
10502 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10503 attr
->values
[0].resolution
.yres
,
10504 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10506 printer
->num_options
= cupsAddOption(name
, value
,
10507 printer
->num_options
,
10508 &(printer
->options
));
10509 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10510 "Setting %s to %s...", attr
->name
, value
);
10514 /* Do nothing for other values */
10522 * 'start_printer()' - Start a printer.
10526 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10527 ipp_attribute_t
*uri
) /* I - Printer URI */
10529 int i
; /* Temporary variable */
10530 http_status_t status
; /* Policy status */
10531 cups_ptype_t dtype
; /* Destination type (printer/class) */
10532 cupsd_printer_t
*printer
; /* Printer data */
10535 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10536 con
->number
, uri
->values
[0].string
.text
);
10539 * Is the destination valid?
10542 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10548 send_ipp_status(con
, IPP_NOT_FOUND
,
10549 _("The printer or class does not exist."));
10557 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10559 send_http_error(con
, status
, printer
);
10564 * Start the printer...
10567 printer
->state_message
[0] = '\0';
10569 cupsdStartPrinter(printer
, 1);
10571 if (dtype
& CUPS_PRINTER_CLASS
)
10572 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10573 printer
->name
, get_username(con
));
10575 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10576 printer
->name
, get_username(con
));
10584 if ((i
= check_quotas(con
, printer
)) < 0)
10586 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10591 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
10596 * Everything was ok, so return OK status...
10599 con
->response
->request
.status
.status_code
= IPP_OK
;
10604 * 'stop_printer()' - Stop a printer.
10608 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
10609 ipp_attribute_t
*uri
) /* I - Printer URI */
10611 http_status_t status
; /* Policy status */
10612 cups_ptype_t dtype
; /* Destination type (printer/class) */
10613 cupsd_printer_t
*printer
; /* Printer data */
10614 ipp_attribute_t
*attr
; /* printer-state-message attribute */
10617 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
10618 con
->number
, uri
->values
[0].string
.text
);
10621 * Is the destination valid?
10624 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10630 send_ipp_status(con
, IPP_NOT_FOUND
,
10631 _("The printer or class does not exist."));
10639 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10641 send_http_error(con
, status
, printer
);
10646 * Stop the printer...
10649 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
10650 IPP_TAG_TEXT
)) == NULL
)
10651 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
10654 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
10655 sizeof(printer
->state_message
));
10658 cupsdStopPrinter(printer
, 1);
10660 if (dtype
& CUPS_PRINTER_CLASS
)
10661 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
10662 printer
->name
, get_username(con
));
10664 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
10665 printer
->name
, get_username(con
));
10668 * Everything was ok, so return OK status...
10671 con
->response
->request
.status
.status_code
= IPP_OK
;
10676 * 'url_encode_attr()' - URL-encode a string attribute.
10680 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
10681 char *buffer
,/* I - String buffer */
10682 size_t bufsize
)/* I - Size of buffer */
10684 int i
; /* Looping var */
10685 char *bufptr
, /* Pointer into buffer */
10686 *bufend
; /* End of buffer */
10689 strlcpy(buffer
, attr
->name
, bufsize
);
10690 bufptr
= buffer
+ strlen(buffer
);
10691 bufend
= buffer
+ bufsize
- 1;
10693 for (i
= 0; i
< attr
->num_values
; i
++)
10695 if (bufptr
>= bufend
)
10703 if (bufptr
>= bufend
)
10708 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
10710 if (bufptr
>= bufend
)
10721 * 'url_encode_string()' - URL-encode a string.
10724 static char * /* O - End of string */
10725 url_encode_string(const char *s
, /* I - String */
10726 char *buffer
, /* I - String buffer */
10727 size_t bufsize
) /* I - Size of buffer */
10729 char *bufptr
, /* Pointer into buffer */
10730 *bufend
; /* End of buffer */
10731 static const char *hex
= "0123456789ABCDEF";
10736 bufend
= buffer
+ bufsize
- 1;
10738 while (*s
&& bufptr
< bufend
)
10740 if (*s
== ' ' || *s
== '%' || *s
== '+')
10742 if (bufptr
>= (bufend
- 2))
10746 *bufptr
++ = hex
[(*s
>> 4) & 15];
10747 *bufptr
++ = hex
[*s
& 15];
10751 else if (*s
== '\'' || *s
== '\\')
10753 if (bufptr
>= (bufend
- 1))
10770 * 'user_allowed()' - See if a user is allowed to print to a queue.
10773 static int /* O - 0 if not allowed, 1 if allowed */
10774 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
10775 const char *username
) /* I - Username */
10777 struct passwd
*pw
; /* User password data */
10778 char baseuser
[256], /* Base username */
10779 *baseptr
, /* Pointer to "@" in base username */
10780 *name
; /* Current user name */
10783 if (cupsArrayCount(p
->users
) == 0)
10786 if (!strcmp(username
, "root"))
10789 if (strchr(username
, '@'))
10792 * Strip @REALM for username check...
10795 strlcpy(baseuser
, username
, sizeof(baseuser
));
10797 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
10800 username
= baseuser
;
10803 pw
= getpwnam(username
);
10806 for (name
= (char *)cupsArrayFirst(p
->users
);
10808 name
= (char *)cupsArrayNext(p
->users
))
10810 if (name
[0] == '@')
10813 * Check group membership...
10816 if (cupsdCheckGroup(username
, pw
, name
+ 1))
10819 else if (name
[0] == '#')
10825 if (cupsdCheckGroup(username
, pw
, name
))
10828 else if (!_cups_strcasecmp(username
, name
))
10832 return ((name
!= NULL
) != p
->deny_users
);
10837 * 'validate_job()' - Validate printer options and destination.
10841 validate_job(cupsd_client_t
*con
, /* I - Client connection */
10842 ipp_attribute_t
*uri
) /* I - Printer URI */
10844 http_status_t status
; /* Policy status */
10845 ipp_attribute_t
*attr
; /* Current attribute */
10847 ipp_attribute_t
*auth_info
; /* auth-info attribute */
10848 #endif /* HAVE_SSL */
10849 ipp_attribute_t
*format
, /* Document-format attribute */
10850 *name
; /* Job-name attribute */
10851 cups_ptype_t dtype
; /* Destination type (printer/class) */
10852 char super
[MIME_MAX_SUPER
],
10853 /* Supertype of file */
10854 type
[MIME_MAX_TYPE
];
10855 /* Subtype of file */
10856 cupsd_printer_t
*printer
; /* Printer */
10859 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
10860 con
->number
, uri
->values
[0].string
.text
);
10863 * OK, see if the client is sending the document compressed - CUPS
10864 * doesn't support compression yet...
10867 if ((attr
= ippFindAttribute(con
->request
, "compression",
10868 IPP_TAG_KEYWORD
)) != NULL
)
10870 if (strcmp(attr
->values
[0].string
.text
, "none")
10872 && strcmp(attr
->values
[0].string
.text
, "gzip")
10873 #endif /* HAVE_LIBZ */
10876 send_ipp_status(con
, IPP_ATTRIBUTES
,
10877 _("Unsupported 'compression' value \"%s\"."),
10878 attr
->values
[0].string
.text
);
10879 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
10880 "compression", NULL
, attr
->values
[0].string
.text
);
10886 * Is it a format we support?
10889 if ((format
= ippFindAttribute(con
->request
, "document-format",
10890 IPP_TAG_MIMETYPE
)) != NULL
)
10892 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
10895 send_ipp_status(con
, IPP_BAD_REQUEST
,
10896 _("Bad 'document-format' value \"%s\"."),
10897 format
->values
[0].string
.text
);
10901 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
10902 !mimeType(MimeDatabase
, super
, type
))
10904 cupsdLogMessage(CUPSD_LOG_INFO
,
10905 "Hint: Do you have the raw file printing rules enabled?");
10906 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
10907 _("Unsupported 'document-format' value \"%s\"."),
10908 format
->values
[0].string
.text
);
10909 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
10910 "document-format", NULL
, format
->values
[0].string
.text
);
10916 * Is the job-name valid?
10919 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
10921 int bad_name
= 0; /* Is the job-name value bad? */
10923 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
10924 name
->num_values
!= 1)
10931 * Validate that job-name conforms to RFC 5198 (Network Unicode) and
10932 * IPP Everywhere requirements for "name" values...
10935 const unsigned char *nameptr
; /* Pointer into "job-name" attribute */
10937 for (nameptr
= (unsigned char *)name
->values
[0].string
.text
;
10941 if (*nameptr
< ' ' && *nameptr
!= '\t')
10943 else if (*nameptr
== 0x7f)
10945 else if ((*nameptr
& 0xe0) == 0xc0)
10947 if ((nameptr
[1] & 0xc0) != 0x80)
10952 else if ((*nameptr
& 0xf0) == 0xe0)
10954 if ((nameptr
[1] & 0xc0) != 0x80 ||
10955 (nameptr
[2] & 0xc0) != 0x80)
10960 else if ((*nameptr
& 0xf8) == 0xf0)
10962 if ((nameptr
[1] & 0xc0) != 0x80 ||
10963 (nameptr
[2] & 0xc0) != 0x80 ||
10964 (nameptr
[3] & 0xc0) != 0x80)
10969 else if (*nameptr
& 0x80)
10979 if (StrictConformance
)
10981 send_ipp_status(con
, IPP_ATTRIBUTES
,
10982 _("Unsupported 'job-name' value."));
10983 ippCopyAttribute(con
->response
, name
, 0);
10988 cupsdLogMessage(CUPSD_LOG_WARN
,
10989 "Unsupported 'job-name' value, deleting from request.");
10990 ippDeleteAttribute(con
->request
, name
);
10996 * Is the destination valid?
10999 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11005 send_ipp_status(con
, IPP_NOT_FOUND
,
11006 _("The printer or class does not exist."));
11015 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11016 #endif /* HAVE_SSL */
11018 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11020 send_http_error(con
, status
, printer
);
11023 else if (printer
->num_auth_info_required
== 1 &&
11024 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11027 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11031 else if (auth_info
&& !con
->http
->tls
&&
11032 !httpAddrLocalhost(con
->http
->hostaddr
))
11035 * Require encryption of auth-info over non-local connections...
11038 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11041 #endif /* HAVE_SSL */
11044 * Everything was ok, so return OK status...
11047 con
->response
->request
.status
.status_code
= IPP_OK
;
11052 * 'validate_name()' - Make sure the printer name only contains valid chars.
11055 static int /* O - 0 if name is no good, 1 if good */
11056 validate_name(const char *name
) /* I - Name to check */
11058 const char *ptr
; /* Pointer into name */
11062 * Scan the whole name...
11065 for (ptr
= name
; *ptr
; ptr
++)
11066 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11070 * All the characters are good; validate the length, too...
11073 return ((ptr
- name
) < 128);
11078 * 'validate_user()' - Validate the user for the request.
11081 static int /* O - 1 if permitted, 0 otherwise */
11082 validate_user(cupsd_job_t
*job
, /* I - Job */
11083 cupsd_client_t
*con
, /* I - Client connection */
11084 const char *owner
, /* I - Owner of job/resource */
11085 char *username
, /* O - Authenticated username */
11086 size_t userlen
) /* I - Length of username */
11088 cupsd_printer_t
*printer
; /* Printer for job */
11091 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, userlen=" CUPS_LLFMT
")", job
->id
, con
? con
->number
: 0, owner
? owner
: "(null)", username
, CUPS_LLCAST userlen
);
11094 * Validate input...
11097 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11101 * Get the best authenticated username that is available.
11104 strlcpy(username
, get_username(con
), userlen
);
11107 * Check the username against the owner...
11110 printer
= cupsdFindDest(job
->dest
);
11112 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11113 con
, owner
) == HTTP_OK
);