2 * IPP routines for the CUPS scheduler.
4 * Copyright © 2007-2019 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7 * This file contains Kerberos support code, copyright 2006 by
10 * Licensed under Apache License v2.0. See the file "LICENSE" for more
15 * Include necessary headers...
19 #include <cups/ppd-private.h>
22 /*# include <ApplicationServices/ApplicationServices.h>
23 extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
24 # include <CoreFoundation/CoreFoundation.h>*/
25 # ifdef HAVE_MEMBERSHIP_H
26 # include <membership.h>
27 # endif /* HAVE_MEMBERSHIP_H */
28 # ifdef HAVE_MEMBERSHIPPRIV_H
29 # include <membershipPriv.h>
31 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
32 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
33 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
34 # endif /* HAVE_MEMBERSHIPPRIV_H */
35 #endif /* __APPLE__ */
42 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
43 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
44 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
45 mime_type_t
*filetype
, int compression
);
46 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
47 mime_type_t
*filetype
);
48 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
49 static void add_job_uuid(cupsd_job_t
*job
);
50 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
51 static void add_printer_state_reasons(cupsd_client_t
*con
,
53 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
54 static void apply_printer_defaults(cupsd_printer_t
*printer
,
56 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
57 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
58 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
59 static void cancel_subscription(cupsd_client_t
*con
, int id
);
60 static int check_rss_recipient(const char *recipient
);
61 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
62 static void close_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
63 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
64 ipp_tag_t group
, int quickcopy
,
65 cups_array_t
*exclude
);
66 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
68 static int copy_file(const char *from
, const char *to
, mode_t mode
);
69 static int copy_model(cupsd_client_t
*con
, const char *from
,
71 static void copy_job_attrs(cupsd_client_t
*con
,
73 cups_array_t
*ra
, cups_array_t
*exclude
);
74 static void copy_printer_attrs(cupsd_client_t
*con
,
75 cupsd_printer_t
*printer
,
77 static void copy_subscription_attrs(cupsd_client_t
*con
,
78 cupsd_subscription_t
*sub
,
80 cups_array_t
*exclude
);
81 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
82 static void create_local_printer(cupsd_client_t
*con
);
83 static cups_array_t
*create_requested_array(ipp_t
*request
);
84 static void create_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
85 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
86 static void get_default(cupsd_client_t
*con
);
87 static void get_devices(cupsd_client_t
*con
);
88 static void get_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
89 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
90 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
91 static void get_notifications(cupsd_client_t
*con
);
92 static void get_ppd(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
93 static void get_ppds(cupsd_client_t
*con
);
94 static void get_printers(cupsd_client_t
*con
, int type
);
95 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
96 static void get_printer_supported(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
97 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
98 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
99 static const char *get_username(cupsd_client_t
*con
);
100 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
101 static void hold_new_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
102 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
103 static int ppd_parse_line(const char *line
, char *option
, int olen
,
104 char *choice
, int clen
);
105 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
106 static void read_job_ticket(cupsd_client_t
*con
);
107 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
108 static void release_held_new_jobs(cupsd_client_t
*con
,
109 ipp_attribute_t
*uri
);
110 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
111 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
112 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
113 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
114 ipp_attribute_t
*auth_info
);
115 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
116 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
117 cupsd_printer_t
*printer
);
118 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
, const char *message
, ...) _CUPS_FORMAT(3, 4);
119 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
120 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
121 static void set_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
122 static int set_printer_defaults(cupsd_client_t
*con
, cupsd_printer_t
*printer
);
123 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
124 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
125 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
, size_t bufsize
);
126 static char *url_encode_string(const char *s
, char *buffer
, size_t bufsize
);
127 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
128 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
129 static int validate_name(const char *name
);
130 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
, const char *owner
, char *username
, size_t userlen
);
134 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request.
137 int /* O - 1 on success, 0 on failure */
138 cupsdProcessIPPRequest(
139 cupsd_client_t
*con
) /* I - Client connection */
141 ipp_tag_t group
; /* Current group tag */
142 ipp_attribute_t
*attr
; /* Current attribute */
143 ipp_attribute_t
*charset
; /* Character set attribute */
144 ipp_attribute_t
*language
; /* Language attribute */
145 ipp_attribute_t
*uri
= NULL
; /* Printer or job URI attribute */
146 ipp_attribute_t
*username
; /* requesting-user-name attr */
147 int sub_id
; /* Subscription ID */
148 int valid
= 1; /* Valid request? */
151 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest(%p[%d]): operation_id=%04x(%s)", con
, con
->number
, con
->request
->request
.op
.operation_id
, ippOpString(con
->request
->request
.op
.operation_id
));
153 if (LogLevel
>= CUPSD_LOG_DEBUG2
)
155 for (group
= IPP_TAG_ZERO
, attr
= ippFirstAttribute(con
->request
); attr
; attr
= ippNextAttribute(con
->request
))
157 const char *name
; /* Attribute name */
158 char value
[1024]; /* Attribute value */
160 if (group
!= ippGetGroupTag(attr
))
162 group
= ippGetGroupTag(attr
);
163 if (group
!= IPP_TAG_ZERO
)
164 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s", ippTagString(group
));
167 if ((name
= ippGetName(attr
)) == NULL
)
170 ippAttributeString(attr
, value
, sizeof(value
));
172 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdProcessIPPRequest: %s %s%s '%s'", name
, ippGetCount(attr
) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attr
)), value
);
177 * First build an empty response message for this request...
180 con
->response
= ippNew();
182 con
->response
->request
.status
.version
[0] = con
->request
->request
.op
.version
[0];
183 con
->response
->request
.status
.version
[1] = con
->request
->request
.op
.version
[1];
184 con
->response
->request
.status
.request_id
= con
->request
->request
.op
.request_id
;
187 * Then validate the request header and required attributes...
190 if (con
->request
->request
.any
.version
[0] != 1 && con
->request
->request
.any
.version
[0] != 2)
193 * Return an error, since we only support IPP 1.x and 2.x.
196 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Bad request version number %d.%d.", IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
, con
->http
->hostname
, con
->request
->request
.any
.version
[0], con
->request
->request
.any
.version
[1]);
198 send_ipp_status(con
, IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
, _("Bad request version number %d.%d."), con
->request
->request
.any
.version
[0], con
->request
->request
.any
.version
[1]);
200 else if (con
->request
->request
.any
.request_id
< 1)
203 * Return an error, since request IDs must be between 1 and 2^31-1
206 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Bad request ID %d.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
, con
->request
->request
.any
.request_id
);
208 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Bad request ID %d."), con
->request
->request
.any
.request_id
);
210 else if (!con
->request
->attrs
)
212 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s No attributes in request.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
214 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("No attributes in request."));
219 * Make sure that the attributes are provided in the correct order and
220 * don't repeat groups...
223 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
226 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
229 * Out of order; return an error...
232 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Attribute groups are out of order", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
234 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute groups are out of order (%x < %x)."), attr
->group_tag
, group
);
238 group
= attr
->group_tag
;
243 * Then make sure that the first three attributes are:
246 * attributes-natural-language
247 * printer-uri/job-uri
250 attr
= con
->request
->attrs
;
251 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-charset") && (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
&& attr
->group_tag
== IPP_TAG_OPERATION
)
259 if (attr
&& attr
->name
&& !strcmp(attr
->name
, "attributes-natural-language") && (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
&& attr
->group_tag
== IPP_TAG_OPERATION
)
264 * Reset language for this request if different from Accept-Language.
267 if (!con
->language
||
268 strcmp(attr
->values
[0].string
.text
, con
->language
->language
))
270 cupsLangFree(con
->language
);
271 con
->language
= cupsLangGet(attr
->values
[0].string
.text
);
277 if ((attr
= ippFindAttribute(con
->request
, "printer-uri", IPP_TAG_URI
)) != NULL
&& attr
->group_tag
== IPP_TAG_OPERATION
)
279 else if ((attr
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
)) != NULL
&& attr
->group_tag
== IPP_TAG_OPERATION
)
281 else if (con
->request
->request
.op
.operation_id
== CUPS_GET_PPD
&& (attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
&& attr
->group_tag
== IPP_TAG_OPERATION
)
287 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", NULL
, charset
->values
[0].string
.text
);
289 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
, "attributes-charset", NULL
, "utf-8");
292 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", NULL
, language
->values
[0].string
.text
);
294 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
, "attributes-natural-language", NULL
, DefaultLanguage
);
296 if (charset
&& _cups_strcasecmp(charset
->values
[0].string
.text
, "us-ascii") && _cups_strcasecmp(charset
->values
[0].string
.text
, "utf-8"))
299 * Bad character set...
302 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unsupported character set \"%s\"",
303 charset
->values
[0].string
.text
);
304 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Unsupported attributes-charset value \"%s\".", IPP_STATUS_ERROR_CHARSET
, con
->http
->hostname
, charset
->values
[0].string
.text
);
305 send_ipp_status(con
, IPP_STATUS_ERROR_CHARSET
, _("Unsupported character set \"%s\"."), charset
->values
[0].string
.text
);
307 else if (!charset
|| !language
||
309 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
310 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
311 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
312 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
313 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
316 * Return an error, since attributes-charset,
317 * attributes-natural-language, and printer-uri/job-uri are required
318 * for all operations.
323 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing attributes-charset attribute.");
325 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing attributes-charset attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
330 cupsdLogMessage(CUPSD_LOG_ERROR
,
331 "Missing attributes-natural-language attribute.");
333 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing attributes-natural-language attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
338 cupsdLogMessage(CUPSD_LOG_ERROR
, "Missing printer-uri, job-uri, or ppd-name attribute.");
340 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Missing printer-uri, job-uri, or ppd-name attribute.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
343 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
345 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
346 cupsdLogMessage(CUPSD_LOG_DEBUG
,
347 "attr \"%s\": group_tag = %x, value_tag = %x",
348 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
351 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
353 send_ipp_status(con
, IPP_BAD_REQUEST
,
354 _("Missing required attributes."));
359 * OK, all the checks pass so far; validate "requesting-user-name"
363 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_ZERO
)) != NULL
)
366 * Validate "requesting-user-name"...
369 if (username
->group_tag
!= IPP_TAG_OPERATION
&& StrictConformance
)
371 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s \"requesting-user-name\" attribute in wrong group.", IPP_STATUS_ERROR_BAD_REQUEST
, con
->http
->hostname
);
372 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("\"requesting-user-name\" attribute in wrong group."));
375 else if (username
->value_tag
!= IPP_TAG_NAME
&& username
->value_tag
!= IPP_TAG_NAMELANG
)
377 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s \"requesting-user-name\" attribute with wrong syntax.", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, con
->http
->hostname
);
378 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("\"requesting-user-name\" attribute with wrong syntax."));
379 if ((attr
= ippCopyAttribute(con
->response
, username
, 0)) != NULL
)
380 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
383 else if (!ippValidateAttribute(username
))
385 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s \"requesting-user-name\" attribute with bad value.", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, con
->http
->hostname
);
387 if (StrictConformance
)
393 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("\"requesting-user-name\" attribute with wrong syntax."));
394 if ((attr
= ippCopyAttribute(con
->response
, username
, 0)) != NULL
)
395 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
401 * Map bad "requesting-user-name" to 'anonymous'...
404 ippSetString(con
->request
, &username
, 0, "anonymous");
407 else if (!strcmp(username
->values
[0].string
.text
, "root") && _cups_strcasecmp(con
->http
->hostname
, "localhost") && strcmp(con
->username
, "root"))
410 * Remote unauthenticated user masquerading as local root...
413 ippSetString(con
->request
, &username
, 0, RemoteRoot
);
417 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id", IPP_TAG_INTEGER
)) != NULL
)
418 sub_id
= attr
->values
[0].integer
;
425 * Try processing the operation...
429 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s", ippOpString(con
->request
->request
.op
.operation_id
), uri
->values
[0].string
.text
);
431 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s", ippOpString(con
->request
->request
.op
.operation_id
));
433 switch (con
->request
->request
.op
.operation_id
)
435 case IPP_OP_PRINT_JOB
:
439 case IPP_OP_VALIDATE_JOB
:
440 validate_job(con
, uri
);
443 case IPP_OP_CREATE_JOB
:
444 create_job(con
, uri
);
447 case IPP_OP_SEND_DOCUMENT
:
448 send_document(con
, uri
);
451 case IPP_OP_CANCEL_JOB
:
452 cancel_job(con
, uri
);
455 case IPP_OP_GET_JOB_ATTRIBUTES
:
456 get_job_attrs(con
, uri
);
459 case IPP_OP_GET_JOBS
:
463 case IPP_OP_GET_PRINTER_ATTRIBUTES
:
464 get_printer_attrs(con
, uri
);
467 case IPP_OP_GET_PRINTER_SUPPORTED_VALUES
:
468 get_printer_supported(con
, uri
);
471 case IPP_OP_HOLD_JOB
:
475 case IPP_OP_RELEASE_JOB
:
476 release_job(con
, uri
);
479 case IPP_OP_RESTART_JOB
:
480 restart_job(con
, uri
);
483 case IPP_OP_PAUSE_PRINTER
:
484 stop_printer(con
, uri
);
487 case IPP_OP_RESUME_PRINTER
:
488 start_printer(con
, uri
);
491 case IPP_OP_PURGE_JOBS
:
492 case IPP_OP_CANCEL_JOBS
:
493 case IPP_OP_CANCEL_MY_JOBS
:
494 cancel_all_jobs(con
, uri
);
497 case IPP_OP_SET_JOB_ATTRIBUTES
:
498 set_job_attrs(con
, uri
);
501 case IPP_OP_SET_PRINTER_ATTRIBUTES
:
502 set_printer_attrs(con
, uri
);
505 case IPP_OP_HOLD_NEW_JOBS
:
506 hold_new_jobs(con
, uri
);
509 case IPP_OP_RELEASE_HELD_NEW_JOBS
:
510 release_held_new_jobs(con
, uri
);
513 case IPP_OP_CLOSE_JOB
:
517 case IPP_OP_CUPS_GET_DEFAULT
:
521 case IPP_OP_CUPS_GET_PRINTERS
:
522 get_printers(con
, 0);
525 case IPP_OP_CUPS_GET_CLASSES
:
526 get_printers(con
, CUPS_PRINTER_CLASS
);
529 case IPP_OP_CUPS_ADD_MODIFY_PRINTER
:
530 add_printer(con
, uri
);
533 case IPP_OP_CUPS_DELETE_PRINTER
:
534 delete_printer(con
, uri
);
537 case IPP_OP_CUPS_ADD_MODIFY_CLASS
:
541 case IPP_OP_CUPS_DELETE_CLASS
:
542 delete_printer(con
, uri
);
545 case IPP_OP_CUPS_ACCEPT_JOBS
:
546 case IPP_OP_ENABLE_PRINTER
:
547 accept_jobs(con
, uri
);
550 case IPP_OP_CUPS_REJECT_JOBS
:
551 case IPP_OP_DISABLE_PRINTER
:
552 reject_jobs(con
, uri
);
555 case IPP_OP_CUPS_SET_DEFAULT
:
556 set_default(con
, uri
);
559 case IPP_OP_CUPS_GET_DEVICES
:
563 case IPP_OP_CUPS_GET_DOCUMENT
:
564 get_document(con
, uri
);
567 case IPP_OP_CUPS_GET_PPD
:
571 case IPP_OP_CUPS_GET_PPDS
:
575 case IPP_OP_CUPS_MOVE_JOB
:
579 case IPP_OP_CUPS_AUTHENTICATE_JOB
:
580 authenticate_job(con
, uri
);
583 case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
:
584 case IPP_OP_CREATE_JOB_SUBSCRIPTIONS
:
585 create_subscriptions(con
, uri
);
588 case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
:
589 get_subscription_attrs(con
, sub_id
);
592 case IPP_OP_GET_SUBSCRIPTIONS
:
593 get_subscriptions(con
, uri
);
596 case IPP_OP_RENEW_SUBSCRIPTION
:
597 renew_subscription(con
, sub_id
);
600 case IPP_OP_CANCEL_SUBSCRIPTION
:
601 cancel_subscription(con
, sub_id
);
604 case IPP_OP_GET_NOTIFICATIONS
:
605 get_notifications(con
);
608 case IPP_OP_CUPS_CREATE_LOCAL_PRINTER
:
609 create_local_printer(con
);
613 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
, "%04X %s Operation %04X (%s) not supported.", IPP_STATUS_ERROR_OPERATION_NOT_SUPPORTED
, con
->http
->hostname
, con
->request
->request
.op
.operation_id
, ippOpString(con
->request
->request
.op
.operation_id
));
615 send_ipp_status(con
, IPP_STATUS_ERROR_OPERATION_NOT_SUPPORTED
, _("%s not supported."), ippOpString(con
->request
->request
.op
.operation_id
));
626 * Sending data from the scheduler...
629 cupsdLogClient(con
, con
->response
->request
.status
.status_code
>= IPP_STATUS_ERROR_BAD_REQUEST
&& con
->response
->request
.status
.status_code
!= IPP_STATUS_ERROR_NOT_FOUND
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
, "Returning IPP %s for %s (%s) from %s.", ippErrorString(con
->response
->request
.status
.status_code
), ippOpString(con
->request
->request
.op
.operation_id
), uri
? uri
->values
[0].string
.text
: "no URI", con
->http
->hostname
);
631 httpClearFields(con
->http
);
633 #ifdef CUPSD_USE_CHUNKING
635 * Because older versions of CUPS (1.1.17 and older) and some IPP
636 * clients do not implement chunking properly, we cannot use
637 * chunking by default. This may become the default in future
638 * CUPS releases, or we might add a configuration directive for
642 if (con
->http
->version
== HTTP_1_1
)
644 cupsdLogClient(con
, CUPSD_LOG_DEBUG
, "Transfer-Encoding: chunked");
645 cupsdSetLength(con
->http
, 0);
648 #endif /* CUPSD_USE_CHUNKING */
650 size_t length
; /* Length of response */
653 length
= ippLength(con
->response
);
655 if (con
->file
>= 0 && !con
->pipe_pid
)
657 struct stat fileinfo
; /* File information */
659 if (!fstat(con
->file
, &fileinfo
))
660 length
+= (size_t)fileinfo
.st_size
;
663 cupsdLogClient(con
, CUPSD_LOG_DEBUG
, "Content-Length: " CUPS_LLFMT
, CUPS_LLCAST length
);
664 httpSetLength(con
->http
, length
);
667 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", CUPSD_AUTH_NONE
))
670 * Tell the caller the response header was sent successfully...
673 cupsdAddSelect(httpGetFd(con
->http
), (cupsd_selfunc_t
)cupsdReadClient
, (cupsd_selfunc_t
)cupsdWriteClient
, con
);
680 * Tell the caller the response header could not be sent...
689 * Sending data from a subprocess like cups-deviced; tell the caller
690 * everything is A-OK so far...
699 * 'cupsdTimeoutJob()' - Timeout a job waiting on job files.
702 int /* O - 0 on success, -1 on error */
703 cupsdTimeoutJob(cupsd_job_t
*job
) /* I - Job to timeout */
705 cupsd_printer_t
*printer
; /* Destination printer or class */
706 ipp_attribute_t
*attr
; /* job-sheets attribute */
707 int kbytes
; /* Kilobytes in banner */
710 job
->pending_timeout
= 0;
713 * See if we need to add the ending sheet...
716 if (!cupsdLoadJob(job
))
719 printer
= cupsdFindDest(job
->dest
);
720 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
722 if (printer
&& !(printer
->type
& CUPS_PRINTER_REMOTE
) &&
723 attr
&& attr
->num_values
> 1)
729 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding end banner page \"%s\".",
730 attr
->values
[1].string
.text
);
732 if ((kbytes
= copy_banner(NULL
, job
, attr
->values
[1].string
.text
)) < 0)
735 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
743 * 'accept_jobs()' - Accept print jobs to a printer.
747 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
748 ipp_attribute_t
*uri
) /* I - Printer or class URI */
750 http_status_t status
; /* Policy status */
751 cups_ptype_t dtype
; /* Destination type (printer/class) */
752 cupsd_printer_t
*printer
; /* Printer data */
755 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
756 con
->number
, uri
->values
[0].string
.text
);
759 * Is the destination valid?
762 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
768 send_ipp_status(con
, IPP_NOT_FOUND
,
769 _("The printer or class does not exist."));
777 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
779 send_http_error(con
, status
, printer
);
784 * Accept jobs sent to the printer...
787 printer
->accepting
= 1;
788 printer
->state_message
[0] = '\0';
790 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
791 "Now accepting jobs.");
793 if (dtype
& CUPS_PRINTER_CLASS
)
795 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
797 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
798 printer
->name
, get_username(con
));
802 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
804 cupsdLogMessage(CUPSD_LOG_INFO
,
805 "Printer \"%s\" now accepting jobs (\"%s\").",
806 printer
->name
, get_username(con
));
810 * Everything was ok, so return OK status...
813 con
->response
->request
.status
.status_code
= IPP_OK
;
818 * 'add_class()' - Add a class to the system.
822 add_class(cupsd_client_t
*con
, /* I - Client connection */
823 ipp_attribute_t
*uri
) /* I - URI of class */
825 http_status_t status
; /* Policy status */
826 int i
; /* Looping var */
827 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
828 username
[HTTP_MAX_URI
], /* Username portion of URI */
829 host
[HTTP_MAX_URI
], /* Host portion of URI */
830 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
831 int port
; /* Port portion of URI */
832 cupsd_printer_t
*pclass
, /* Class */
833 *member
; /* Member printer/class */
834 cups_ptype_t dtype
; /* Destination type */
835 ipp_attribute_t
*attr
; /* Printer attribute */
836 int modify
; /* Non-zero if we just modified */
837 int need_restart_job
; /* Need to restart job? */
840 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
841 con
->number
, uri
->values
[0].string
.text
);
844 * Do we have a valid URI?
847 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
848 sizeof(scheme
), username
, sizeof(username
), host
,
849 sizeof(host
), &port
, resource
, sizeof(resource
));
852 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
855 * No, return an error...
858 send_ipp_status(con
, IPP_BAD_REQUEST
,
859 _("The printer-uri must be of the form "
860 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
865 * Do we have a valid printer name?
868 if (!validate_name(resource
+ 9))
871 * No, return an error...
874 send_ipp_status(con
, IPP_BAD_REQUEST
,
875 _("The printer-uri \"%s\" contains invalid characters."),
876 uri
->values
[0].string
.text
);
881 * See if the class already exists; if not, create a new class...
884 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
887 * Class doesn't exist; see if we have a printer of the same name...
890 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
)
893 * Yes, return an error...
896 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
897 _("A printer named \"%s\" already exists."),
903 * No, check the default policy and then add the class...
906 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
908 send_http_error(con
, status
, NULL
);
912 pclass
= cupsdAddClass(resource
+ 9);
915 pclass
->printer_id
= NextPrinterId
++;
917 else if ((status
= cupsdCheckPolicy(pclass
->op_policy_ptr
, con
,
920 send_http_error(con
, status
, pclass
);
927 * Look for attributes and copy them over as needed...
930 need_restart_job
= 0;
932 if ((attr
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
933 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
935 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
936 cupsdSetString(&pclass
->geo_location
, attr
->values
[0].string
.text
);
938 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
939 cupsdSetString(&pclass
->organization
, attr
->values
[0].string
.text
);
941 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
942 cupsdSetString(&pclass
->organizational_unit
, attr
->values
[0].string
.text
);
944 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
945 IPP_TAG_TEXT
)) != NULL
)
946 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
948 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
949 IPP_TAG_BOOLEAN
)) != NULL
&&
950 attr
->values
[0].boolean
!= pclass
->accepting
)
952 cupsdLogMessage(CUPSD_LOG_INFO
,
953 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
954 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
956 pclass
->accepting
= attr
->values
[0].boolean
;
958 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s accepting jobs.",
959 pclass
->accepting
? "Now" : "No longer");
962 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
964 if (pclass
->type
& CUPS_PRINTER_REMOTE
)
967 * Cannot re-share remote printers.
970 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
972 cupsdDeletePrinter(pclass
, 0);
977 if (pclass
->shared
&& !ippGetBoolean(attr
, 0))
978 cupsdDeregisterPrinter(pclass
, 1);
980 cupsdLogMessage(CUPSD_LOG_INFO
,
981 "Setting %s printer-is-shared to %d (was %d.)",
982 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
984 pclass
->shared
= ippGetBoolean(attr
, 0);
987 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
988 IPP_TAG_ENUM
)) != NULL
)
990 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
991 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
993 send_ipp_status(con
, IPP_BAD_REQUEST
,
994 _("Attempt to set %s printer-state to bad value %d."),
995 pclass
->name
, attr
->values
[0].integer
);
997 cupsdDeletePrinter(pclass
, 0);
1002 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
1003 pclass
->name
, attr
->values
[0].integer
, pclass
->state
);
1005 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1006 cupsdStopPrinter(pclass
, 0);
1009 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1010 need_restart_job
= 1;
1013 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1014 IPP_TAG_TEXT
)) != NULL
)
1016 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
1017 sizeof(pclass
->state_message
));
1019 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, pclass
, NULL
, "%s",
1020 pclass
->state_message
);
1022 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1023 IPP_TAG_URI
)) != NULL
)
1026 * Clear the printer array as needed...
1029 need_restart_job
= 1;
1031 if (pclass
->num_printers
> 0)
1033 free(pclass
->printers
);
1034 pclass
->num_printers
= 0;
1038 * Add each printer or class that is listed...
1041 for (i
= 0; i
< attr
->num_values
; i
++)
1044 * Search for the printer or class URI...
1047 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1053 send_ipp_status(con
, IPP_NOT_FOUND
,
1054 _("The printer or class does not exist."));
1056 cupsdDeletePrinter(pclass
, 0);
1060 else if (dtype
& CUPS_PRINTER_CLASS
)
1062 send_ipp_status(con
, IPP_BAD_REQUEST
,
1063 _("Nested classes are not allowed."));
1065 cupsdDeletePrinter(pclass
, 0);
1071 * Add it to the class...
1074 cupsdAddPrinterToClass(pclass
, member
);
1078 if (!set_printer_defaults(con
, pclass
))
1081 cupsdDeletePrinter(pclass
, 0);
1086 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
1087 IPP_TAG_KEYWORD
)) != NULL
)
1088 cupsdSetAuthInfoRequired(pclass
, NULL
, attr
);
1090 pclass
->config_time
= time(NULL
);
1093 * Update the printer class attributes and return...
1096 cupsdSetPrinterAttrs(pclass
);
1097 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
1099 if (need_restart_job
&& pclass
->job
)
1102 * Reset the current job to a "pending" status...
1105 cupsdSetJobState(pclass
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
1106 "Job restarted because the class was modified.");
1109 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
1113 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
1114 pclass
, NULL
, "Class \"%s\" modified by \"%s\".",
1115 pclass
->name
, get_username(con
));
1117 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1118 pclass
->name
, get_username(con
));
1122 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
1123 pclass
, NULL
, "New class \"%s\" added by \"%s\".",
1124 pclass
->name
, get_username(con
));
1126 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1127 pclass
->name
, get_username(con
));
1130 con
->response
->request
.status
.status_code
= IPP_OK
;
1135 * 'add_file()' - Add a file to a job.
1138 static int /* O - 0 on success, -1 on error */
1139 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1140 cupsd_job_t
*job
, /* I - Job to add to */
1141 mime_type_t
*filetype
, /* I - Type of file */
1142 int compression
) /* I - Compression */
1144 mime_type_t
**filetypes
; /* New filetypes array... */
1145 int *compressions
; /* New compressions array... */
1148 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1149 "add_file(con=%p[%d], job=%d, filetype=%s/%s, "
1150 "compression=%d)", con
, con
? con
->number
: -1, job
->id
,
1151 filetype
->super
, filetype
->type
, compression
);
1154 * Add the file to the job...
1157 if (job
->num_files
== 0)
1159 compressions
= (int *)malloc(sizeof(int));
1160 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1164 compressions
= (int *)realloc(job
->compressions
,
1165 (size_t)(job
->num_files
+ 1) * sizeof(int));
1166 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1167 (size_t)(job
->num_files
+ 1) *
1168 sizeof(mime_type_t
*));
1172 job
->compressions
= compressions
;
1175 job
->filetypes
= filetypes
;
1177 if (!compressions
|| !filetypes
)
1179 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1180 "Job aborted because the scheduler ran out of memory.");
1183 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1184 _("Unable to allocate memory for file types."));
1189 job
->compressions
[job
->num_files
] = compression
;
1190 job
->filetypes
[job
->num_files
] = filetype
;
1195 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1202 * 'add_job()' - Add a job to a print queue.
1205 static cupsd_job_t
* /* O - Job object */
1206 add_job(cupsd_client_t
*con
, /* I - Client connection */
1207 cupsd_printer_t
*printer
, /* I - Destination printer */
1208 mime_type_t
*filetype
) /* I - First print file type, if any */
1210 http_status_t status
; /* Policy status */
1211 ipp_attribute_t
*attr
, /* Current attribute */
1212 *auth_info
; /* auth-info attribute */
1213 const char *mandatory
; /* Current mandatory job attribute */
1214 const char *val
; /* Default option value */
1215 int priority
; /* Job priority */
1216 cupsd_job_t
*job
; /* Current job */
1217 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1218 int kbytes
; /* Size of print file */
1219 int i
; /* Looping var */
1220 int lowerpagerange
; /* Page range bound */
1221 int exact
; /* Did we have an exact match? */
1222 ipp_attribute_t
*media_col
, /* media-col attribute */
1223 *media_margin
; /* media-*-margin attribute */
1224 ipp_t
*unsup_col
; /* media-col in unsupported response */
1225 static const char * const readonly
[] =/* List of read-only attributes */
1227 "date-time-at-completed",
1228 "date-time-at-creation",
1229 "date-time-at-processing",
1230 "job-detailed-status-messages",
1231 "job-document-access-errors",
1233 "job-impressions-completed",
1234 "job-k-octets-completed",
1235 "job-media-sheets-completed",
1236 "job-pages-completed",
1237 "job-printer-up-time",
1240 "job-state-message",
1241 "job-state-reasons",
1243 "number-of-documents",
1244 "number-of-intervening-jobs",
1245 "output-device-assigned",
1246 "time-at-completed",
1248 "time-at-processing"
1252 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1253 con
, con
->number
, printer
, printer
->name
,
1254 filetype
, filetype
? filetype
->super
: "none",
1255 filetype
? filetype
->type
: "none");
1258 * Check remote printing to non-shared printer...
1261 if (!printer
->shared
&&
1262 _cups_strcasecmp(con
->http
->hostname
, "localhost") &&
1263 _cups_strcasecmp(con
->http
->hostname
, ServerName
))
1265 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1266 _("The printer or class is not shared."));
1274 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1276 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1278 send_http_error(con
, status
, printer
);
1281 else if (printer
->num_auth_info_required
== 1 &&
1282 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
1285 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1289 else if (auth_info
&& !con
->http
->tls
&&
1290 !httpAddrLocalhost(con
->http
->hostaddr
))
1293 * Require encryption of auth-info over non-local connections...
1296 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1299 #endif /* HAVE_SSL */
1302 * See if the printer is accepting jobs...
1305 if (!printer
->accepting
)
1307 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1308 _("Destination \"%s\" is not accepting jobs."),
1314 * Validate job template attributes; for now just document-format,
1315 * copies, job-sheets, number-up, page-ranges, mandatory attributes, and
1319 for (i
= 0; i
< (int)(sizeof(readonly
) / sizeof(readonly
[0])); i
++)
1321 if ((attr
= ippFindAttribute(con
->request
, readonly
[i
], IPP_TAG_ZERO
)) != NULL
)
1323 ippDeleteAttribute(con
->request
, attr
);
1325 if (StrictConformance
)
1327 send_ipp_status(con
, IPP_BAD_REQUEST
, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly
[i
]);
1331 cupsdLogMessage(CUPSD_LOG_INFO
, "Unexpected '%s' Job Status attribute in a job creation request.", readonly
[i
]);
1337 for (mandatory
= (char *)cupsArrayFirst(printer
->pc
->mandatory
);
1339 mandatory
= (char *)cupsArrayNext(printer
->pc
->mandatory
))
1341 if (!ippFindAttribute(con
->request
, mandatory
, IPP_TAG_ZERO
))
1344 * Missing a required attribute...
1347 send_ipp_status(con
, IPP_CONFLICT
,
1348 _("The \"%s\" attribute is required for print jobs."),
1355 if (filetype
&& printer
->filetypes
&&
1356 !cupsArrayFind(printer
->filetypes
, filetype
))
1358 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1359 /* MIME media type string */
1362 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1365 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1366 _("Unsupported format \"%s\"."), mimetype
);
1368 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1369 "document-format", NULL
, mimetype
);
1374 if ((attr
= ippFindAttribute(con
->request
, "copies",
1375 IPP_TAG_INTEGER
)) != NULL
)
1377 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1379 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1380 attr
->values
[0].integer
);
1381 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1382 "copies", attr
->values
[0].integer
);
1387 if ((attr
= ippFindAttribute(con
->request
, "job-sheets",
1388 IPP_TAG_ZERO
)) != NULL
)
1390 if (attr
->value_tag
!= IPP_TAG_KEYWORD
&&
1391 attr
->value_tag
!= IPP_TAG_NAME
)
1393 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value type."));
1397 if (attr
->num_values
> 2)
1399 send_ipp_status(con
, IPP_BAD_REQUEST
,
1400 _("Too many job-sheets values (%d > 2)."),
1405 for (i
= 0; i
< attr
->num_values
; i
++)
1406 if (strcmp(attr
->values
[i
].string
.text
, "none") &&
1407 !cupsdFindBanner(attr
->values
[i
].string
.text
))
1409 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-sheets value \"%s\"."),
1410 attr
->values
[i
].string
.text
);
1415 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1416 IPP_TAG_INTEGER
)) != NULL
)
1418 if (attr
->values
[0].integer
!= 1 &&
1419 attr
->values
[0].integer
!= 2 &&
1420 attr
->values
[0].integer
!= 4 &&
1421 attr
->values
[0].integer
!= 6 &&
1422 attr
->values
[0].integer
!= 9 &&
1423 attr
->values
[0].integer
!= 16)
1425 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1426 attr
->values
[0].integer
);
1427 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1428 "number-up", attr
->values
[0].integer
);
1433 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1434 IPP_TAG_RANGE
)) != NULL
)
1436 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1438 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1439 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1441 send_ipp_status(con
, IPP_BAD_REQUEST
,
1442 _("Bad page-ranges values %d-%d."),
1443 attr
->values
[i
].range
.lower
,
1444 attr
->values
[i
].range
.upper
);
1448 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1453 * Do media selection as needed...
1456 if (!ippFindAttribute(con
->request
, "PageRegion", IPP_TAG_ZERO
) &&
1457 !ippFindAttribute(con
->request
, "PageSize", IPP_TAG_ZERO
) &&
1458 _ppdCacheGetPageSize(printer
->pc
, con
->request
, NULL
, &exact
))
1461 (media_col
= ippFindAttribute(con
->request
, "media-col",
1462 IPP_TAG_BEGIN_COLLECTION
)) != NULL
)
1464 send_ipp_status(con
, IPP_OK_SUBST
, _("Unsupported margins."));
1466 unsup_col
= ippNew();
1467 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1468 "media-bottom-margin",
1469 IPP_TAG_INTEGER
)) != NULL
)
1470 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1471 "media-bottom-margin", media_margin
->values
[0].integer
);
1473 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1474 "media-left-margin",
1475 IPP_TAG_INTEGER
)) != NULL
)
1476 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1477 "media-left-margin", media_margin
->values
[0].integer
);
1479 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1480 "media-right-margin",
1481 IPP_TAG_INTEGER
)) != NULL
)
1482 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1483 "media-right-margin", media_margin
->values
[0].integer
);
1485 if ((media_margin
= ippFindAttribute(media_col
->values
[0].collection
,
1487 IPP_TAG_INTEGER
)) != NULL
)
1488 ippAddInteger(unsup_col
, IPP_TAG_ZERO
, IPP_TAG_INTEGER
,
1489 "media-top-margin", media_margin
->values
[0].integer
);
1491 ippAddCollection(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, "media-col",
1493 ippDelete(unsup_col
);
1498 * Make sure we aren't over our limit...
1501 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1504 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1506 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Too many active jobs."));
1510 if ((i
= check_quotas(con
, printer
)) < 0)
1512 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1517 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
1522 * Create the job and set things up...
1525 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1526 IPP_TAG_INTEGER
)) != NULL
)
1527 priority
= attr
->values
[0].integer
;
1530 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1531 printer
->options
)) != NULL
)
1532 priority
= atoi(val
);
1536 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1540 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) == NULL
)
1541 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1542 else if ((attr
->value_tag
!= IPP_TAG_NAME
&&
1543 attr
->value_tag
!= IPP_TAG_NAMELANG
) ||
1544 attr
->num_values
!= 1)
1546 send_ipp_status(con
, IPP_ATTRIBUTES
,
1547 _("Bad job-name value: Wrong type or count."));
1548 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1549 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1551 if (StrictConformance
)
1554 /* Don't use invalid attribute */
1555 ippDeleteAttribute(con
->request
, attr
);
1557 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1559 else if (!ippValidateAttribute(attr
))
1561 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad job-name value: %s"),
1562 cupsLastErrorString());
1564 if ((attr
= ippCopyAttribute(con
->response
, attr
, 0)) != NULL
)
1565 attr
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
1567 if (StrictConformance
)
1570 /* Don't use invalid attribute */
1571 ippDeleteAttribute(con
->request
, attr
);
1573 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, "Untitled");
1576 attr
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_NAME
);
1578 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1580 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1581 _("Unable to add job for destination \"%s\"."),
1586 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
1587 job
->attrs
= con
->request
;
1589 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1591 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
1594 apply_printer_defaults(printer
, job
);
1596 if (con
->username
[0])
1598 cupsdSetString(&job
->username
, con
->username
);
1601 ippSetString(job
->attrs
, &attr
, 0, con
->username
);
1605 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1606 "add_job: requesting-user-name=\"%s\"",
1607 attr
->values
[0].string
.text
);
1609 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1612 cupsdSetString(&job
->username
, "anonymous");
1615 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1616 "job-originating-user-name", NULL
, job
->username
);
1619 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1620 ippSetName(job
->attrs
, &attr
, "job-originating-user-name");
1623 if (con
->username
[0] || auth_info
)
1625 save_auth_info(con
, job
, auth_info
);
1628 * Remove the auth-info attribute from the attribute data...
1632 ippDeleteAttribute(job
->attrs
, auth_info
);
1635 if ((attr
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_NAME
)) != NULL
)
1636 cupsdSetString(&(job
->name
), attr
->values
[0].string
.text
);
1638 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1639 IPP_TAG_ZERO
)) != NULL
)
1642 * Request contains a job-originating-host-name attribute; validate it...
1645 if (attr
->value_tag
!= IPP_TAG_NAME
||
1646 attr
->num_values
!= 1 ||
1647 strcmp(con
->http
->hostname
, "localhost"))
1650 * Can't override the value if we aren't connected via localhost.
1651 * Also, we can only have 1 value and it must be a name value.
1654 ippDeleteAttribute(job
->attrs
, attr
);
1655 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-host-name", NULL
, con
->http
->hostname
);
1658 ippSetGroupTag(job
->attrs
, &attr
, IPP_TAG_JOB
);
1663 * No job-originating-host-name attribute, so use the hostname from
1667 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1668 "job-originating-host-name", NULL
, con
->http
->hostname
);
1671 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-completed");
1672 ippAddDate(job
->attrs
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(time(NULL
)));
1673 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "date-time-at-processing");
1674 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-completed");
1675 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", time(NULL
));
1676 ippAddOutOfBand(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NOVALUE
, "time-at-processing");
1679 * Add remaining job attributes...
1682 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1683 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1684 "job-state", IPP_JOB_STOPPED
);
1685 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1686 job
->reasons
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1687 "job-state-reasons", NULL
, "job-incoming");
1688 job
->impressions
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-impressions-completed", 0);
1689 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1690 "job-media-sheets-completed", 0);
1691 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1694 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
1695 attr
->values
[0].integer
= 0;
1697 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", 0);
1699 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1700 IPP_TAG_KEYWORD
)) == NULL
)
1701 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1704 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1705 printer
->options
)) == NULL
)
1708 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1709 "job-hold-until", NULL
, val
);
1712 if (printer
->holding_new_jobs
)
1715 * Hold all new jobs on this printer...
1718 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1719 cupsdSetJobHoldUntil(job
, ippGetString(attr
, 0, NULL
), 0);
1721 cupsdSetJobHoldUntil(job
, "indefinite", 0);
1723 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1724 job
->state_value
= IPP_JOB_HELD
;
1726 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-held-on-create");
1728 else if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
1731 * Hold job until specified time...
1734 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
1736 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1737 job
->state_value
= IPP_JOB_HELD
;
1739 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
1741 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1743 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
1744 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1745 job
->state_value
= IPP_JOB_HELD
;
1749 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1750 job
->state_value
= IPP_JOB_PENDING
;
1752 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
1755 if (!(printer
->type
& CUPS_PRINTER_REMOTE
) || Classification
)
1758 * Add job sheets options...
1761 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1762 IPP_TAG_ZERO
)) == NULL
)
1764 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1765 "Adding default job-sheets values \"%s,%s\"...",
1766 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1768 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1770 ippSetString(job
->attrs
, &attr
, 0, printer
->job_sheets
[0]);
1771 ippSetString(job
->attrs
, &attr
, 1, printer
->job_sheets
[1]);
1774 job
->job_sheets
= attr
;
1777 * Enforce classification level if set...
1782 cupsdLogMessage(CUPSD_LOG_INFO
,
1783 "Classification=\"%s\", ClassifyOverride=%d",
1784 Classification
? Classification
: "(null)",
1787 if (ClassifyOverride
)
1789 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1790 (attr
->num_values
== 1 ||
1791 !strcmp(attr
->values
[1].string
.text
, "none")))
1794 * Force the leading banner to have the classification on it...
1797 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1799 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1800 "job-sheets=\"%s,none\", "
1801 "job-originating-user-name=\"%s\"",
1802 Classification
, job
->username
);
1804 else if (attr
->num_values
== 2 &&
1805 strcmp(attr
->values
[0].string
.text
,
1806 attr
->values
[1].string
.text
) &&
1807 strcmp(attr
->values
[0].string
.text
, "none") &&
1808 strcmp(attr
->values
[1].string
.text
, "none"))
1811 * Can't put two different security markings on the same document!
1814 ippSetString(job
->attrs
, &attr
, 1, attr
->values
[0].string
.text
);
1816 cupsdLogJob(job
, CUPSD_LOG_NOTICE
, "CLASSIFICATION FORCED "
1817 "job-sheets=\"%s,%s\", "
1818 "job-originating-user-name=\"%s\"",
1819 attr
->values
[0].string
.text
,
1820 attr
->values
[1].string
.text
, job
->username
);
1822 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1823 strcmp(attr
->values
[0].string
.text
, "none") &&
1824 (attr
->num_values
== 1 ||
1825 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1826 strcmp(attr
->values
[1].string
.text
, "none"))))
1828 if (attr
->num_values
== 1)
1829 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1830 "CLASSIFICATION OVERRIDDEN "
1831 "job-sheets=\"%s\", "
1832 "job-originating-user-name=\"%s\"",
1833 attr
->values
[0].string
.text
, job
->username
);
1835 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1836 "CLASSIFICATION OVERRIDDEN "
1837 "job-sheets=\"%s,%s\",fffff "
1838 "job-originating-user-name=\"%s\"",
1839 attr
->values
[0].string
.text
,
1840 attr
->values
[1].string
.text
, job
->username
);
1843 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1844 (attr
->num_values
== 1 ||
1845 strcmp(attr
->values
[1].string
.text
, Classification
)))
1848 * Force the banner to have the classification on it...
1851 if (attr
->num_values
> 1 &&
1852 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1854 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1855 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1859 if (attr
->num_values
== 1 ||
1860 strcmp(attr
->values
[0].string
.text
, "none"))
1861 ippSetString(job
->attrs
, &attr
, 0, Classification
);
1863 if (attr
->num_values
> 1 &&
1864 strcmp(attr
->values
[1].string
.text
, "none"))
1865 ippSetString(job
->attrs
, &attr
, 1, Classification
);
1868 if (attr
->num_values
> 1)
1869 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1870 "CLASSIFICATION FORCED "
1871 "job-sheets=\"%s,%s\", "
1872 "job-originating-user-name=\"%s\"",
1873 attr
->values
[0].string
.text
,
1874 attr
->values
[1].string
.text
, job
->username
);
1876 cupsdLogJob(job
, CUPSD_LOG_NOTICE
,
1877 "CLASSIFICATION FORCED "
1878 "job-sheets=\"%s\", "
1879 "job-originating-user-name=\"%s\"",
1880 Classification
, job
->username
);
1885 * See if we need to add the starting sheet...
1888 if (!(printer
->type
& CUPS_PRINTER_REMOTE
))
1890 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Adding start banner page \"%s\".",
1891 attr
->values
[0].string
.text
);
1893 if ((kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
)) < 0)
1895 cupsdSetJobState(job
, IPP_JOB_ABORTED
, CUPSD_JOB_PURGE
,
1896 "Aborting job because the start banner could not be "
1901 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1904 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1905 IPP_TAG_ZERO
)) != NULL
)
1906 job
->job_sheets
= attr
;
1909 * Fill in the response info...
1912 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
1913 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
1914 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1917 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1919 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1921 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_TEXT
, "job-state-message", NULL
, "");
1922 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
1923 NULL
, job
->reasons
->values
[0].string
.text
);
1925 con
->response
->request
.status
.status_code
= IPP_OK
;
1928 * Add any job subscriptions...
1931 add_job_subscriptions(con
, job
);
1934 * Set all but the first two attributes to the job attributes group...
1937 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1938 attr
->group_tag
= IPP_TAG_JOB
;
1941 * Fire the "job created" event...
1944 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1947 * Return the new job...
1955 * 'add_job_subscriptions()' - Add any subscriptions for a job.
1959 add_job_subscriptions(
1960 cupsd_client_t
*con
, /* I - Client connection */
1961 cupsd_job_t
*job
) /* I - Newly created job */
1963 int i
; /* Looping var */
1964 ipp_attribute_t
*prev
, /* Previous attribute */
1965 *next
, /* Next attribute */
1966 *attr
; /* Current attribute */
1967 cupsd_subscription_t
*sub
; /* Subscription object */
1968 const char *recipient
, /* notify-recipient-uri */
1969 *pullmethod
; /* notify-pull-method */
1970 ipp_attribute_t
*user_data
; /* notify-user-data */
1971 int interval
; /* notify-time-interval */
1972 unsigned mask
; /* notify-events */
1976 * Find the first subscription group attribute; return if we have
1980 for (attr
= job
->attrs
->attrs
; attr
; attr
= attr
->next
)
1981 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1988 * Process the subscription attributes in the request...
1997 mask
= CUPSD_EVENT_NONE
;
1999 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
2001 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
2002 attr
->value_tag
== IPP_TAG_URI
)
2005 * Validate the recipient scheme against the ServerBin/notifier
2009 char notifier
[1024], /* Notifier filename */
2010 scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2011 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2012 host
[HTTP_MAX_URI
], /* Host portion of URI */
2013 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2014 int port
; /* Port portion of URI */
2015 struct stat info
; /* File information */
2017 recipient
= attr
->values
[0].string
.text
;
2019 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
2020 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2021 host
, sizeof(host
), &port
,
2022 resource
, sizeof(resource
)) < HTTP_URI_OK
)
2024 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2025 _("Bad notify-recipient-uri \"%s\"."), recipient
);
2026 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2027 "notify-status-code", IPP_URI_SCHEME
);
2031 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
, scheme
);
2032 if (access(notifier
, X_OK
) || stat(notifier
, &info
) || !S_ISREG(info
.st_mode
))
2034 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2035 _("notify-recipient-uri URI \"%s\" uses unknown "
2036 "scheme."), recipient
);
2037 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2038 "notify-status-code", IPP_URI_SCHEME
);
2042 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
2044 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2045 _("notify-recipient-uri URI \"%s\" is already used."),
2047 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2048 "notify-status-code", IPP_ATTRIBUTES
);
2052 else if (!strcmp(attr
->name
, "notify-pull-method") &&
2053 attr
->value_tag
== IPP_TAG_KEYWORD
)
2055 pullmethod
= attr
->values
[0].string
.text
;
2057 if (strcmp(pullmethod
, "ippget"))
2059 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2060 _("Bad notify-pull-method \"%s\"."), pullmethod
);
2061 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
2062 "notify-status-code", IPP_ATTRIBUTES
);
2066 else if (!strcmp(attr
->name
, "notify-charset") &&
2067 attr
->value_tag
== IPP_TAG_CHARSET
&&
2068 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
2069 strcmp(attr
->values
[0].string
.text
, "utf-8"))
2071 send_ipp_status(con
, IPP_CHARSET
,
2072 _("Character set \"%s\" not supported."),
2073 attr
->values
[0].string
.text
);
2076 else if (!strcmp(attr
->name
, "notify-natural-language") &&
2077 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
2078 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
2080 send_ipp_status(con
, IPP_CHARSET
,
2081 _("Language \"%s\" not supported."),
2082 attr
->values
[0].string
.text
);
2085 else if (!strcmp(attr
->name
, "notify-user-data") &&
2086 attr
->value_tag
== IPP_TAG_STRING
)
2088 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
2090 send_ipp_status(con
, IPP_REQUEST_VALUE
,
2091 _("The notify-user-data value is too large "
2092 "(%d > 63 octets)."),
2093 attr
->values
[0].unknown
.length
);
2099 else if (!strcmp(attr
->name
, "notify-events") &&
2100 attr
->value_tag
== IPP_TAG_KEYWORD
)
2102 for (i
= 0; i
< attr
->num_values
; i
++)
2103 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
2105 else if (!strcmp(attr
->name
, "notify-lease-duration"))
2107 send_ipp_status(con
, IPP_BAD_REQUEST
,
2108 _("The notify-lease-duration attribute cannot be "
2109 "used with job subscriptions."));
2112 else if (!strcmp(attr
->name
, "notify-time-interval") &&
2113 attr
->value_tag
== IPP_TAG_INTEGER
)
2114 interval
= attr
->values
[0].integer
;
2119 if (!recipient
&& !pullmethod
)
2122 if (mask
== CUPSD_EVENT_NONE
)
2123 mask
= CUPSD_EVENT_JOB_COMPLETED
;
2125 if ((sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
,
2126 recipient
, 0)) != NULL
)
2128 sub
->interval
= interval
;
2130 cupsdSetString(&sub
->owner
, job
->username
);
2134 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
2135 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
2136 (size_t)sub
->user_data_len
);
2139 ippAddSeparator(con
->response
);
2140 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
2141 "notify-subscription-id", sub
->id
);
2143 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
2151 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
2154 * Remove all of the subscription attributes from the job request...
2156 * TODO: Optimize this since subscription groups have to come at the
2157 * end of the request...
2160 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
2164 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
2165 attr
->group_tag
== IPP_TAG_ZERO
)
2168 * Free and remove this attribute...
2171 ippDeleteAttribute(NULL
, attr
);
2176 job
->attrs
->attrs
= next
;
2182 job
->attrs
->last
= prev
;
2183 job
->attrs
->current
= prev
;
2188 * 'add_job_uuid()' - Add job-uuid attribute to a job.
2190 * See RFC 4122 for the definition of UUIDs and the format.
2194 add_job_uuid(cupsd_job_t
*job
) /* I - Job */
2196 char uuid
[64]; /* job-uuid string */
2200 * Add a job-uuid attribute if none exists...
2203 if (!ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2204 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
,
2205 httpAssembleUUID(ServerName
, RemotePort
, job
->dest
, job
->id
,
2206 uuid
, sizeof(uuid
)));
2211 * 'add_printer()' - Add a printer to the system.
2215 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2216 ipp_attribute_t
*uri
) /* I - URI of printer */
2218 http_status_t status
; /* Policy status */
2219 int i
; /* Looping var */
2220 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
2221 username
[HTTP_MAX_URI
], /* Username portion of URI */
2222 host
[HTTP_MAX_URI
], /* Host portion of URI */
2223 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2224 int port
; /* Port portion of URI */
2225 cupsd_printer_t
*printer
; /* Printer/class */
2226 ipp_attribute_t
*attr
; /* Printer attribute */
2227 cups_file_t
*fp
; /* Script/PPD file */
2228 char line
[1024]; /* Line from file... */
2229 char srcfile
[1024], /* Source Script/PPD file */
2230 dstfile
[1024]; /* Destination Script/PPD file */
2231 int modify
; /* Non-zero if we are modifying */
2232 int changed_driver
, /* Changed the PPD? */
2233 need_restart_job
, /* Need to restart job? */
2234 set_device_uri
, /* Did we set the device URI? */
2235 set_port_monitor
; /* Did we set the port monitor? */
2238 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2239 con
->number
, uri
->values
[0].string
.text
);
2242 * Do we have a valid URI?
2245 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
2246 sizeof(scheme
), username
, sizeof(username
), host
,
2247 sizeof(host
), &port
, resource
, sizeof(resource
));
2249 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2252 * No, return an error...
2255 send_ipp_status(con
, IPP_BAD_REQUEST
,
2256 _("The printer-uri must be of the form "
2257 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2262 * Do we have a valid printer name?
2265 if (!validate_name(resource
+ 10))
2268 * No, return an error...
2271 send_ipp_status(con
, IPP_BAD_REQUEST
,
2272 _("The printer-uri \"%s\" contains invalid characters."),
2273 uri
->values
[0].string
.text
);
2278 * See if the printer already exists; if not, create a new printer...
2281 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2284 * Printer doesn't exist; see if we have a class of the same name...
2287 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
)
2290 * Yes, return an error...
2293 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2294 _("A class named \"%s\" already exists."),
2300 * No, check the default policy then add the printer...
2303 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2305 send_http_error(con
, status
, NULL
);
2309 printer
= cupsdAddPrinter(resource
+ 10);
2312 printer
->printer_id
= NextPrinterId
++;
2314 else if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2317 send_http_error(con
, status
, printer
);
2324 * Look for attributes and copy them over as needed...
2328 need_restart_job
= 0;
2330 if ((attr
= ippFindAttribute(con
->request
, "printer-is-temporary", IPP_TAG_BOOLEAN
)) != NULL
)
2331 printer
->temporary
= ippGetBoolean(attr
, 0);
2333 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2334 IPP_TAG_TEXT
)) != NULL
)
2335 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2337 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
2338 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
2340 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
2341 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
2343 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
2344 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
2346 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2347 IPP_TAG_TEXT
)) != NULL
)
2348 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2352 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2353 IPP_TAG_URI
)) != NULL
)
2356 * Do we have a valid device URI?
2359 http_uri_status_t uri_status
; /* URI separation status */
2360 char old_device_uri
[1024];
2361 /* Old device URI */
2363 need_restart_job
= 1;
2365 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
2366 attr
->values
[0].string
.text
,
2367 scheme
, sizeof(scheme
),
2368 username
, sizeof(username
),
2369 host
, sizeof(host
), &port
,
2370 resource
, sizeof(resource
));
2372 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s device-uri: %s", printer
->name
, httpURIStatusString(uri_status
));
2374 if (uri_status
< HTTP_URI_OK
)
2376 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"."),
2377 attr
->values
[0].string
.text
);
2379 cupsdDeletePrinter(printer
, 0);
2384 if (!strcmp(scheme
, "file"))
2387 * See if the administrator has enabled file devices...
2390 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2393 * File devices are disabled and the URL is not file:/dev/null...
2396 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2397 _("File device URIs have been disabled. "
2398 "To enable, see the FileDevice directive in "
2399 "\"%s/cups-files.conf\"."),
2402 cupsdDeletePrinter(printer
, 0);
2410 * See if the backend exists and is executable...
2413 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, scheme
);
2414 if (access(srcfile
, X_OK
))
2417 * Could not find device in list!
2420 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2421 _("Bad device-uri scheme \"%s\"."), scheme
);
2423 cupsdDeletePrinter(printer
, 0);
2429 if (printer
->sanitized_device_uri
)
2430 strlcpy(old_device_uri
, printer
->sanitized_device_uri
,
2431 sizeof(old_device_uri
));
2433 old_device_uri
[0] = '\0';
2435 cupsdSetDeviceURI(printer
, attr
->values
[0].string
.text
);
2437 cupsdLogMessage(CUPSD_LOG_INFO
,
2438 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2439 printer
->name
, printer
->sanitized_device_uri
,
2445 set_port_monitor
= 0;
2447 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2448 IPP_TAG_NAME
)) != NULL
)
2450 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2453 need_restart_job
= 1;
2455 supported
= ippFindAttribute(printer
->ppd_attrs
, "port-monitor-supported",
2459 for (i
= 0; i
< supported
->num_values
; i
++)
2460 if (!strcmp(supported
->values
[i
].string
.text
,
2461 attr
->values
[0].string
.text
))
2465 if (!supported
|| i
>= supported
->num_values
)
2467 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"."),
2468 attr
->values
[0].string
.text
);
2470 cupsdDeletePrinter(printer
, 0);
2475 cupsdLogMessage(CUPSD_LOG_INFO
,
2476 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2477 printer
->name
, attr
->values
[0].string
.text
,
2478 printer
->port_monitor
? printer
->port_monitor
: "none");
2480 if (strcmp(attr
->values
[0].string
.text
, "none"))
2481 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2483 cupsdClearString(&printer
->port_monitor
);
2485 set_port_monitor
= 1;
2488 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2489 IPP_TAG_BOOLEAN
)) != NULL
&&
2490 attr
->values
[0].boolean
!= printer
->accepting
)
2492 cupsdLogMessage(CUPSD_LOG_INFO
,
2493 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2494 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2496 printer
->accepting
= attr
->values
[0].boolean
;
2498 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2499 "%s accepting jobs.",
2500 printer
->accepting
? "Now" : "No longer");
2503 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared", IPP_TAG_BOOLEAN
)) != NULL
)
2505 if (ippGetBoolean(attr
, 0) &&
2506 printer
->num_auth_info_required
== 1 &&
2507 !strcmp(printer
->auth_info_required
[0], "negotiate"))
2509 send_ipp_status(con
, IPP_BAD_REQUEST
,
2510 _("Cannot share a remote Kerberized printer."));
2512 cupsdDeletePrinter(printer
, 0);
2517 if (printer
->type
& CUPS_PRINTER_REMOTE
)
2520 * Cannot re-share remote printers.
2523 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Cannot change printer-is-shared for remote queues."));
2525 cupsdDeletePrinter(printer
, 0);
2530 if (printer
->shared
&& !ippGetBoolean(attr
, 0))
2531 cupsdDeregisterPrinter(printer
, 1);
2533 cupsdLogMessage(CUPSD_LOG_INFO
,
2534 "Setting %s printer-is-shared to %d (was %d.)",
2535 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2537 printer
->shared
= ippGetBoolean(attr
, 0);
2538 if (printer
->shared
&& printer
->temporary
)
2539 printer
->temporary
= 0;
2542 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2543 IPP_TAG_ENUM
)) != NULL
)
2545 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2546 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2548 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d."),
2549 attr
->values
[0].integer
);
2551 cupsdDeletePrinter(printer
, 0);
2556 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)",
2557 printer
->name
, attr
->values
[0].integer
, printer
->state
);
2559 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2560 cupsdStopPrinter(printer
, 0);
2563 need_restart_job
= 1;
2564 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2568 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2569 IPP_TAG_TEXT
)) != NULL
)
2571 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2572 sizeof(printer
->state_message
));
2574 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
, "%s",
2575 printer
->state_message
);
2578 if ((attr
= ippFindAttribute(con
->request
, "printer-state-reasons",
2579 IPP_TAG_KEYWORD
)) != NULL
)
2581 if (attr
->num_values
>
2582 (int)(sizeof(printer
->reasons
) / sizeof(printer
->reasons
[0])))
2584 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2585 _("Too many printer-state-reasons values (%d > %d)."),
2587 (int)(sizeof(printer
->reasons
) /
2588 sizeof(printer
->reasons
[0])));
2590 cupsdDeletePrinter(printer
, 0);
2595 for (i
= 0; i
< printer
->num_reasons
; i
++)
2596 _cupsStrFree(printer
->reasons
[i
]);
2598 printer
->num_reasons
= 0;
2599 for (i
= 0; i
< attr
->num_values
; i
++)
2601 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
2604 printer
->reasons
[printer
->num_reasons
] =
2605 _cupsStrRetain(attr
->values
[i
].string
.text
);
2606 printer
->num_reasons
++;
2608 if (!strcmp(attr
->values
[i
].string
.text
, "paused") &&
2609 printer
->state
!= IPP_PRINTER_STOPPED
)
2611 cupsdLogMessage(CUPSD_LOG_INFO
,
2612 "Setting %s printer-state to %d (was %d.)",
2613 printer
->name
, IPP_PRINTER_STOPPED
, printer
->state
);
2614 cupsdStopPrinter(printer
, 0);
2618 if (PrintcapFormat
== PRINTCAP_PLIST
)
2619 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2621 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
2622 "Printer \"%s\" state changed.", printer
->name
);
2625 if (!set_printer_defaults(con
, printer
))
2628 cupsdDeletePrinter(printer
, 0);
2633 if ((attr
= ippFindAttribute(con
->request
, "auth-info-required",
2634 IPP_TAG_KEYWORD
)) != NULL
)
2635 cupsdSetAuthInfoRequired(printer
, NULL
, attr
);
2638 * See if we have all required attributes...
2641 if (!printer
->device_uri
)
2642 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2645 * See if we have a PPD file attached to the request...
2650 need_restart_job
= 1;
2653 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2655 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2658 * Yes; get the first line from it...
2662 cupsFileGets(fp
, line
, sizeof(line
));
2666 * Then see what kind of file it is...
2669 if (strncmp(line
, "*PPD-Adobe", 10))
2671 send_ipp_status(con
, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED
, _("Bad PPD file."));
2673 cupsdDeletePrinter(printer
, 0);
2678 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2682 * The new file is a PPD file, so move the file over to the ppd
2686 if (copy_file(srcfile
, dstfile
, ConfigFilePerm
))
2688 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file - %s"), strerror(errno
));
2690 cupsdDeletePrinter(printer
, 0);
2695 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2698 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name", IPP_TAG_NAME
)) != NULL
)
2700 const char *ppd_name
= ippGetString(attr
, 0, NULL
);
2701 /* ppd-name value */
2703 need_restart_job
= 1;
2706 if (!strcmp(ppd_name
, "raw"))
2709 * Raw driver, remove any existing PPD file.
2712 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2715 else if (strstr(ppd_name
, "../"))
2717 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
2719 cupsdDeletePrinter(printer
, 0);
2729 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
2731 if (copy_model(con
, ppd_name
, dstfile
))
2733 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file."));
2735 cupsdDeletePrinter(printer
, 0);
2740 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Copied PPD file successfully");
2747 * If we changed the PPD, then remove the printer's cache file and clear the
2748 * printer-state-reasons...
2751 char cache_name
[1024]; /* Cache filename for printer attrs */
2753 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, printer
->name
);
2756 cupsdSetPrinterReasons(printer
, "none");
2759 * (Re)register color profiles...
2762 cupsdRegisterColor(printer
);
2766 * If we set the device URI but not the port monitor, check which port
2767 * monitor to use by default...
2770 if (set_device_uri
&& !set_port_monitor
)
2772 ppd_file_t
*ppd
; /* PPD file */
2773 ppd_attr_t
*ppdattr
; /* cupsPortMonitor attribute */
2776 httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
,
2777 sizeof(scheme
), username
, sizeof(username
), host
,
2778 sizeof(host
), &port
, resource
, sizeof(resource
));
2780 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
,
2782 if ((ppd
= _ppdOpenFile(srcfile
, _PPD_LOCALIZATION_NONE
)) != NULL
)
2784 for (ppdattr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
2786 ppdattr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
2787 if (!strcmp(scheme
, ppdattr
->spec
))
2789 cupsdLogMessage(CUPSD_LOG_INFO
,
2790 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2791 printer
->name
, ppdattr
->value
,
2792 printer
->port_monitor
? printer
->port_monitor
2795 if (strcmp(ppdattr
->value
, "none"))
2796 cupsdSetString(&printer
->port_monitor
, ppdattr
->value
);
2798 cupsdClearString(&printer
->port_monitor
);
2807 printer
->config_time
= time(NULL
);
2810 * Update the printer attributes and return...
2813 if (!printer
->temporary
)
2815 if (!printer
->printer_id
)
2816 printer
->printer_id
= NextPrinterId
++;
2818 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
2821 cupsdSetPrinterAttrs(printer
);
2823 if (need_restart_job
&& printer
->job
)
2826 * Restart the current job...
2829 cupsdSetJobState(printer
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
2830 "Job restarted because the printer was modified.");
2833 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
2837 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
,
2838 printer
, NULL
, "Printer \"%s\" modified by \"%s\".",
2839 printer
->name
, get_username(con
));
2841 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2842 printer
->name
, get_username(con
));
2846 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
,
2847 printer
, NULL
, "New printer \"%s\" added by \"%s\".",
2848 printer
->name
, get_username(con
));
2850 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2851 printer
->name
, get_username(con
));
2854 con
->response
->request
.status
.status_code
= IPP_OK
;
2859 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2860 * based upon the printer state...
2864 add_printer_state_reasons(
2865 cupsd_client_t
*con
, /* I - Client connection */
2866 cupsd_printer_t
*p
) /* I - Printer info */
2868 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2869 "add_printer_state_reasons(%p[%d], %p[%s])",
2870 con
, con
->number
, p
, p
->name
);
2872 if (p
->num_reasons
== 0)
2873 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2874 "printer-state-reasons", NULL
, "none");
2876 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2877 "printer-state-reasons", p
->num_reasons
, NULL
,
2878 (const char * const *)p
->reasons
);
2883 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2884 * the specified printer or class.
2888 add_queued_job_count(
2889 cupsd_client_t
*con
, /* I - Client connection */
2890 cupsd_printer_t
*p
) /* I - Printer or class */
2892 int count
; /* Number of jobs on destination */
2895 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2896 con
, con
->number
, p
, p
->name
);
2898 count
= cupsdGetPrinterJobCount(p
->name
);
2900 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2901 "queued-job-count", count
);
2906 * 'apply_printer_defaults()' - Apply printer default options to a job.
2910 apply_printer_defaults(
2911 cupsd_printer_t
*printer
, /* I - Printer */
2912 cupsd_job_t
*job
) /* I - Job */
2914 int i
, /* Looping var */
2915 num_options
; /* Number of default options */
2916 cups_option_t
*options
, /* Default options */
2917 *option
; /* Current option */
2920 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Applying default options...");
2923 * Collect all of the default options and add the missing ones to the
2927 for (i
= printer
->num_options
, num_options
= 0, options
= NULL
,
2928 option
= printer
->options
;
2931 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2933 if (!strcmp(option
->name
, "print-quality") && ippFindAttribute(job
->attrs
, "cupsPrintQuality", IPP_TAG_NAME
))
2934 continue; /* Don't override cupsPrintQuality */
2936 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Adding default %s=%s", option
->name
, option
->value
);
2938 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
, &options
);
2942 * Encode these options as attributes in the job object...
2945 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2946 cupsFreeOptions(num_options
, options
);
2951 * 'authenticate_job()' - Set job authentication info.
2955 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2956 ipp_attribute_t
*uri
) /* I - Job URI */
2958 ipp_attribute_t
*attr
, /* job-id attribute */
2959 *auth_info
; /* auth-info attribute */
2960 int jobid
; /* Job ID */
2961 cupsd_job_t
*job
; /* Current job */
2962 char scheme
[HTTP_MAX_URI
],
2963 /* Method portion of URI */
2964 username
[HTTP_MAX_URI
],
2965 /* Username portion of URI */
2967 /* Host portion of URI */
2968 resource
[HTTP_MAX_URI
];
2969 /* Resource portion of URI */
2970 int port
; /* Port portion of URI */
2973 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2974 con
, con
->number
, uri
->values
[0].string
.text
);
2977 * Start with "everything is OK" status...
2980 con
->response
->request
.status
.status_code
= IPP_OK
;
2983 * See if we have a job URI or a printer URI...
2986 if (!strcmp(uri
->name
, "printer-uri"))
2989 * Got a printer URI; see if we also have a job-id attribute...
2992 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2993 IPP_TAG_INTEGER
)) == NULL
)
2995 send_ipp_status(con
, IPP_BAD_REQUEST
,
2996 _("Got a printer-uri attribute but no job-id."));
3000 jobid
= attr
->values
[0].integer
;
3005 * Got a job URI; parse it to get the job ID...
3008 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3009 sizeof(scheme
), username
, sizeof(username
), host
,
3010 sizeof(host
), &port
, resource
, sizeof(resource
));
3012 if (strncmp(resource
, "/jobs/", 6))
3018 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3019 uri
->values
[0].string
.text
);
3023 jobid
= atoi(resource
+ 6);
3027 * See if the job exists...
3030 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3033 * Nope - return a "not found" error...
3036 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3041 * See if the job has been completed...
3044 if (job
->state_value
!= IPP_JOB_HELD
)
3047 * Return a "not-possible" error...
3050 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3051 _("Job #%d is not held for authentication."),
3057 * See if we have already authenticated...
3060 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
3062 if (!con
->username
[0] && !auth_info
)
3064 cupsd_printer_t
*printer
; /* Job destination */
3067 * No auth data. If we need to authenticate via Kerberos, send a
3068 * HTTP auth challenge, otherwise just return an IPP error...
3071 printer
= cupsdFindDest(job
->dest
);
3073 if (printer
&& printer
->num_auth_info_required
> 0 &&
3074 !strcmp(printer
->auth_info_required
[0], "negotiate"))
3075 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
3077 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3078 _("No authentication information provided."));
3083 * See if the job is owned by the requesting user...
3086 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3088 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3089 cupsdFindDest(job
->dest
));
3094 * Save the authentication information for this job...
3097 save_auth_info(con
, job
, auth_info
);
3100 * Reset the job-hold-until value to "no-hold"...
3103 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3104 IPP_TAG_KEYWORD
)) == NULL
)
3105 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3109 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
3110 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
3114 * Release the job and return...
3117 cupsdReleaseJob(job
);
3119 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, NULL
, job
, "Job authenticated by user");
3121 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Authenticated by \"%s\".", con
->username
);
3128 * 'cancel_all_jobs()' - Cancel all or selected print jobs.
3132 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
3133 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3135 int i
; /* Looping var */
3136 http_status_t status
; /* Policy status */
3137 cups_ptype_t dtype
; /* Destination type */
3138 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3139 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
3140 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
3141 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3142 int port
; /* Port portion of URI */
3143 ipp_attribute_t
*attr
; /* Attribute in request */
3144 const char *username
= NULL
; /* Username */
3145 cupsd_jobaction_t purge
= CUPSD_JOB_DEFAULT
;
3147 cupsd_printer_t
*printer
; /* Printer */
3148 ipp_attribute_t
*job_ids
; /* job-ids attribute */
3149 cupsd_job_t
*job
; /* Job */
3152 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
3153 con
->number
, uri
->values
[0].string
.text
);
3156 * Get the jobs to cancel/purge...
3159 switch (con
->request
->request
.op
.operation_id
)
3161 case IPP_PURGE_JOBS
:
3163 * Get the username (if any) for the jobs we want to cancel (only if
3164 * "my-jobs" is specified...
3167 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
3168 IPP_TAG_BOOLEAN
)) != NULL
&&
3169 attr
->values
[0].boolean
)
3171 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3172 IPP_TAG_NAME
)) != NULL
)
3173 username
= attr
->values
[0].string
.text
;
3176 send_ipp_status(con
, IPP_BAD_REQUEST
,
3177 _("Missing requesting-user-name attribute."));
3183 * Look for the "purge-jobs" attribute...
3186 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
3187 IPP_TAG_BOOLEAN
)) != NULL
)
3188 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3190 purge
= CUPSD_JOB_PURGE
;
3193 case IPP_CANCEL_MY_JOBS
:
3194 if (con
->username
[0])
3195 username
= con
->username
;
3196 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
3197 IPP_TAG_NAME
)) != NULL
)
3198 username
= attr
->values
[0].string
.text
;
3201 send_ipp_status(con
, IPP_BAD_REQUEST
,
3202 _("Missing requesting-user-name attribute."));
3210 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
3213 * See if we have a printer URI...
3216 if (strcmp(uri
->name
, "printer-uri"))
3218 send_ipp_status(con
, IPP_BAD_REQUEST
,
3219 _("The printer-uri attribute is required."));
3224 * And if the destination is valid...
3227 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3233 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
3234 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
3235 hostname
, sizeof(hostname
), &port
,
3236 resource
, sizeof(resource
));
3238 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
3239 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
3241 send_ipp_status(con
, IPP_NOT_FOUND
,
3242 _("The printer or class does not exist."));
3250 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
3252 send_http_error(con
, status
, NULL
);
3258 for (i
= 0; i
< job_ids
->num_values
; i
++)
3260 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
)
3263 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3264 _cups_strcasecmp(job
->username
, username
))
3268 if (i
< job_ids
->num_values
)
3270 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3271 job_ids
->values
[i
].integer
);
3275 for (i
= 0; i
< job_ids
->num_values
; i
++)
3277 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3279 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3280 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3281 "Job canceled by user.");
3284 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3285 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3291 * Cancel all jobs on all printers...
3294 cupsdCancelJobs(NULL
, username
, purge
);
3296 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
3297 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3307 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
3310 send_http_error(con
, status
, printer
);
3316 for (i
= 0; i
< job_ids
->num_values
; i
++)
3318 if ((job
= cupsdFindJob(job_ids
->values
[i
].integer
)) == NULL
||
3319 _cups_strcasecmp(job
->dest
, printer
->name
))
3322 if (con
->request
->request
.op
.operation_id
== IPP_CANCEL_MY_JOBS
&&
3323 _cups_strcasecmp(job
->username
, username
))
3327 if (i
< job_ids
->num_values
)
3329 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3330 job_ids
->values
[i
].integer
);
3334 for (i
= 0; i
< job_ids
->num_values
; i
++)
3336 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
3338 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3339 purge
== CUPSD_JOB_PURGE
? "Job purged by user." :
3340 "Job canceled by user.");
3343 cupsdLogMessage(CUPSD_LOG_INFO
, "Selected jobs were %s by \"%s\".",
3344 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3350 * Cancel all of the jobs on the named printer...
3353 cupsdCancelJobs(printer
->name
, username
, purge
);
3355 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
3357 purge
== CUPSD_JOB_PURGE
? "purged" : "canceled",
3362 con
->response
->request
.status
.status_code
= IPP_OK
;
3369 * 'cancel_job()' - Cancel a print job.
3373 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
3374 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
3376 ipp_attribute_t
*attr
; /* Current attribute */
3377 int jobid
; /* Job ID */
3378 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
3379 username
[HTTP_MAX_URI
], /* Username portion of URI */
3380 host
[HTTP_MAX_URI
], /* Host portion of URI */
3381 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3382 int port
; /* Port portion of URI */
3383 cupsd_job_t
*job
; /* Job information */
3384 cups_ptype_t dtype
; /* Destination type (printer/class) */
3385 cupsd_printer_t
*printer
; /* Printer data */
3386 cupsd_jobaction_t purge
; /* Purge the job? */
3389 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
3390 con
->number
, uri
->values
[0].string
.text
);
3393 * See if we have a job URI or a printer URI...
3396 if (!strcmp(uri
->name
, "printer-uri"))
3399 * Got a printer URI; see if we also have a job-id attribute...
3402 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3403 IPP_TAG_INTEGER
)) == NULL
)
3405 send_ipp_status(con
, IPP_BAD_REQUEST
,
3406 _("Got a printer-uri attribute but no job-id."));
3410 if ((jobid
= attr
->values
[0].integer
) == 0)
3413 * Find the current job on the specified printer...
3416 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
3422 send_ipp_status(con
, IPP_NOT_FOUND
,
3423 _("The printer or class does not exist."));
3428 * See if there are any pending jobs...
3431 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3433 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3434 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3435 !_cups_strcasecmp(job
->dest
, printer
->name
))
3443 * No, try stopped jobs...
3446 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3448 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3449 if (job
->state_value
== IPP_JOB_STOPPED
&&
3450 !_cups_strcasecmp(job
->dest
, printer
->name
))
3457 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s."),
3467 * Got a job URI; parse it to get the job ID...
3470 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3471 sizeof(scheme
), username
, sizeof(username
), host
,
3472 sizeof(host
), &port
, resource
, sizeof(resource
));
3474 if (strncmp(resource
, "/jobs/", 6))
3480 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
3481 uri
->values
[0].string
.text
);
3485 jobid
= atoi(resource
+ 6);
3489 * Look for the "purge-job" attribute...
3492 if ((attr
= ippFindAttribute(con
->request
, "purge-job",
3493 IPP_TAG_BOOLEAN
)) != NULL
)
3494 purge
= attr
->values
[0].boolean
? CUPSD_JOB_PURGE
: CUPSD_JOB_DEFAULT
;
3496 purge
= CUPSD_JOB_DEFAULT
;
3499 * See if the job exists...
3502 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3505 * Nope - return a "not found" error...
3508 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
3513 * See if the job is owned by the requesting user...
3516 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3518 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3519 cupsdFindDest(job
->dest
));
3524 * See if the job is already completed, canceled, or aborted; if so,
3525 * we can't cancel...
3528 if (job
->state_value
>= IPP_JOB_CANCELED
&& purge
!= CUPSD_JOB_PURGE
)
3530 switch (job
->state_value
)
3532 case IPP_JOB_CANCELED
:
3533 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3534 _("Job #%d is already canceled - can\'t cancel."),
3538 case IPP_JOB_ABORTED
:
3539 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3540 _("Job #%d is already aborted - can\'t cancel."),
3545 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3546 _("Job #%d is already completed - can\'t cancel."),
3555 * Cancel the job and return...
3558 cupsdSetJobState(job
, IPP_JOB_CANCELED
, purge
,
3559 purge
== CUPSD_JOB_PURGE
? "Job purged by \"%s\"" :
3560 "Job canceled by \"%s\"",
3564 if (purge
== CUPSD_JOB_PURGE
)
3565 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Purged by \"%s\".", jobid
,
3568 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job %d] Canceled by \"%s\".", jobid
,
3571 con
->response
->request
.status
.status_code
= IPP_OK
;
3576 * 'cancel_subscription()' - Cancel a subscription.
3580 cancel_subscription(
3581 cupsd_client_t
*con
, /* I - Client connection */
3582 int sub_id
) /* I - Subscription ID */
3584 http_status_t status
; /* Policy status */
3585 cupsd_subscription_t
*sub
; /* Subscription */
3588 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3589 "cancel_subscription(con=%p[%d], sub_id=%d)",
3590 con
, con
->number
, sub_id
);
3593 * Is the subscription ID valid?
3596 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3599 * Bad subscription ID...
3602 send_ipp_status(con
, IPP_NOT_FOUND
,
3603 _("Subscription #%d does not exist."), sub_id
);
3611 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3613 con
, sub
->owner
)) != HTTP_OK
)
3615 send_http_error(con
, status
, sub
->dest
);
3620 * Cancel the subscription...
3623 cupsdDeleteSubscription(sub
, 1);
3625 con
->response
->request
.status
.status_code
= IPP_OK
;
3630 * 'check_rss_recipient()' - Check that we do not have a duplicate RSS feed URI.
3633 static int /* O - 1 if OK, 0 if not */
3634 check_rss_recipient(
3635 const char *recipient
) /* I - Recipient URI */
3637 cupsd_subscription_t
*sub
; /* Current subscription */
3640 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
3642 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
3646 * Compare the URIs up to the first ?...
3649 const char *r1
, *r2
;
3651 for (r1
= recipient
, r2
= sub
->recipient
;
3652 *r1
== *r2
&& *r1
&& *r1
!= '?' && *r2
&& *r2
!= '?';
3664 * 'check_quotas()' - Check quotas for a printer and user.
3667 static int /* O - 1 if OK, 0 if forbidden,
3668 -1 if limit reached */
3669 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3670 cupsd_printer_t
*p
) /* I - Printer or class */
3672 char username
[33], /* Username */
3673 *name
; /* Current user name */
3674 cupsd_quota_t
*q
; /* Quota data */
3675 #ifdef HAVE_MBR_UID_TO_UUID
3677 * Use Apple membership APIs which require that all names represent
3678 * valid user account or group records accessible by the server.
3681 uuid_t usr_uuid
; /* UUID for job requesting user */
3682 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3683 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3684 int mbr_err
; /* Error from membership function */
3685 int is_member
; /* Is this user a member? */
3688 * Use standard POSIX APIs for checking users and groups...
3691 struct passwd
*pw
; /* User password data */
3692 #endif /* HAVE_MBR_UID_TO_UUID */
3695 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3696 con
, con
->number
, p
, p
->name
);
3699 * Figure out who is printing...
3702 strlcpy(username
, get_username(con
), sizeof(username
));
3704 if ((name
= strchr(username
, '@')) != NULL
)
3705 *name
= '\0'; /* Strip @REALM */
3708 * Check global active job limits for printers and users...
3711 if (MaxJobsPerPrinter
)
3714 * Check if there are too many pending jobs on this printer...
3717 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3719 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3728 * Check if there are too many pending jobs for this user...
3731 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3733 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3740 * Check against users...
3743 if (cupsArrayCount(p
->users
) == 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3746 if (cupsArrayCount(p
->users
))
3748 #ifdef HAVE_MBR_UID_TO_UUID
3750 * Get UUID for job requesting user...
3753 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3759 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3760 "check_quotas: UUID lookup failed for user \"%s\"",
3762 cupsdLogMessage(CUPSD_LOG_INFO
,
3763 "Denying user \"%s\" access to printer \"%s\" "
3764 "(unknown user)...",
3770 * Get UID and GID of requesting user...
3773 pw
= getpwnam(username
);
3775 #endif /* HAVE_MBR_UID_TO_UUID */
3777 for (name
= (char *)cupsArrayFirst(p
->users
);
3779 name
= (char *)cupsArrayNext(p
->users
))
3783 * Check group membership...
3786 #ifdef HAVE_MBR_UID_TO_UUID
3789 if (uuid_parse(name
+ 2, grp_uuid
))
3790 uuid_clear(grp_uuid
);
3792 else if ((mbr_err
= mbr_group_name_to_uuid(name
+ 1, grp_uuid
)) != 0)
3795 * Invalid ACL entries are ignored for matching; just record a
3796 * warning in the log...
3799 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3800 "check_quotas: UUID lookup failed for ACL entry "
3801 "\"%s\" (err=%d)", name
, mbr_err
);
3802 cupsdLogMessage(CUPSD_LOG_WARN
,
3803 "Access control entry \"%s\" not a valid group name; "
3804 "entry ignored", name
);
3807 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3811 * At this point, there should be no errors, but check anyways...
3814 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3815 "check_quotas: group \"%s\" membership check "
3816 "failed (err=%d)", name
+ 1, mbr_err
);
3821 * Stop if we found a match...
3828 if (cupsdCheckGroup(username
, pw
, name
+ 1))
3830 #endif /* HAVE_MBR_UID_TO_UUID */
3832 #ifdef HAVE_MBR_UID_TO_UUID
3837 if (uuid_parse(name
+ 1, usr2_uuid
))
3838 uuid_clear(usr2_uuid
);
3840 else if ((mbr_err
= mbr_user_name_to_uuid(name
, usr2_uuid
)) != 0)
3843 * Invalid ACL entries are ignored for matching; just record a
3844 * warning in the log...
3847 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3848 "check_quotas: UUID lookup failed for ACL entry "
3849 "\"%s\" (err=%d)", name
, mbr_err
);
3850 cupsdLogMessage(CUPSD_LOG_WARN
,
3851 "Access control entry \"%s\" not a valid user name; "
3852 "entry ignored", name
);
3855 if (!uuid_compare(usr_uuid
, usr2_uuid
))
3859 else if (!_cups_strcasecmp(username
, name
))
3861 #endif /* HAVE_MBR_UID_TO_UUID */
3863 if ((name
!= NULL
) == p
->deny_users
)
3865 cupsdLogMessage(CUPSD_LOG_INFO
,
3866 "Denying user \"%s\" access to printer \"%s\"...",
3876 if (p
->k_limit
|| p
->page_limit
)
3878 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3880 cupsdLogMessage(CUPSD_LOG_ERROR
,
3881 "Unable to allocate quota data for user \"%s\"",
3886 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3887 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3889 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3896 * If we have gotten this far, we're done!
3904 * 'close_job()' - Close a multi-file job.
3908 close_job(cupsd_client_t
*con
, /* I - Client connection */
3909 ipp_attribute_t
*uri
) /* I - Printer URI */
3911 cupsd_job_t
*job
; /* Job */
3912 ipp_attribute_t
*attr
; /* Attribute */
3913 char job_uri
[HTTP_MAX_URI
],
3915 username
[256]; /* User name */
3918 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "close_job(%p[%d], %s)", con
,
3919 con
->number
, uri
->values
[0].string
.text
);
3922 * See if we have a job URI or a printer URI...
3925 if (strcmp(uri
->name
, "printer-uri"))
3928 * job-uri is not supported by Close-Job!
3931 send_ipp_status(con
, IPP_BAD_REQUEST
,
3932 _("Close-Job doesn't support the job-uri attribute."));
3937 * Got a printer URI; see if we also have a job-id attribute...
3940 if ((attr
= ippFindAttribute(con
->request
, "job-id",
3941 IPP_TAG_INTEGER
)) == NULL
)
3943 send_ipp_status(con
, IPP_BAD_REQUEST
,
3944 _("Got a printer-uri attribute but no job-id."));
3948 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
3951 * Nope - return a "not found" error...
3954 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
3955 attr
->values
[0].integer
);
3960 * See if the job is owned by the requesting user...
3963 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3965 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
3966 cupsdFindDest(job
->dest
));
3971 * Add any ending sheet...
3974 if (cupsdTimeoutJob(job
))
3977 if (job
->state_value
== IPP_JOB_STOPPED
)
3979 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3980 job
->state_value
= IPP_JOB_PENDING
;
3982 else if (job
->state_value
== IPP_JOB_HELD
)
3984 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
3985 IPP_TAG_KEYWORD
)) == NULL
)
3986 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
3988 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
3990 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
3991 job
->state_value
= IPP_JOB_PENDING
;
3996 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
3999 * Fill in the response info...
4002 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4003 con
->clientname
, con
->clientport
, "/jobs/%d", job
->id
);
4004 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
4007 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4009 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4012 con
->response
->request
.status
.status_code
= IPP_OK
;
4015 * Start the job if necessary...
4023 * 'copy_attrs()' - Copy attributes from one request to another.
4027 copy_attrs(ipp_t
*to
, /* I - Destination request */
4028 ipp_t
*from
, /* I - Source request */
4029 cups_array_t
*ra
, /* I - Requested attributes */
4030 ipp_tag_t group
, /* I - Group to copy */
4031 int quickcopy
, /* I - Do a quick copy? */
4032 cups_array_t
*exclude
) /* I - Attributes to exclude? */
4034 ipp_attribute_t
*fromattr
; /* Source attribute */
4037 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4038 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
4039 to
, from
, ra
, group
, quickcopy
);
4044 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
4047 * Filter attributes as needed...
4050 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
4051 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
4054 if (!strcmp(fromattr
->name
, "document-password") ||
4055 !strcmp(fromattr
->name
, "job-authorization-uri") ||
4056 !strcmp(fromattr
->name
, "job-password") ||
4057 !strcmp(fromattr
->name
, "job-password-encryption") ||
4058 !strcmp(fromattr
->name
, "job-printer-uri"))
4062 (cupsArrayFind(exclude
, fromattr
->name
) ||
4063 cupsArrayFind(exclude
, "all")))
4066 * We need to exclude this attribute for security reasons; we require the
4067 * job-id attribute regardless of the security settings for IPP
4070 * The job-printer-uri attribute is handled by copy_job_attrs().
4072 * Subscription attribute security is handled by copy_subscription_attrs().
4075 if (strcmp(fromattr
->name
, "job-id"))
4079 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
4082 * Don't send collection attributes by default to IPP/1.x clients
4083 * since many do not support collections. Also don't send
4084 * media-col-database unless specifically requested by the client.
4087 if (fromattr
->value_tag
== IPP_TAG_BEGIN_COLLECTION
&&
4089 (to
->request
.status
.version
[0] == 1 ||
4090 !strcmp(fromattr
->name
, "media-col-database")))
4093 ippCopyAttribute(to
, fromattr
, quickcopy
);
4100 * 'copy_banner()' - Copy a banner file to the requests directory for the
4104 static int /* O - Size of banner file in kbytes */
4105 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
4106 cupsd_job_t
*job
, /* I - Job information */
4107 const char *name
) /* I - Name of banner */
4109 int i
; /* Looping var */
4110 int kbytes
; /* Size of banner file in kbytes */
4111 char filename
[1024]; /* Job filename */
4112 cupsd_banner_t
*banner
; /* Pointer to banner */
4113 cups_file_t
*in
; /* Input file */
4114 cups_file_t
*out
; /* Output file */
4115 int ch
; /* Character from file */
4116 char attrname
[255], /* Name of attribute */
4117 *s
; /* Pointer into name */
4118 ipp_attribute_t
*attr
; /* Attribute */
4121 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4122 "copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
4123 con
, con
? con
->number
: -1, job
, job
->id
,
4124 name
? name
: "(null)");
4127 * Find the banner; return if not found or "none"...
4130 if (!name
|| !strcmp(name
, "none") ||
4131 (banner
= cupsdFindBanner(name
)) == NULL
)
4135 * Open the banner and job files...
4138 if (add_file(con
, job
, banner
->filetype
, 0))
4141 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
4143 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
4145 cupsdLogMessage(CUPSD_LOG_ERROR
,
4146 "Unable to create banner job file %s - %s",
4147 filename
, strerror(errno
));
4152 fchmod(cupsFileNumber(out
), 0640);
4153 fchown(cupsFileNumber(out
), RunUser
, Group
);
4156 * Try the localized banner file under the subdirectory...
4159 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
4161 if (strlen(attrname
) > 2 && attrname
[2] == '-')
4164 * Convert ll-cc to ll_CC...
4168 attrname
[3] = (char)toupper(attrname
[3] & 255);
4169 attrname
[4] = (char)toupper(attrname
[4] & 255);
4172 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4175 if (access(filename
, 0) && strlen(attrname
) > 2)
4178 * Wasn't able to find "ll_CC" locale file; try the non-national
4179 * localization banner directory.
4184 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
4188 if (access(filename
, 0))
4191 * Use the non-localized banner file.
4194 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
4197 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
4201 cupsdLogMessage(CUPSD_LOG_ERROR
,
4202 "Unable to open banner template file %s - %s",
4203 filename
, strerror(errno
));
4209 * Parse the file to the end...
4212 while ((ch
= cupsFileGetChar(in
)) != EOF
)
4216 * Get an attribute name...
4219 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
4220 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
4222 else if (s
< (attrname
+ sizeof(attrname
) - 1))
4232 * Ignore { followed by stuff that is not an attribute name...
4235 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
4240 * See if it is defined...
4243 if (attrname
[0] == '?')
4248 if (!strcmp(s
, "printer-name"))
4250 cupsFilePuts(out
, job
->dest
);
4253 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
4256 * See if we have a leading question mark...
4259 if (attrname
[0] != '?')
4262 * Nope, write to file as-is; probably a PostScript procedure...
4265 cupsFilePrintf(out
, "{%s}", attrname
);
4272 * Output value(s)...
4275 for (i
= 0; i
< attr
->num_values
; i
++)
4278 cupsFilePutChar(out
, ',');
4280 switch (attr
->value_tag
)
4282 case IPP_TAG_INTEGER
:
4284 if (!strncmp(s
, "time-at-", 8))
4286 struct timeval tv
; /* Time value */
4288 tv
.tv_sec
= attr
->values
[i
].integer
;
4291 cupsFilePuts(out
, cupsdGetDateTime(&tv
, CUPSD_TIME_STANDARD
));
4294 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
4297 case IPP_TAG_BOOLEAN
:
4298 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
4301 case IPP_TAG_NOVALUE
:
4302 cupsFilePuts(out
, "novalue");
4305 case IPP_TAG_RANGE
:
4306 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
4307 attr
->values
[i
].range
.upper
);
4310 case IPP_TAG_RESOLUTION
:
4311 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
4312 attr
->values
[i
].resolution
.yres
,
4313 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4318 case IPP_TAG_STRING
:
4321 case IPP_TAG_KEYWORD
:
4322 case IPP_TAG_CHARSET
:
4323 case IPP_TAG_LANGUAGE
:
4324 if (!_cups_strcasecmp(banner
->filetype
->type
, "postscript"))
4327 * Need to quote strings for PS banners...
4332 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
4334 if (*p
== '(' || *p
== ')' || *p
== '\\')
4336 cupsFilePutChar(out
, '\\');
4337 cupsFilePutChar(out
, *p
);
4339 else if (*p
< 32 || *p
> 126)
4340 cupsFilePrintf(out
, "\\%03o", *p
& 255);
4342 cupsFilePutChar(out
, *p
);
4346 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
4350 break; /* anti-compiler-warning-code */
4354 else if (ch
== '\\') /* Quoted char */
4356 ch
= cupsFileGetChar(in
);
4358 if (ch
!= '{') /* Only do special handling for \{ */
4359 cupsFilePutChar(out
, '\\');
4361 cupsFilePutChar(out
, ch
);
4364 cupsFilePutChar(out
, ch
);
4368 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
4370 job
->koctets
+= kbytes
;
4372 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
4373 attr
->values
[0].integer
+= kbytes
;
4382 * 'copy_file()' - Copy a PPD file...
4385 static int /* O - 0 = success, -1 = error */
4386 copy_file(const char *from
, /* I - Source file */
4387 const char *to
, /* I - Destination file */
4388 mode_t mode
) /* I - Permissions */
4390 cups_file_t
*src
, /* Source file */
4391 *dst
; /* Destination file */
4392 int bytes
; /* Bytes to read/write */
4393 char buffer
[2048]; /* Copy buffer */
4396 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
4399 * Open the source and destination file for a copy...
4402 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
4405 if ((dst
= cupsdCreateConfFile(to
, mode
)) == NULL
)
4412 * Copy the source file to the destination...
4415 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
4416 if (cupsFileWrite(dst
, buffer
, (size_t)bytes
) < bytes
)
4424 * Close both files and return...
4429 return (cupsdCloseCreatedConfFile(dst
, to
));
4434 * 'copy_model()' - Copy a PPD model file, substituting default values
4438 static int /* O - 0 = success, -1 = error */
4439 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4440 const char *from
, /* I - Source file */
4441 const char *to
) /* I - Destination file */
4443 fd_set input
; /* select() input set */
4444 struct timeval timeout
; /* select() timeout */
4445 int maxfd
; /* Max file descriptor for select() */
4446 char tempfile
[1024]; /* Temporary PPD file */
4447 int tempfd
; /* Temporary PPD file descriptor */
4448 int temppid
; /* Process ID of cups-driverd */
4449 int temppipe
[2]; /* Temporary pipes */
4450 char *argv
[4], /* Command-line arguments */
4451 *envp
[MAX_ENV
]; /* Environment */
4452 cups_file_t
*src
, /* Source file */
4453 *dst
; /* Destination file */
4454 ppd_file_t
*ppd
; /* PPD file */
4455 int bytes
, /* Bytes from pipe */
4456 total
; /* Total bytes from pipe */
4457 char buffer
[2048]; /* Copy buffer */
4458 int i
; /* Looping var */
4459 char option
[PPD_MAX_NAME
], /* Option name */
4460 choice
[PPD_MAX_NAME
]; /* Choice name */
4461 ppd_size_t
*size
; /* Default size */
4462 int num_defaults
; /* Number of default options */
4463 cups_option_t
*defaults
; /* Default options */
4464 char cups_protocol
[PPD_MAX_LINE
];
4465 /* cupsProtocol attribute */
4468 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con
, from
, to
);
4471 * Run cups-driverd to get the PPD file...
4474 argv
[0] = "cups-driverd";
4476 argv
[2] = (char *)from
;
4479 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4481 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4482 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->number
);
4483 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4484 if (tempfd
< 0 || cupsdOpenPipe(temppipe
))
4487 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4488 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4490 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4491 -1, -1, 0, DefaultProfile
, NULL
, &temppid
))
4502 * Wait up to 30 seconds for the PPD file to be copied...
4507 if (temppipe
[0] > CGIPipes
[0])
4508 maxfd
= temppipe
[0] + 1;
4510 maxfd
= CGIPipes
[0] + 1;
4515 * See if we have data ready...
4519 FD_SET(temppipe
[0], &input
);
4520 FD_SET(CGIPipes
[0], &input
);
4522 timeout
.tv_sec
= 30;
4523 timeout
.tv_usec
= 0;
4525 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4535 * We have timed out...
4541 if (FD_ISSET(temppipe
[0], &input
))
4544 * Read the PPD file from the pipe, and write it to the PPD file.
4547 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4549 if (write(tempfd
, buffer
, (size_t)bytes
) < bytes
)
4558 if (FD_ISSET(CGIPipes
[0], &input
))
4568 * No data from cups-deviced...
4571 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file");
4577 * Open the source file for a copy...
4580 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4587 * Read the source file and see what page sizes are supported...
4590 if ((ppd
= _ppdOpen(src
, _PPD_LOCALIZATION_NONE
)) == NULL
)
4598 * Open the destination (if possible) and set the default options...
4603 cups_protocol
[0] = '\0';
4605 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4608 * Read all of the default lines from the old PPD...
4611 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4612 if (!strncmp(buffer
, "*Default", 8))
4615 * Add the default option...
4618 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4619 choice
, sizeof(choice
)))
4621 ppd_option_t
*ppdo
; /* PPD option */
4625 * Only add the default if the default hasn't already been
4626 * set and the choice exists in the new PPD...
4629 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4630 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4631 ppdFindChoice(ppdo
, choice
))
4632 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4636 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4637 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4641 else if ((size
= ppdPageSize(ppd
, DefaultPaperSize
)) != NULL
)
4644 * Add the default media sizes...
4647 num_defaults
= cupsAddOption("PageSize", size
->name
,
4648 num_defaults
, &defaults
);
4649 num_defaults
= cupsAddOption("PageRegion", size
->name
,
4650 num_defaults
, &defaults
);
4651 num_defaults
= cupsAddOption("PaperDimension", size
->name
,
4652 num_defaults
, &defaults
);
4653 num_defaults
= cupsAddOption("ImageableArea", size
->name
,
4654 num_defaults
, &defaults
);
4660 * Open the destination file for a copy...
4663 if ((dst
= cupsdCreateConfFile(to
, ConfigFilePerm
)) == NULL
)
4665 cupsFreeOptions(num_defaults
, defaults
);
4672 * Copy the source file to the destination...
4675 cupsFileRewind(src
);
4677 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4679 if (!strncmp(buffer
, "*Default", 8))
4682 * Check for an previous default option choice...
4685 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4686 choice
, sizeof(choice
)))
4688 const char *val
; /* Default option value */
4691 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4694 * Substitute the previous choice...
4697 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4702 cupsFilePrintf(dst
, "%s\n", buffer
);
4705 if (cups_protocol
[0])
4706 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4708 cupsFreeOptions(num_defaults
, defaults
);
4711 * Close both files and return...
4718 return (cupsdCloseCreatedConfFile(dst
, to
));
4723 * 'copy_job_attrs()' - Copy job attributes.
4727 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4728 cupsd_job_t
*job
, /* I - Job */
4729 cups_array_t
*ra
, /* I - Requested attributes array */
4730 cups_array_t
*exclude
) /* I - Private attributes array */
4732 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4736 * Send the requested attributes for each job...
4739 if (!cupsArrayFind(exclude
, "all"))
4741 if ((!exclude
|| !cupsArrayFind(exclude
, "number-of-documents")) &&
4742 (!ra
|| cupsArrayFind(ra
, "number-of-documents")))
4743 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4744 "number-of-documents", job
->num_files
);
4746 if ((!exclude
|| !cupsArrayFind(exclude
, "job-media-progress")) &&
4747 (!ra
|| cupsArrayFind(ra
, "job-media-progress")))
4748 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4749 "job-media-progress", job
->progress
);
4751 if ((!exclude
|| !cupsArrayFind(exclude
, "job-more-info")) &&
4752 (!ra
|| cupsArrayFind(ra
, "job-more-info")))
4754 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "http",
4755 NULL
, con
->clientname
, con
->clientport
, "/jobs/%d",
4757 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4758 "job-more-info", NULL
, job_uri
);
4761 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4762 (!exclude
|| !cupsArrayFind(exclude
, "job-preserved")) &&
4763 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4764 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4765 job
->num_files
> 0);
4767 if ((!exclude
|| !cupsArrayFind(exclude
, "job-printer-up-time")) &&
4768 (!ra
|| cupsArrayFind(ra
, "job-printer-up-time")))
4769 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4770 "job-printer-up-time", time(NULL
));
4773 if (!ra
|| cupsArrayFind(ra
, "job-printer-uri"))
4775 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4776 con
->clientname
, con
->clientport
,
4777 (job
->dtype
& CUPS_PRINTER_CLASS
) ? "/classes/%s" :
4780 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4781 "job-printer-uri", NULL
, job_uri
);
4784 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4786 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4787 con
->clientname
, con
->clientport
, "/jobs/%d",
4789 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4790 "job-uri", NULL
, job_uri
);
4795 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0, exclude
);
4800 * Generate attributes from the job structure...
4803 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-completed")))
4804 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-completed", ippTimeToDate(job
->completed_time
));
4806 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "date-time-at-creation")))
4807 ippAddDate(con
->response
, IPP_TAG_JOB
, "date-time-at-creation", ippTimeToDate(job
->creation_time
));
4809 if (!ra
|| cupsArrayFind(ra
, "job-id"))
4810 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4812 if (!ra
|| cupsArrayFind(ra
, "job-k-octets"))
4813 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-k-octets", job
->koctets
);
4815 if (job
->name
&& (!ra
|| cupsArrayFind(ra
, "job-name")))
4816 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
, job
->name
);
4818 if (job
->username
&& (!ra
|| cupsArrayFind(ra
, "job-originating-user-name")))
4819 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-originating-user-name", NULL
, job
->username
);
4821 if (!ra
|| cupsArrayFind(ra
, "job-state"))
4822 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state", (int)job
->state_value
);
4824 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4826 switch (job
->state_value
)
4828 default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
4830 case IPP_JSTATE_ABORTED
:
4831 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-aborted-by-system");
4833 case IPP_JSTATE_CANCELED
:
4834 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-canceled-by-user");
4836 case IPP_JSTATE_COMPLETED
:
4837 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons", NULL
, "job-completed-successfully");
4842 if (job
->completed_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-completed")))
4843 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-completed", (int)job
->completed_time
);
4845 if (job
->creation_time
&& (!ra
|| cupsArrayFind(ra
, "time-at-creation")))
4846 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation", (int)job
->creation_time
);
4852 * 'copy_printer_attrs()' - Copy printer attributes.
4857 cupsd_client_t
*con
, /* I - Client connection */
4858 cupsd_printer_t
*printer
, /* I - Printer */
4859 cups_array_t
*ra
) /* I - Requested attributes array */
4861 char uri
[HTTP_MAX_URI
]; /* URI value */
4862 time_t curtime
; /* Current time */
4863 int i
; /* Looping var */
4864 int is_encrypted
= httpIsEncrypted(con
->http
);
4865 /* Is the connection encrypted? */
4869 * Copy the printer attributes to the response using requested-attributes
4870 * and document-format attributes that may be provided by the client.
4873 _cupsRWLockRead(&printer
->lock
);
4875 curtime
= time(NULL
);
4877 if (!ra
|| cupsArrayFind(ra
, "marker-change-time"))
4878 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "marker-change-time", printer
->marker_time
);
4880 if (printer
->num_printers
> 0 && (!ra
|| cupsArrayFind(ra
, "member-uris")))
4882 ipp_attribute_t
*member_uris
; /* member-uris attribute */
4883 cupsd_printer_t
*p2
; /* Printer in class */
4884 ipp_attribute_t
*p2_uri
; /* printer-uri-supported for class printer */
4887 if ((member_uris
= ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "member-uris", printer
->num_printers
, NULL
, NULL
)) != NULL
)
4889 for (i
= 0; i
< printer
->num_printers
; i
++)
4891 p2
= printer
->printers
[i
];
4893 if ((p2_uri
= ippFindAttribute(p2
->attrs
, "printer-uri-supported", IPP_TAG_URI
)) != NULL
)
4895 member_uris
->values
[i
].string
.text
= _cupsStrRetain(p2_uri
->values
[0].string
.text
);
4899 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, (p2
->type
& CUPS_PRINTER_CLASS
) ? "/classes/%s" : "/printers/%s", p2
->name
);
4900 member_uris
->values
[i
].string
.text
= _cupsStrAlloc(uri
);
4906 if (printer
->alert
&& (!ra
|| cupsArrayFind(ra
, "printer-alert")))
4907 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_STRING
, "printer-alert", NULL
, printer
->alert
);
4909 if (printer
->alert_description
&& (!ra
|| cupsArrayFind(ra
, "printer-alert-description")))
4910 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-alert-description", NULL
, printer
->alert_description
);
4912 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-date-time"))
4913 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-config-change-date-time", ippTimeToDate(printer
->config_time
));
4915 if (!ra
|| cupsArrayFind(ra
, "printer-config-change-time"))
4916 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-config-change-time", printer
->config_time
);
4918 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4919 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time", ippTimeToDate(curtime
));
4921 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
4922 if (!ra
|| cupsArrayFind(ra
, "printer-dns-sd-name"))
4924 if (printer
->reg_name
)
4925 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-dns-sd-name", NULL
, printer
->reg_name
);
4927 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
, "printer-dns-sd-name", 0);
4929 #endif /* HAVE_DNSSD || HAVE_AVAHI */
4931 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4932 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-error-policy", NULL
, printer
->error_policy
);
4934 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy-supported"))
4936 static const char * const errors
[] =/* printer-error-policy-supported values */
4939 "retry-current-job",
4944 if (printer
->type
& CUPS_PRINTER_CLASS
)
4945 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_NAME
), "printer-error-policy-supported", NULL
, "retry-current-job");
4947 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_NAME
), "printer-error-policy-supported", sizeof(errors
) / sizeof(errors
[0]), NULL
, errors
);
4950 if (!ra
|| cupsArrayFind(ra
, "printer-icons"))
4952 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "https" : "http", NULL
, con
->clientname
, con
->clientport
, "/icons/%s.png", printer
->name
);
4953 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-icons", NULL
, uri
);
4954 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-icons=\"%s\"", uri
);
4957 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4958 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
4960 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4961 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared", (char)printer
->shared
);
4963 if (!ra
|| cupsArrayFind(ra
, "printer-is-temporary"))
4964 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-temporary", (char)printer
->temporary
);
4966 if (!ra
|| cupsArrayFind(ra
, "printer-more-info"))
4968 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "https" : "http", NULL
, con
->clientname
, con
->clientport
, (printer
->type
& CUPS_PRINTER_CLASS
) ? "/classes/%s" : "/printers/%s", printer
->name
);
4969 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-more-info", NULL
, uri
);
4972 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4973 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-op-policy", NULL
, printer
->op_policy
);
4975 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4976 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
4978 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-date-time"))
4979 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-state-change-date-time", ippTimeToDate(printer
->state_time
));
4981 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4982 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-state-change-time", printer
->state_time
);
4984 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4985 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-state-message", NULL
, printer
->state_message
);
4987 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4988 add_printer_state_reasons(con
, printer
);
4990 if (!ra
|| cupsArrayFind(ra
, "printer-strings-uri"))
4992 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "https" : "http", NULL
, con
->clientname
, con
->clientport
, "/strings/%s.strings", printer
->name
);
4993 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-strings-uri", NULL
, uri
);
4994 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-strings-uri=\"%s\"", uri
);
4997 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4999 cups_ptype_t type
; /* printer-type value */
5002 * Add the CUPS-specific printer-type attribute...
5005 type
= printer
->type
;
5007 if (printer
== DefaultPrinter
)
5008 type
|= CUPS_PRINTER_DEFAULT
;
5010 if (!printer
->accepting
)
5011 type
|= CUPS_PRINTER_REJECTING
;
5013 if (!printer
->shared
)
5014 type
|= CUPS_PRINTER_NOT_SHARED
;
5016 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type", (int)type
);
5019 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
5020 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-up-time", curtime
);
5022 if (!ra
|| cupsArrayFind(ra
, "printer-uri-supported"))
5024 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), is_encrypted
? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, (printer
->type
& CUPS_PRINTER_CLASS
) ? "/classes/%s" : "/printers/%s", printer
->name
);
5025 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5026 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"", uri
);
5029 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
5030 add_queued_job_count(con
, printer
);
5032 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5033 if (printer
->ppd_attrs
)
5034 copy_attrs(con
->response
, printer
->ppd_attrs
, ra
, IPP_TAG_ZERO
, 0, NULL
);
5035 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
, NULL
);
5037 _cupsRWUnlock(&printer
->lock
);
5042 * 'copy_subscription_attrs()' - Copy subscription attributes.
5046 copy_subscription_attrs(
5047 cupsd_client_t
*con
, /* I - Client connection */
5048 cupsd_subscription_t
*sub
, /* I - Subscription */
5049 cups_array_t
*ra
, /* I - Requested attributes array */
5050 cups_array_t
*exclude
) /* I - Private attributes array */
5052 ipp_attribute_t
*attr
; /* Current attribute */
5053 char printer_uri
[HTTP_MAX_URI
];
5055 int count
; /* Number of events */
5056 unsigned mask
; /* Current event mask */
5057 const char *name
; /* Current event name */
5060 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5061 "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
5062 con
, sub
, ra
, exclude
);
5065 * Copy the subscription attributes to the response using the
5066 * requested-attributes attribute that may be provided by the client.
5069 if (!exclude
|| !cupsArrayFind(exclude
, "all"))
5071 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-events")) &&
5072 (!ra
|| cupsArrayFind(ra
, "notify-events")))
5074 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_subscription_attrs: notify-events");
5076 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
5079 * Simple event list...
5082 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "notify-events", NULL
, name
);
5087 * Complex event list...
5090 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5091 if (sub
->mask
& mask
)
5094 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "notify-events", count
, NULL
, NULL
);
5096 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
5097 if (sub
->mask
& mask
)
5099 attr
->values
[count
].string
.text
= (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
5106 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-lease-duration")) &&
5107 (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration"))))
5108 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5109 "notify-lease-duration", sub
->lease
);
5111 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-recipient-uri")) &&
5112 (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri"))))
5113 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5114 "notify-recipient-uri", NULL
, sub
->recipient
);
5115 else if ((!exclude
|| !cupsArrayFind(exclude
, "notify-pull-method")) &&
5116 (!ra
|| cupsArrayFind(ra
, "notify-pull-method")))
5117 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
5118 "notify-pull-method", NULL
, "ippget");
5120 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-subscriber-user-name")) &&
5121 (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name")))
5122 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
5123 "notify-subscriber-user-name", NULL
, sub
->owner
);
5125 if ((!exclude
|| !cupsArrayFind(exclude
, "notify-time-interval")) &&
5126 (!ra
|| cupsArrayFind(ra
, "notify-time-interval")))
5127 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5128 "notify-time-interval", sub
->interval
);
5130 if (sub
->user_data_len
> 0 &&
5131 (!exclude
|| !cupsArrayFind(exclude
, "notify-user-data")) &&
5132 (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
5133 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
5134 sub
->user_data
, sub
->user_data_len
);
5137 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
5138 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5139 "notify-job-id", sub
->job
->id
);
5141 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
5143 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
5144 "ipp", NULL
, con
->clientname
, con
->clientport
,
5145 "/printers/%s", sub
->dest
->name
);
5146 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
5147 "notify-printer-uri", NULL
, printer_uri
);
5150 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
5151 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5152 "notify-subscription-id", sub
->id
);
5157 * 'create_job()' - Print a file to a printer or class.
5161 create_job(cupsd_client_t
*con
, /* I - Client connection */
5162 ipp_attribute_t
*uri
) /* I - Printer URI */
5164 int i
; /* Looping var */
5165 cupsd_printer_t
*printer
; /* Printer */
5166 cupsd_job_t
*job
; /* New job */
5167 static const char * const forbidden_attrs
[] =
5168 { /* List of forbidden attributes */
5172 "document-natural-language"
5176 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
5177 con
->number
, uri
->values
[0].string
.text
);
5180 * Is the destination valid?
5183 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
5189 send_ipp_status(con
, IPP_NOT_FOUND
,
5190 _("The printer or class does not exist."));
5195 * Check for invalid Create-Job attributes and log a warning or error depending
5196 * on whether cupsd is running in "strict conformance" mode...
5200 i
< (int)(sizeof(forbidden_attrs
) / sizeof(forbidden_attrs
[0]));
5202 if (ippFindAttribute(con
->request
, forbidden_attrs
[i
], IPP_TAG_ZERO
))
5204 if (StrictConformance
)
5206 send_ipp_status(con
, IPP_BAD_REQUEST
,
5207 _("The '%s' operation attribute cannot be supplied in a "
5208 "Create-Job request."), forbidden_attrs
[i
]);
5212 cupsdLogMessage(CUPSD_LOG_WARN
,
5213 "Unexpected '%s' operation attribute in a Create-Job "
5214 "request.", forbidden_attrs
[i
]);
5218 * Create the job object...
5221 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
5224 job
->pending_timeout
= 1;
5227 * Save and log the job...
5230 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
5231 job
->dest
, job
->username
);
5236 * 'create_local_bg_thread()' - Background thread for creating a local print queue.
5239 static void * /* O - Exit status */
5240 create_local_bg_thread(
5241 cupsd_printer_t
*printer
) /* I - Printer */
5243 cups_file_t
*from
, /* Source file */
5244 *to
; /* Destination file */
5245 char fromppd
[1024], /* Source PPD */
5246 toppd
[1024], /* Destination PPD */
5247 scheme
[32], /* URI scheme */
5248 userpass
[256], /* User:pass */
5249 host
[256], /* Hostname */
5250 resource
[1024], /* Resource path */
5251 line
[1024]; /* Line from PPD */
5252 int port
; /* Port number */
5253 http_encryption_t encryption
; /* Type of encryption to use */
5254 http_t
*http
; /* Connection to printer */
5255 ipp_t
*request
, /* Request to printer */
5256 *response
; /* Response from printer */
5257 ipp_attribute_t
*attr
; /* Attribute in response */
5258 ipp_status_t status
; /* Status code */
5259 static const char * const pattrs
[] = /* Printer attributes we need */
5262 "media-col-database"
5267 * Try connecting to the printer...
5270 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Generating PPD file from \"%s\"...", printer
->name
, printer
->device_uri
);
5272 if (httpSeparateURI(HTTP_URI_CODING_ALL
, printer
->device_uri
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
5274 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Bad device URI \"%s\".", printer
->name
, printer
->device_uri
);
5278 if (!strcmp(scheme
, "ipps") || port
== 443)
5279 encryption
= HTTP_ENCRYPTION_ALWAYS
;
5281 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
5283 if ((http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
)) == NULL
)
5285 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to connect to %s:%d: %s", printer
->name
, host
, port
, cupsLastErrorString());
5290 * Query the printer for its capabilities...
5293 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer
->name
, host
, port
);
5295 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5296 ippSetVersion(request
, 2, 0);
5297 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5298 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", (int)(sizeof(pattrs
) / sizeof(pattrs
[0])), NULL
, pattrs
);
5300 response
= cupsDoRequest(http
, request
, resource
);
5301 status
= cupsLastError();
5303 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Get-Printer-Attributes returned %s (%s)", printer
->name
, ippErrorString(cupsLastError()), cupsLastErrorString());
5305 if (status
== IPP_STATUS_ERROR_BAD_REQUEST
|| status
== IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
5308 * Try request using IPP/1.1, in case we are talking to an old CUPS server or
5312 ippDelete(response
);
5314 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: Re-sending Get-Printer-Attributes request using IPP/1.1...", printer
->name
);
5316 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
5317 ippSetVersion(request
, 1, 1);
5318 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, printer
->device_uri
);
5319 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "requested-attributes", NULL
, "all");
5321 response
= cupsDoRequest(http
, request
, resource
);
5323 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s: IPP/1.1 Get-Printer-Attributes returned %s (%s)", printer
->name
, ippErrorString(cupsLastError()), cupsLastErrorString());
5326 // TODO: Grab printer icon file...
5330 * Write the PPD for the queue...
5333 if (_ppdCreateFromIPP(fromppd
, sizeof(fromppd
), response
))
5335 _cupsRWLockWrite(&printer
->lock
);
5337 if ((!printer
->info
|| !*(printer
->info
)) && (attr
= ippFindAttribute(response
, "printer-info", IPP_TAG_TEXT
)) != NULL
)
5338 cupsdSetString(&printer
->info
, ippGetString(attr
, 0, NULL
));
5340 if ((!printer
->location
|| !*(printer
->location
)) && (attr
= ippFindAttribute(response
, "printer-location", IPP_TAG_TEXT
)) != NULL
)
5341 cupsdSetString(&printer
->location
, ippGetString(attr
, 0, NULL
));
5343 if ((!printer
->geo_location
|| !*(printer
->geo_location
)) && (attr
= ippFindAttribute(response
, "printer-geo-location", IPP_TAG_URI
)) != NULL
)
5344 cupsdSetString(&printer
->geo_location
, ippGetString(attr
, 0, NULL
));
5346 _cupsRWUnlock(&printer
->lock
);
5348 if ((from
= cupsFileOpen(fromppd
, "r")) == NULL
)
5350 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to read generated PPD: %s", printer
->name
, strerror(errno
));
5354 snprintf(toppd
, sizeof(toppd
), "%s/ppd/%s.ppd", ServerRoot
, printer
->name
);
5355 if ((to
= cupsdCreateConfFile(toppd
, ConfigFilePerm
)) == NULL
)
5357 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: Unable to create PPD for printer: %s", printer
->name
, strerror(errno
));
5358 cupsFileClose(from
);
5362 while (cupsFileGets(from
, line
, sizeof(line
)))
5363 cupsFilePrintf(to
, "%s\n", line
);
5365 cupsFileClose(from
);
5366 if (!cupsdCloseCreatedConfFile(to
, toppd
))
5368 printer
->config_time
= time(NULL
);
5369 printer
->state
= IPP_PSTATE_IDLE
;
5370 printer
->accepting
= 1;
5372 cupsdSetPrinterAttrs(printer
);
5374 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
, "Printer \"%s\" is now available.", printer
->name
);
5375 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" is now available.", printer
->name
);
5379 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: PPD creation failed: %s", printer
->name
, cupsLastErrorString());
5386 * 'create_local_printer()' - Create a local (temporary) print queue.
5390 create_local_printer(
5391 cupsd_client_t
*con
) /* I - Client connection */
5393 ipp_attribute_t
*device_uri
, /* device-uri attribute */
5394 *printer_geo_location
, /* printer-geo-location attribute */
5395 *printer_info
, /* printer-info attribute */
5396 *printer_location
, /* printer-location attribute */
5397 *printer_name
; /* printer-name attribute */
5398 cupsd_printer_t
*printer
; /* New printer */
5399 http_status_t status
; /* Policy status */
5400 char name
[128], /* Sanitized printer name */
5401 *nameptr
, /* Pointer into name */
5402 uri
[1024]; /* printer-uri-supported value */
5403 const char *ptr
; /* Pointer into attribute value */
5407 * Require local access to create a local printer...
5410 if (!httpAddrLocalhost(httpGetAddress(con
->http
)))
5412 send_ipp_status(con
, IPP_STATUS_ERROR_FORBIDDEN
, _("Only local users can create a local printer."));
5417 * Check any other policy limits...
5420 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5422 send_http_error(con
, status
, NULL
);
5427 * Grab needed attributes...
5430 if ((printer_name
= ippFindAttribute(con
->request
, "printer-name", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
|| ippGetValueTag(printer_name
) != IPP_TAG_NAME
)
5433 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "printer-name");
5434 else if (ippGetGroupTag(printer_name
) != IPP_TAG_PRINTER
)
5435 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "printer-name");
5437 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "printer-name");
5442 for (nameptr
= name
, ptr
= ippGetString(printer_name
, 0, NULL
); *ptr
&& nameptr
< (name
+ sizeof(name
) - 1); ptr
++)
5445 * Sanitize the printer name...
5448 if (_cups_isalnum(*ptr
))
5450 else if (nameptr
== name
|| nameptr
[-1] != '_')
5456 if ((device_uri
= ippFindAttribute(con
->request
, "device-uri", IPP_TAG_ZERO
)) == NULL
|| ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
|| ippGetValueTag(device_uri
) != IPP_TAG_URI
)
5459 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Missing required attribute \"%s\"."), "device-uri");
5460 else if (ippGetGroupTag(device_uri
) != IPP_TAG_PRINTER
)
5461 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is in the wrong group."), "device-uri");
5463 send_ipp_status(con
, IPP_STATUS_ERROR_BAD_REQUEST
, _("Attribute \"%s\" is the wrong value type."), "device-uri");
5468 printer_geo_location
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
);
5469 printer_info
= ippFindAttribute(con
->request
, "printer-info", IPP_TAG_TEXT
);
5470 printer_location
= ippFindAttribute(con
->request
, "printer-location", IPP_TAG_TEXT
);
5473 * See if the printer already exists...
5476 if ((printer
= cupsdFindDest(name
)) != NULL
)
5478 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_POSSIBLE
, _("Printer \"%s\" already exists."), name
);
5479 goto add_printer_attributes
;
5483 * Create the printer...
5486 if ((printer
= cupsdAddPrinter(name
)) == NULL
)
5488 send_ipp_status(con
, IPP_STATUS_ERROR_INTERNAL
, _("Unable to create printer."));
5492 printer
->shared
= 0;
5493 printer
->temporary
= 1;
5495 cupsdSetDeviceURI(printer
, ippGetString(device_uri
, 0, NULL
));
5497 if (printer_geo_location
)
5498 cupsdSetString(&printer
->geo_location
, ippGetString(printer_geo_location
, 0, NULL
));
5500 cupsdSetString(&printer
->info
, ippGetString(printer_info
, 0, NULL
));
5501 if (printer_location
)
5502 cupsdSetString(&printer
->location
, ippGetString(printer_location
, 0, NULL
));
5504 cupsdSetPrinterAttrs(printer
);
5507 * Run a background thread to create the PPD...
5510 _cupsThreadCreate((_cups_thread_func_t
)create_local_bg_thread
, printer
);
5513 * Return printer attributes...
5516 send_ipp_status(con
, IPP_STATUS_OK
, _("Local printer created."));
5518 add_printer_attributes
:
5520 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", (char)printer
->accepting
);
5521 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state", printer
->state
);
5522 add_printer_state_reasons(con
, printer
);
5524 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), httpIsEncrypted(con
->http
) ? "ipps" : "ipp", NULL
, con
->clientname
, con
->clientport
, "/printers/%s", printer
->name
);
5525 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uri-supported", NULL
, uri
);
5530 * 'create_requested_array()' - Create an array for the requested-attributes.
5533 static cups_array_t
* /* O - Array of attributes or NULL */
5534 create_requested_array(ipp_t
*request
) /* I - IPP request */
5536 cups_array_t
*ra
; /* Requested attributes array */
5540 * Create the array for standard attributes...
5543 ra
= ippCreateRequestedArray(request
);
5546 * Add CUPS defaults as needed...
5549 if (cupsArrayFind(ra
, "printer-defaults"))
5552 * Include user-set defaults...
5555 char *name
; /* Option name */
5557 cupsArrayRemove(ra
, "printer-defaults");
5559 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
5561 name
= (char *)cupsArrayNext(CommonDefaults
))
5562 if (!cupsArrayFind(ra
, name
))
5563 cupsArrayAdd(ra
, name
);
5571 * 'create_subscriptions()' - Create one or more notification subscriptions.
5575 create_subscriptions(
5576 cupsd_client_t
*con
, /* I - Client connection */
5577 ipp_attribute_t
*uri
) /* I - Printer URI */
5579 http_status_t status
; /* Policy status */
5580 int i
; /* Looping var */
5581 ipp_attribute_t
*attr
; /* Current attribute */
5582 cups_ptype_t dtype
; /* Destination type (printer/class) */
5583 char scheme
[HTTP_MAX_URI
],
5584 /* Scheme portion of URI */
5585 userpass
[HTTP_MAX_URI
],
5586 /* Username portion of URI */
5588 /* Host portion of URI */
5589 resource
[HTTP_MAX_URI
];
5590 /* Resource portion of URI */
5591 int port
; /* Port portion of URI */
5592 cupsd_printer_t
*printer
; /* Printer/class */
5593 cupsd_job_t
*job
; /* Job */
5594 int jobid
; /* Job ID */
5595 cupsd_subscription_t
*sub
; /* Subscription object */
5596 const char *username
, /* requesting-user-name or
5597 authenticated username */
5598 *recipient
, /* notify-recipient-uri */
5599 *pullmethod
; /* notify-pull-method */
5600 ipp_attribute_t
*user_data
; /* notify-user-data */
5601 int interval
, /* notify-time-interval */
5602 lease
; /* notify-lease-duration */
5603 unsigned mask
; /* notify-events */
5604 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
5605 *notify_lease
; /* notify-lease-duration(-default) */
5609 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5611 if (attr
->group_tag
!= IPP_TAG_ZERO
)
5612 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "g%04x v%04x %s", attr
->group_tag
,
5613 attr
->value_tag
, attr
->name
);
5615 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "----SEP----");
5620 * Is the destination valid?
5623 cupsdLogMessage(CUPSD_LOG_DEBUG
, "create_subscriptions(con=%p(%d), uri=\"%s\")", con
, con
->number
, uri
->values
[0].string
.text
);
5625 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5626 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
5627 sizeof(host
), &port
, resource
, sizeof(resource
));
5629 if (!strcmp(resource
, "/"))
5631 dtype
= (cups_ptype_t
)0;
5634 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5636 dtype
= (cups_ptype_t
)0;
5639 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5641 dtype
= CUPS_PRINTER_CLASS
;
5644 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5650 send_ipp_status(con
, IPP_NOT_FOUND
,
5651 _("The printer or class does not exist."));
5661 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5664 send_http_error(con
, status
, printer
);
5668 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5670 send_http_error(con
, status
, NULL
);
5675 * Get the user that is requesting the subscription...
5678 username
= get_username(con
);
5681 * Find the first subscription group attribute; return if we have
5685 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
5686 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5691 send_ipp_status(con
, IPP_BAD_REQUEST
,
5692 _("No subscription attributes in request."));
5697 * Process the subscription attributes in the request...
5700 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5708 lease
= DefaultLeaseDuration
;
5710 mask
= CUPSD_EVENT_NONE
;
5714 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5716 notify_lease
= ippFindAttribute(printer
->attrs
,
5717 "notify-lease-duration-default",
5721 lease
= notify_lease
->values
[0].integer
;
5725 notify_events
= NULL
;
5726 notify_lease
= NULL
;
5729 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5731 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5732 attr
->value_tag
== IPP_TAG_URI
)
5735 * Validate the recipient scheme against the ServerBin/notifier
5739 char notifier
[1024]; /* Notifier filename */
5742 recipient
= attr
->values
[0].string
.text
;
5744 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5745 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5746 host
, sizeof(host
), &port
,
5747 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5749 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5750 _("Bad notify-recipient-uri \"%s\"."), recipient
);
5751 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5752 "notify-status-code", IPP_URI_SCHEME
);
5756 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5758 if (access(notifier
, X_OK
) || !strcmp(scheme
, ".") || !strcmp(scheme
, ".."))
5760 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5761 _("notify-recipient-uri URI \"%s\" uses unknown "
5762 "scheme."), recipient
);
5763 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5764 "notify-status-code", IPP_URI_SCHEME
);
5768 if (!strcmp(scheme
, "rss") && !check_rss_recipient(recipient
))
5770 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5771 _("notify-recipient-uri URI \"%s\" is already used."),
5773 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5774 "notify-status-code", IPP_ATTRIBUTES
);
5778 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5779 attr
->value_tag
== IPP_TAG_KEYWORD
)
5781 pullmethod
= attr
->values
[0].string
.text
;
5783 if (strcmp(pullmethod
, "ippget"))
5785 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5786 _("Bad notify-pull-method \"%s\"."), pullmethod
);
5787 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5788 "notify-status-code", IPP_ATTRIBUTES
);
5792 else if (!strcmp(attr
->name
, "notify-charset") &&
5793 attr
->value_tag
== IPP_TAG_CHARSET
&&
5794 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5795 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5797 send_ipp_status(con
, IPP_CHARSET
,
5798 _("Character set \"%s\" not supported."),
5799 attr
->values
[0].string
.text
);
5802 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5803 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5804 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5806 send_ipp_status(con
, IPP_CHARSET
,
5807 _("Language \"%s\" not supported."),
5808 attr
->values
[0].string
.text
);
5811 else if (!strcmp(attr
->name
, "notify-user-data") &&
5812 attr
->value_tag
== IPP_TAG_STRING
)
5814 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5816 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5817 _("The notify-user-data value is too large "
5818 "(%d > 63 octets)."),
5819 attr
->values
[0].unknown
.length
);
5825 else if (!strcmp(attr
->name
, "notify-events") &&
5826 attr
->value_tag
== IPP_TAG_KEYWORD
)
5827 notify_events
= attr
;
5828 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5829 attr
->value_tag
== IPP_TAG_INTEGER
)
5830 lease
= attr
->values
[0].integer
;
5831 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5832 attr
->value_tag
== IPP_TAG_INTEGER
)
5833 interval
= attr
->values
[0].integer
;
5834 else if (!strcmp(attr
->name
, "notify-job-id") &&
5835 attr
->value_tag
== IPP_TAG_INTEGER
)
5836 jobid
= attr
->values
[0].integer
;
5843 for (i
= 0; i
< notify_events
->num_values
; i
++)
5844 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5849 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5852 if (!strncmp(recipient
, "mailto:", 7) && user_data
)
5854 char temp
[64]; /* Temporary string */
5856 memcpy(temp
, user_data
->values
[0].unknown
.data
, (size_t)user_data
->values
[0].unknown
.length
);
5857 temp
[user_data
->values
[0].unknown
.length
] = '\0';
5859 if (httpSeparateURI(HTTP_URI_CODING_ALL
, temp
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_OK
)
5861 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad notify-user-data \"%s\"."), temp
);
5862 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
, "notify-status-code", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
);
5869 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5870 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5871 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5873 if (!recipient
&& !pullmethod
)
5876 if (mask
== CUPSD_EVENT_NONE
)
5879 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5881 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5884 send_ipp_status(con
, IPP_BAD_REQUEST
,
5885 _("notify-events not specified."));
5890 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5892 cupsdLogMessage(CUPSD_LOG_INFO
,
5893 "create_subscriptions: Limiting notify-lease-duration to "
5896 lease
= MaxLeaseDuration
;
5901 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5903 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
5911 if ((sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0)) == NULL
)
5913 send_ipp_status(con
, IPP_TOO_MANY_SUBSCRIPTIONS
,
5914 _("There are too many subscriptions."));
5919 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for job %d.",
5922 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5923 "Added subscription #%d for printer \"%s\".",
5924 sub
->id
, printer
->name
);
5926 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription #%d for server.",
5929 sub
->interval
= interval
;
5931 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5933 cupsdSetString(&sub
->owner
, username
);
5937 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5938 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5939 (size_t)sub
->user_data_len
);
5942 ippAddSeparator(con
->response
);
5943 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5944 "notify-subscription-id", sub
->id
);
5946 con
->response
->request
.status
.status_code
= IPP_OK
;
5952 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
5957 * 'delete_printer()' - Remove a printer or class from the system.
5961 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5962 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5964 http_status_t status
; /* Policy status */
5965 cups_ptype_t dtype
; /* Destination type (printer/class) */
5966 cupsd_printer_t
*printer
; /* Printer/class */
5967 char filename
[1024]; /* Script/PPD filename */
5968 int temporary
; /* Temporary queue? */
5971 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5972 con
->number
, uri
->values
[0].string
.text
);
5975 * Do we have a valid URI?
5978 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5984 send_ipp_status(con
, IPP_NOT_FOUND
,
5985 _("The printer or class does not exist."));
5993 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5995 send_http_error(con
, status
, NULL
);
6000 * Remove old jobs...
6003 cupsdCancelJobs(printer
->name
, NULL
, 1);
6006 * Remove old subscriptions and send a "deleted printer" event...
6009 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
6010 "%s \"%s\" deleted by \"%s\".",
6011 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
6012 printer
->name
, get_username(con
));
6014 cupsdExpireSubscriptions(printer
, NULL
);
6017 * Remove any old PPD or script files...
6020 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
6023 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
,
6027 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, printer
->name
);
6030 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, printer
->name
);
6034 * Unregister color profiles...
6037 cupsdUnregisterColor(printer
);
6039 temporary
= printer
->temporary
;
6041 if (dtype
& CUPS_PRINTER_CLASS
)
6043 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
6044 printer
->name
, get_username(con
));
6046 cupsdDeletePrinter(printer
, 0);
6048 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6052 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
6053 printer
->name
, get_username(con
));
6055 if (cupsdDeletePrinter(printer
, 0) && !temporary
)
6056 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
6059 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
6063 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
6066 * Return with no errors...
6069 con
->response
->request
.status
.status_code
= IPP_OK
;
6074 * 'get_default()' - Get the default destination.
6078 get_default(cupsd_client_t
*con
) /* I - Client connection */
6080 http_status_t status
; /* Policy status */
6081 cups_array_t
*ra
; /* Requested attributes array */
6084 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->number
);
6090 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6092 send_http_error(con
, status
, NULL
);
6098 ra
= create_requested_array(con
->request
);
6100 copy_printer_attrs(con
, DefaultPrinter
, ra
);
6102 cupsArrayDelete(ra
);
6104 con
->response
->request
.status
.status_code
= IPP_OK
;
6107 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer."));
6112 * 'get_devices()' - Get the list of available devices on the local system.
6116 get_devices(cupsd_client_t
*con
) /* I - Client connection */
6118 http_status_t status
; /* Policy status */
6119 ipp_attribute_t
*limit
, /* limit attribute */
6120 *timeout
, /* timeout attribute */
6121 *requested
, /* requested-attributes attribute */
6122 *exclude
, /* exclude-schemes attribute */
6123 *include
; /* include-schemes attribute */
6124 char command
[1024], /* cups-deviced command */
6125 options
[2048], /* Options to pass to command */
6127 /* String for requested attributes */
6129 /* String for excluded schemes */
6131 /* String for included schemes */
6134 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->number
);
6140 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6142 send_http_error(con
, status
, NULL
);
6147 * Run cups-deviced command with the given options...
6150 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
6151 timeout
= ippFindAttribute(con
->request
, "timeout", IPP_TAG_INTEGER
);
6152 requested
= ippFindAttribute(con
->request
, "requested-attributes",
6154 exclude
= ippFindAttribute(con
->request
, "exclude-schemes", IPP_TAG_NAME
);
6155 include
= ippFindAttribute(con
->request
, "include-schemes", IPP_TAG_NAME
);
6158 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
6160 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
6163 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
6165 exclude_str
[0] = '\0';
6168 url_encode_attr(include
, include_str
, sizeof(include_str
));
6170 include_str
[0] = '\0';
6172 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
6173 snprintf(options
, sizeof(options
),
6174 "%d+%d+%d+%d+%s%s%s%s%s",
6175 con
->request
->request
.op
.request_id
,
6176 limit
? limit
->values
[0].integer
: 0,
6177 timeout
? timeout
->values
[0].integer
: 15,
6180 exclude_str
[0] ? "%20" : "", exclude_str
,
6181 include_str
[0] ? "%20" : "", include_str
);
6183 if (cupsdSendCommand(con
, command
, options
, 1))
6186 * Command started successfully, don't send an IPP response here...
6189 ippDelete(con
->response
);
6190 con
->response
= NULL
;
6195 * Command failed, return "internal error" so the user knows something
6199 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6200 _("cups-deviced failed to execute."));
6206 * 'get_document()' - Get a copy of a job file.
6210 get_document(cupsd_client_t
*con
, /* I - Client connection */
6211 ipp_attribute_t
*uri
) /* I - Job URI */
6213 http_status_t status
; /* Policy status */
6214 ipp_attribute_t
*attr
; /* Current attribute */
6215 int jobid
; /* Job ID */
6216 int docnum
; /* Document number */
6217 cupsd_job_t
*job
; /* Current job */
6218 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
6219 username
[HTTP_MAX_URI
], /* Username portion of URI */
6220 host
[HTTP_MAX_URI
], /* Host portion of URI */
6221 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6222 int port
; /* Port portion of URI */
6223 char filename
[1024], /* Filename for document */
6224 format
[1024]; /* Format for document */
6227 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_document(%p[%d], %s)", con
,
6228 con
->number
, uri
->values
[0].string
.text
);
6231 * See if we have a job URI or a printer URI...
6234 if (!strcmp(uri
->name
, "printer-uri"))
6237 * Got a printer URI; see if we also have a job-id attribute...
6240 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6241 IPP_TAG_INTEGER
)) == NULL
)
6243 send_ipp_status(con
, IPP_BAD_REQUEST
,
6244 _("Got a printer-uri attribute but no job-id."));
6248 jobid
= attr
->values
[0].integer
;
6253 * Got a job URI; parse it to get the job ID...
6256 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6257 sizeof(scheme
), username
, sizeof(username
), host
,
6258 sizeof(host
), &port
, resource
, sizeof(resource
));
6260 if (strncmp(resource
, "/jobs/", 6))
6266 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6267 uri
->values
[0].string
.text
);
6271 jobid
= atoi(resource
+ 6);
6275 * See if the job exists...
6278 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6281 * Nope - return a "not found" error...
6284 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6292 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
,
6293 job
->username
)) != HTTP_OK
)
6295 send_http_error(con
, status
, NULL
);
6300 * Get the document number...
6303 if ((attr
= ippFindAttribute(con
->request
, "document-number",
6304 IPP_TAG_INTEGER
)) == NULL
)
6306 send_ipp_status(con
, IPP_BAD_REQUEST
,
6307 _("Missing document-number attribute."));
6311 if ((docnum
= attr
->values
[0].integer
) < 1 || docnum
> job
->num_files
||
6312 attr
->num_values
> 1)
6314 send_ipp_status(con
, IPP_NOT_FOUND
,
6315 _("Document #%d does not exist in job #%d."), docnum
,
6320 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, jobid
,
6322 if ((con
->file
= open(filename
, O_RDONLY
)) == -1)
6324 cupsdLogMessage(CUPSD_LOG_ERROR
,
6325 "Unable to open document %d in job %d - %s", docnum
, jobid
,
6327 send_ipp_status(con
, IPP_NOT_FOUND
,
6328 _("Unable to open document #%d in job #%d."), docnum
,
6333 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
6337 snprintf(format
, sizeof(format
), "%s/%s", job
->filetypes
[docnum
- 1]->super
,
6338 job
->filetypes
[docnum
- 1]->type
);
6340 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format",
6342 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "document-number",
6344 if ((attr
= ippFindAttribute(job
->attrs
, "document-name",
6345 IPP_TAG_NAME
)) != NULL
)
6346 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name",
6347 NULL
, attr
->values
[0].string
.text
);
6352 * 'get_job_attrs()' - Get job attributes.
6356 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
6357 ipp_attribute_t
*uri
) /* I - Job URI */
6359 http_status_t status
; /* Policy status */
6360 ipp_attribute_t
*attr
; /* Current attribute */
6361 int jobid
; /* Job ID */
6362 cupsd_job_t
*job
; /* Current job */
6363 cupsd_printer_t
*printer
; /* Current printer */
6364 cupsd_policy_t
*policy
; /* Current security policy */
6365 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6366 username
[HTTP_MAX_URI
], /* Username portion of URI */
6367 host
[HTTP_MAX_URI
], /* Host portion of URI */
6368 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6369 int port
; /* Port portion of URI */
6370 cups_array_t
*ra
, /* Requested attributes array */
6371 *exclude
; /* Private attributes array */
6374 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
6375 con
->number
, uri
->values
[0].string
.text
);
6378 * See if we have a job URI or a printer URI...
6381 if (!strcmp(uri
->name
, "printer-uri"))
6384 * Got a printer URI; see if we also have a job-id attribute...
6387 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6388 IPP_TAG_INTEGER
)) == NULL
)
6390 send_ipp_status(con
, IPP_BAD_REQUEST
,
6391 _("Got a printer-uri attribute but no job-id."));
6395 jobid
= attr
->values
[0].integer
;
6400 * Got a job URI; parse it to get the job ID...
6403 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6404 sizeof(scheme
), username
, sizeof(username
), host
,
6405 sizeof(host
), &port
, resource
, sizeof(resource
));
6407 if (strncmp(resource
, "/jobs/", 6))
6413 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
6414 uri
->values
[0].string
.text
);
6418 jobid
= atoi(resource
+ 6);
6422 * See if the job exists...
6425 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6428 * Nope - return a "not found" error...
6431 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
6439 if ((printer
= job
->printer
) == NULL
)
6440 printer
= cupsdFindDest(job
->dest
);
6443 policy
= printer
->op_policy_ptr
;
6445 policy
= DefaultPolicyPtr
;
6447 if ((status
= cupsdCheckPolicy(policy
, con
, job
->username
)) != HTTP_OK
)
6449 send_http_error(con
, status
, NULL
);
6453 exclude
= cupsdGetPrivateAttrs(policy
, con
, printer
, job
->username
);
6456 * Copy attributes...
6461 ra
= create_requested_array(con
->request
);
6462 copy_job_attrs(con
, job
, ra
, exclude
);
6463 cupsArrayDelete(ra
);
6465 con
->response
->request
.status
.status_code
= IPP_OK
;
6470 * 'get_jobs()' - Get a list of jobs for the specified printer.
6474 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
6475 ipp_attribute_t
*uri
) /* I - Printer URI */
6477 http_status_t status
; /* Policy status */
6478 ipp_attribute_t
*attr
; /* Current attribute */
6479 const char *dest
; /* Destination */
6480 cups_ptype_t dtype
; /* Destination type (printer/class) */
6481 cups_ptype_t dmask
; /* Destination type mask */
6482 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6483 username
[HTTP_MAX_URI
], /* Username portion of URI */
6484 host
[HTTP_MAX_URI
], /* Host portion of URI */
6485 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6486 int port
; /* Port portion of URI */
6487 int job_comparison
; /* Job comparison */
6488 ipp_jstate_t job_state
; /* job-state value */
6489 int first_job_id
= 1, /* First job ID */
6490 first_index
= 1, /* First index */
6491 limit
= 0, /* Maximum number of jobs to return */
6492 count
, /* Number of jobs that match */
6493 need_load_job
= 0; /* Do we need to load the job? */
6494 const char *job_attr
; /* Job attribute requested */
6495 ipp_attribute_t
*job_ids
; /* job-ids attribute */
6496 cupsd_job_t
*job
; /* Current job pointer */
6497 cupsd_printer_t
*printer
; /* Printer */
6498 cups_array_t
*list
; /* Which job list... */
6499 int delete_list
= 0; /* Delete the list afterwards? */
6500 cups_array_t
*ra
, /* Requested attributes array */
6501 *exclude
; /* Private attributes array */
6502 cupsd_policy_t
*policy
; /* Current policy */
6505 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->number
,
6506 uri
->values
[0].string
.text
);
6509 * Is the destination valid?
6512 if (strcmp(uri
->name
, "printer-uri"))
6514 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No printer-uri in request."));
6518 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6519 sizeof(scheme
), username
, sizeof(username
), host
,
6520 sizeof(host
), &port
, resource
, sizeof(resource
));
6522 if (!strcmp(resource
, "/") || !strcmp(resource
, "/jobs"))
6525 dtype
= (cups_ptype_t
)0;
6526 dmask
= (cups_ptype_t
)0;
6529 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
6532 dtype
= (cups_ptype_t
)0;
6533 dmask
= CUPS_PRINTER_CLASS
;
6536 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
6539 dtype
= CUPS_PRINTER_CLASS
;
6540 dmask
= CUPS_PRINTER_CLASS
;
6543 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
6550 send_ipp_status(con
, IPP_NOT_FOUND
,
6551 _("The printer or class does not exist."));
6556 dtype
&= CUPS_PRINTER_CLASS
;
6557 dmask
= CUPS_PRINTER_CLASS
;
6565 policy
= printer
->op_policy_ptr
;
6567 policy
= DefaultPolicyPtr
;
6569 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
6571 send_http_error(con
, status
, NULL
);
6575 job_ids
= ippFindAttribute(con
->request
, "job-ids", IPP_TAG_INTEGER
);
6578 * See if the "which-jobs" attribute have been specified...
6581 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
6582 IPP_TAG_KEYWORD
)) != NULL
&& job_ids
)
6584 send_ipp_status(con
, IPP_CONFLICT
,
6585 _("The %s attribute cannot be provided with job-ids."),
6589 else if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "not-completed"))
6591 job_comparison
= -1;
6592 job_state
= IPP_JOB_STOPPED
;
6595 else if (!strcmp(attr
->values
[0].string
.text
, "completed"))
6598 job_state
= IPP_JOB_CANCELED
;
6599 list
= cupsdGetCompletedJobs(printer
);
6602 else if (!strcmp(attr
->values
[0].string
.text
, "aborted"))
6605 job_state
= IPP_JOB_ABORTED
;
6606 list
= cupsdGetCompletedJobs(printer
);
6609 else if (!strcmp(attr
->values
[0].string
.text
, "all"))
6612 job_state
= IPP_JOB_PENDING
;
6615 else if (!strcmp(attr
->values
[0].string
.text
, "canceled"))
6618 job_state
= IPP_JOB_CANCELED
;
6619 list
= cupsdGetCompletedJobs(printer
);
6622 else if (!strcmp(attr
->values
[0].string
.text
, "pending"))
6625 job_state
= IPP_JOB_PENDING
;
6628 else if (!strcmp(attr
->values
[0].string
.text
, "pending-held"))
6631 job_state
= IPP_JOB_HELD
;
6634 else if (!strcmp(attr
->values
[0].string
.text
, "processing"))
6637 job_state
= IPP_JOB_PROCESSING
;
6638 list
= PrintingJobs
;
6640 else if (!strcmp(attr
->values
[0].string
.text
, "processing-stopped"))
6643 job_state
= IPP_JOB_STOPPED
;
6648 send_ipp_status(con
, IPP_ATTRIBUTES
,
6649 _("The which-jobs value \"%s\" is not supported."),
6650 attr
->values
[0].string
.text
);
6651 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6652 "which-jobs", NULL
, attr
->values
[0].string
.text
);
6657 * See if they want to limit the number of jobs reported...
6660 if ((attr
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
)) != NULL
)
6664 send_ipp_status(con
, IPP_CONFLICT
,
6665 _("The %s attribute cannot be provided with job-ids."),
6670 limit
= attr
->values
[0].integer
;
6673 if ((attr
= ippFindAttribute(con
->request
, "first-index", IPP_TAG_INTEGER
)) != NULL
)
6677 send_ipp_status(con
, IPP_CONFLICT
,
6678 _("The %s attribute cannot be provided with job-ids."),
6683 first_index
= attr
->values
[0].integer
;
6685 else if ((attr
= ippFindAttribute(con
->request
, "first-job-id", IPP_TAG_INTEGER
)) != NULL
)
6689 send_ipp_status(con
, IPP_CONFLICT
,
6690 _("The %s attribute cannot be provided with job-ids."),
6695 first_job_id
= attr
->values
[0].integer
;
6699 * See if we only want to see jobs for a specific user...
6702 if ((attr
= ippFindAttribute(con
->request
, "my-jobs", IPP_TAG_BOOLEAN
)) != NULL
&& job_ids
)
6704 send_ipp_status(con
, IPP_CONFLICT
,
6705 _("The %s attribute cannot be provided with job-ids."),
6709 else if (attr
&& attr
->values
[0].boolean
)
6710 strlcpy(username
, get_username(con
), sizeof(username
));
6714 ra
= create_requested_array(con
->request
);
6715 for (job_attr
= (char *)cupsArrayFirst(ra
); job_attr
; job_attr
= (char *)cupsArrayNext(ra
))
6716 if (strcmp(job_attr
, "job-id") &&
6717 strcmp(job_attr
, "job-k-octets") &&
6718 strcmp(job_attr
, "job-media-progress") &&
6719 strcmp(job_attr
, "job-more-info") &&
6720 strcmp(job_attr
, "job-name") &&
6721 strcmp(job_attr
, "job-originating-user-name") &&
6722 strcmp(job_attr
, "job-preserved") &&
6723 strcmp(job_attr
, "job-printer-up-time") &&
6724 strcmp(job_attr
, "job-printer-uri") &&
6725 strcmp(job_attr
, "job-state") &&
6726 strcmp(job_attr
, "job-state-reasons") &&
6727 strcmp(job_attr
, "job-uri") &&
6728 strcmp(job_attr
, "time-at-completed") &&
6729 strcmp(job_attr
, "time-at-creation") &&
6730 strcmp(job_attr
, "number-of-documents"))
6736 if (need_load_job
&& (limit
== 0 || limit
> 500) && (list
== Jobs
|| delete_list
))
6739 * Limit expensive Get-Jobs for job history to 500 jobs...
6742 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "limit", 500);
6745 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
, "limit", limit
);
6749 cupsdLogClient(con
, CUPSD_LOG_INFO
, "Limiting Get-Jobs response to %d jobs.", limit
);
6753 * OK, build a list of jobs for this printer...
6758 int i
; /* Looping var */
6760 for (i
= 0; i
< job_ids
->num_values
; i
++)
6762 if (!cupsdFindJob(job_ids
->values
[i
].integer
))
6766 if (i
< job_ids
->num_values
)
6768 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
6769 job_ids
->values
[i
].integer
);
6773 for (i
= 0; i
< job_ids
->num_values
; i
++)
6775 job
= cupsdFindJob(job_ids
->values
[i
].integer
);
6777 if (need_load_job
&& !job
->attrs
)
6783 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6789 ippAddSeparator(con
->response
);
6791 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6792 job
->printer
->op_policy_ptr
:
6793 policy
, con
, job
->printer
,
6796 copy_job_attrs(con
, job
, ra
, exclude
);
6801 if (first_index
> 1)
6802 job
= (cupsd_job_t
*)cupsArrayIndex(list
, first_index
- 1);
6804 job
= (cupsd_job_t
*)cupsArrayFirst(list
);
6806 for (count
= 0; (limit
<= 0 || count
< limit
) && job
; job
= (cupsd_job_t
*)cupsArrayNext(list
))
6809 * Filter out jobs that don't match...
6812 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6813 "get_jobs: job->id=%d, dest=\"%s\", username=\"%s\", "
6814 "state_value=%d, attrs=%p", job
->id
, job
->dest
,
6815 job
->username
, job
->state_value
, job
->attrs
);
6817 if (!job
->dest
|| !job
->username
)
6820 if (!job
->dest
|| !job
->username
)
6823 if ((dest
&& strcmp(job
->dest
, dest
)) &&
6824 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
6826 if ((job
->dtype
& dmask
) != dtype
&&
6827 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
6830 if ((job_comparison
< 0 && job
->state_value
> job_state
) ||
6831 (job_comparison
== 0 && job
->state_value
!= job_state
) ||
6832 (job_comparison
> 0 && job
->state_value
< job_state
))
6835 if (job
->id
< first_job_id
)
6838 if (need_load_job
&& !job
->attrs
)
6844 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: No attributes for job %d", job
->id
);
6849 if (username
[0] && _cups_strcasecmp(username
, job
->username
))
6853 ippAddSeparator(con
->response
);
6857 exclude
= cupsdGetPrivateAttrs(job
->printer
?
6858 job
->printer
->op_policy_ptr
:
6859 policy
, con
, job
->printer
,
6862 copy_job_attrs(con
, job
, ra
, exclude
);
6865 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count=%d", count
);
6868 cupsArrayDelete(ra
);
6871 cupsArrayDelete(list
);
6873 con
->response
->request
.status
.status_code
= IPP_OK
;
6878 * 'get_notifications()' - Get events for a subscription.
6882 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
6884 int i
, j
; /* Looping vars */
6885 http_status_t status
; /* Policy status */
6886 cupsd_subscription_t
*sub
; /* Subscription */
6887 ipp_attribute_t
*ids
, /* notify-subscription-ids */
6888 *sequences
; /* notify-sequence-numbers */
6889 int min_seq
; /* Minimum sequence number */
6890 int interval
; /* Poll interval */
6893 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
6897 * Get subscription attributes...
6900 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
6902 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
6907 send_ipp_status(con
, IPP_BAD_REQUEST
,
6908 _("Missing notify-subscription-ids attribute."));
6913 * Are the subscription IDs valid?
6916 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
6918 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
6921 * Bad subscription ID...
6924 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
6925 ids
->values
[i
].integer
);
6933 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6935 con
, sub
->owner
)) != HTTP_OK
)
6937 send_http_error(con
, status
, sub
->dest
);
6942 * Check the subscription type and update the interval accordingly.
6945 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
6948 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
6950 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
6956 * Tell the client to poll again in N seconds...
6960 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6961 "notify-get-interval", interval
);
6963 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
6964 "printer-up-time", time(NULL
));
6967 * Copy the subscription event attributes to the response.
6970 con
->response
->request
.status
.status_code
=
6971 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
6973 for (i
= 0; i
< ids
->num_values
; i
++)
6976 * Get the subscription and sequence number...
6979 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
6981 if (sequences
&& i
< sequences
->num_values
)
6982 min_seq
= sequences
->values
[i
].integer
;
6987 * If we don't have any new events, nothing to do here...
6990 if (min_seq
> (sub
->first_event_id
+ cupsArrayCount(sub
->events
)))
6994 * Otherwise copy all of the new events...
6997 if (sub
->first_event_id
> min_seq
)
7000 j
= min_seq
- sub
->first_event_id
;
7002 for (; j
< cupsArrayCount(sub
->events
); j
++)
7004 ippAddSeparator(con
->response
);
7006 copy_attrs(con
->response
,
7007 ((cupsd_event_t
*)cupsArrayIndex(sub
->events
, j
))->attrs
, NULL
,
7008 IPP_TAG_EVENT_NOTIFICATION
, 0, NULL
);
7015 * 'get_ppd()' - Get a named PPD from the local system.
7019 get_ppd(cupsd_client_t
*con
, /* I - Client connection */
7020 ipp_attribute_t
*uri
) /* I - Printer URI or PPD name */
7022 http_status_t status
; /* Policy status */
7023 cupsd_printer_t
*dest
; /* Destination */
7024 cups_ptype_t dtype
; /* Destination type */
7027 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppd(%p[%d], %p[%s=%s])", con
,
7028 con
->number
, uri
, uri
->name
, uri
->values
[0].string
.text
);
7030 if (!strcmp(ippGetName(uri
), "ppd-name"))
7033 * Return a PPD file from cups-driverd...
7036 const char *ppd_name
= ippGetString(uri
, 0, NULL
);
7037 /* ppd-name value */
7038 char command
[1024], /* cups-driverd command */
7039 options
[1024], /* Options to pass to command */
7040 oppd_name
[1024]; /* Escaped ppd-name */
7046 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7048 send_http_error(con
, status
, NULL
);
7053 * Check ppd-name value...
7056 if (strstr(ppd_name
, "../"))
7058 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Invalid ppd-name value."));
7063 * Run cups-driverd command with the given options...
7066 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7067 url_encode_string(ppd_name
, oppd_name
, sizeof(oppd_name
));
7068 snprintf(options
, sizeof(options
), "get+%d+%s", ippGetRequestId(con
->request
), oppd_name
);
7070 if (cupsdSendCommand(con
, command
, options
, 0))
7073 * Command started successfully, don't send an IPP response here...
7076 ippDelete(con
->response
);
7077 con
->response
= NULL
;
7082 * Command failed, return "internal error" so the user knows something
7086 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("cups-driverd failed to execute."));
7089 else if (!strcmp(ippGetName(uri
), "printer-uri") && cupsdValidateDest(ippGetString(uri
, 0, NULL
), &dtype
, &dest
))
7091 int i
; /* Looping var */
7092 char filename
[1024]; /* PPD filename */
7098 if ((status
= cupsdCheckPolicy(dest
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7100 send_http_error(con
, status
, dest
);
7105 * See if we need the PPD for a class or remote printer...
7108 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->name
);
7110 if ((dtype
& CUPS_PRINTER_REMOTE
) && access(filename
, 0))
7112 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7113 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->uri
);
7116 else if (dtype
& CUPS_PRINTER_CLASS
)
7118 for (i
= 0; i
< dest
->num_printers
; i
++)
7119 if (!(dest
->printers
[i
]->type
& CUPS_PRINTER_CLASS
))
7121 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
->printers
[i
]->name
);
7123 if (!access(filename
, 0))
7127 if (i
< dest
->num_printers
)
7128 dest
= dest
->printers
[i
];
7131 send_ipp_status(con
, IPP_STATUS_CUPS_SEE_OTHER
, _("See remote printer."));
7132 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, dest
->printers
[0]->uri
);
7138 * Found the printer with the PPD file, now see if there is one...
7141 if ((con
->file
= open(filename
, O_RDONLY
)) < 0)
7143 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri
, 0, NULL
), strerror(errno
));
7147 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
7151 ippSetStatusCode(con
->response
, IPP_STATUS_OK
);
7154 send_ipp_status(con
, IPP_STATUS_ERROR_NOT_FOUND
, _("The PPD file \"%s\" could not be found."), ippGetString(uri
, 0, NULL
));
7159 * 'get_ppds()' - Get the list of PPD files on the local system.
7163 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
7165 http_status_t status
; /* Policy status */
7166 ipp_attribute_t
*limit
, /* Limit attribute */
7167 *device
, /* ppd-device-id attribute */
7168 *language
, /* ppd-natural-language attribute */
7169 *make
, /* ppd-make attribute */
7170 *model
, /* ppd-make-and-model attribute */
7171 *model_number
, /* ppd-model-number attribute */
7172 *product
, /* ppd-product attribute */
7173 *psversion
, /* ppd-psverion attribute */
7174 *type
, /* ppd-type attribute */
7175 *requested
, /* requested-attributes attribute */
7176 *exclude
, /* exclude-schemes attribute */
7177 *include
; /* include-schemes attribute */
7178 char command
[1024], /* cups-driverd command */
7179 options
[4096], /* Options to pass to command */
7180 device_str
[256],/* Escaped ppd-device-id string */
7182 /* Escaped ppd-natural-language */
7183 make_str
[256], /* Escaped ppd-make string */
7184 model_str
[256], /* Escaped ppd-make-and-model string */
7185 model_number_str
[256],
7186 /* ppd-model-number string */
7188 /* Escaped ppd-product string */
7190 /* Escaped ppd-psversion string */
7191 type_str
[256], /* Escaped ppd-type string */
7193 /* String for requested attributes */
7195 /* String for excluded schemes */
7197 /* String for included schemes */
7200 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->number
);
7206 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7208 send_http_error(con
, status
, NULL
);
7213 * Run cups-driverd command with the given options...
7216 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
7217 device
= ippFindAttribute(con
->request
, "ppd-device-id", IPP_TAG_TEXT
);
7218 language
= ippFindAttribute(con
->request
, "ppd-natural-language",
7220 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
7221 model
= ippFindAttribute(con
->request
, "ppd-make-and-model",
7223 model_number
= ippFindAttribute(con
->request
, "ppd-model-number",
7225 product
= ippFindAttribute(con
->request
, "ppd-product", IPP_TAG_TEXT
);
7226 psversion
= ippFindAttribute(con
->request
, "ppd-psversion", IPP_TAG_TEXT
);
7227 type
= ippFindAttribute(con
->request
, "ppd-type", IPP_TAG_KEYWORD
);
7228 requested
= ippFindAttribute(con
->request
, "requested-attributes",
7230 exclude
= ippFindAttribute(con
->request
, "exclude-schemes",
7232 include
= ippFindAttribute(con
->request
, "include-schemes",
7236 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
7238 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
7241 url_encode_attr(device
, device_str
, sizeof(device_str
));
7243 device_str
[0] = '\0';
7246 url_encode_attr(language
, language_str
, sizeof(language_str
));
7248 language_str
[0] = '\0';
7251 url_encode_attr(make
, make_str
, sizeof(make_str
));
7256 url_encode_attr(model
, model_str
, sizeof(model_str
));
7258 model_str
[0] = '\0';
7261 snprintf(model_number_str
, sizeof(model_number_str
), "ppd-model-number=%d",
7262 model_number
->values
[0].integer
);
7264 model_number_str
[0] = '\0';
7267 url_encode_attr(product
, product_str
, sizeof(product_str
));
7269 product_str
[0] = '\0';
7272 url_encode_attr(psversion
, psversion_str
, sizeof(psversion_str
));
7274 psversion_str
[0] = '\0';
7277 url_encode_attr(type
, type_str
, sizeof(type_str
));
7282 url_encode_attr(exclude
, exclude_str
, sizeof(exclude_str
));
7284 exclude_str
[0] = '\0';
7287 url_encode_attr(include
, include_str
, sizeof(include_str
));
7289 include_str
[0] = '\0';
7291 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
7292 snprintf(options
, sizeof(options
),
7293 "list+%d+%d+%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
7294 con
->request
->request
.op
.request_id
,
7295 limit
? limit
->values
[0].integer
: 0,
7297 device
? "%20" : "", device_str
,
7298 language
? "%20" : "", language_str
,
7299 make
? "%20" : "", make_str
,
7300 model
? "%20" : "", model_str
,
7301 model_number
? "%20" : "", model_number_str
,
7302 product
? "%20" : "", product_str
,
7303 psversion
? "%20" : "", psversion_str
,
7304 type
? "%20" : "", type_str
,
7305 exclude_str
[0] ? "%20" : "", exclude_str
,
7306 include_str
[0] ? "%20" : "", include_str
);
7308 if (cupsdSendCommand(con
, command
, options
, 0))
7311 * Command started successfully, don't send an IPP response here...
7314 ippDelete(con
->response
);
7315 con
->response
= NULL
;
7320 * Command failed, return "internal error" so the user knows something
7324 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
7325 _("cups-driverd failed to execute."));
7331 * 'get_printer_attrs()' - Get printer attributes.
7335 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
7336 ipp_attribute_t
*uri
) /* I - Printer URI */
7338 http_status_t status
; /* Policy status */
7339 cups_ptype_t dtype
; /* Destination type (printer/class) */
7340 cupsd_printer_t
*printer
; /* Printer/class */
7341 cups_array_t
*ra
; /* Requested attributes array */
7344 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
7345 con
->number
, uri
->values
[0].string
.text
);
7348 * Is the destination valid?
7351 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7357 send_ipp_status(con
, IPP_NOT_FOUND
,
7358 _("The printer or class does not exist."));
7366 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7368 send_http_error(con
, status
, printer
);
7373 * Send the attributes...
7376 ra
= create_requested_array(con
->request
);
7378 copy_printer_attrs(con
, printer
, ra
);
7380 cupsArrayDelete(ra
);
7382 con
->response
->request
.status
.status_code
= IPP_OK
;
7387 * 'get_printer_supported()' - Get printer supported values.
7391 get_printer_supported(
7392 cupsd_client_t
*con
, /* I - Client connection */
7393 ipp_attribute_t
*uri
) /* I - Printer URI */
7395 http_status_t status
; /* Policy status */
7396 cups_ptype_t dtype
; /* Destination type (printer/class) */
7397 cupsd_printer_t
*printer
; /* Printer/class */
7400 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_supported(%p[%d], %s)", con
,
7401 con
->number
, uri
->values
[0].string
.text
);
7404 * Is the destination valid?
7407 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7413 send_ipp_status(con
, IPP_NOT_FOUND
,
7414 _("The printer or class does not exist."));
7422 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7424 send_http_error(con
, status
, printer
);
7429 * Return a list of attributes that can be set via Set-Printer-Attributes.
7432 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7433 "printer-geo-location", 0);
7434 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7436 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7437 "printer-location", 0);
7438 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7439 "printer-organization", 0);
7440 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ADMINDEFINE
,
7441 "printer-organizational-unit", 0);
7443 con
->response
->request
.status
.status_code
= IPP_OK
;
7448 * 'get_printers()' - Get a list of printers or classes.
7452 get_printers(cupsd_client_t
*con
, /* I - Client connection */
7453 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
7455 http_status_t status
; /* Policy status */
7456 ipp_attribute_t
*attr
; /* Current attribute */
7457 int limit
; /* Max number of printers to return */
7458 int count
; /* Number of printers that match */
7459 int printer_id
; /* Printer we are interested in */
7460 cupsd_printer_t
*printer
; /* Current printer pointer */
7461 cups_ptype_t printer_type
, /* printer-type attribute */
7462 printer_mask
; /* printer-type-mask attribute */
7463 char *location
; /* Location string */
7464 const char *username
; /* Current user */
7465 char *first_printer_name
; /* first-printer-name attribute */
7466 cups_array_t
*ra
; /* Requested attributes array */
7467 int local
; /* Local connection? */
7470 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
7477 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
7479 send_http_error(con
, status
, NULL
);
7484 * Check for printers...
7487 if (!Printers
|| !cupsArrayCount(Printers
))
7489 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
7494 * See if they want to limit the number of printers reported...
7497 if ((attr
= ippFindAttribute(con
->request
, "limit",
7498 IPP_TAG_INTEGER
)) != NULL
)
7499 limit
= attr
->values
[0].integer
;
7503 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
7504 IPP_TAG_NAME
)) != NULL
)
7505 first_printer_name
= attr
->values
[0].string
.text
;
7507 first_printer_name
= NULL
;
7510 * Support filtering...
7513 if ((attr
= ippFindAttribute(con
->request
, "printer-id", IPP_TAG_INTEGER
)) != NULL
)
7515 if ((printer_id
= ippGetInteger(attr
, 0)) <= 0)
7517 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Bad \"printer-id\" value %d."), printer_id
);
7524 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
7525 IPP_TAG_ENUM
)) != NULL
)
7526 printer_type
= (cups_ptype_t
)attr
->values
[0].integer
;
7528 printer_type
= (cups_ptype_t
)0;
7530 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
7531 IPP_TAG_ENUM
)) != NULL
)
7532 printer_mask
= (cups_ptype_t
)attr
->values
[0].integer
;
7534 printer_mask
= (cups_ptype_t
)0;
7536 local
= httpAddrLocalhost(&(con
->clientaddr
));
7538 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
7539 IPP_TAG_TEXT
)) != NULL
)
7540 location
= attr
->values
[0].string
.text
;
7544 if (con
->username
[0])
7545 username
= con
->username
;
7546 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7547 IPP_TAG_NAME
)) != NULL
)
7548 username
= attr
->values
[0].string
.text
;
7552 ra
= create_requested_array(con
->request
);
7555 * OK, build a list of printers for this printer...
7558 if (first_printer_name
)
7560 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
7561 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7564 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
7567 count
< limit
&& printer
;
7568 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
7570 if (!local
&& !printer
->shared
)
7573 if (printer_id
&& printer
->printer_id
!= printer_id
)
7576 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
7577 (printer
->type
& printer_mask
) == printer_type
&&
7579 (printer
->location
&& !_cups_strcasecmp(printer
->location
, location
))))
7582 * If a username is specified, see if it is allowed or denied
7586 if (cupsArrayCount(printer
->users
) && username
&&
7587 !user_allowed(printer
, username
))
7591 * Add the group separator as needed...
7595 ippAddSeparator(con
->response
);
7600 * Send the attributes...
7603 copy_printer_attrs(con
, printer
, ra
);
7607 cupsArrayDelete(ra
);
7609 con
->response
->request
.status
.status_code
= IPP_OK
;
7614 * 'get_subscription_attrs()' - Get subscription attributes.
7618 get_subscription_attrs(
7619 cupsd_client_t
*con
, /* I - Client connection */
7620 int sub_id
) /* I - Subscription ID */
7622 http_status_t status
; /* Policy status */
7623 cupsd_subscription_t
*sub
; /* Subscription */
7624 cupsd_policy_t
*policy
; /* Current security policy */
7625 cups_array_t
*ra
, /* Requested attributes array */
7626 *exclude
; /* Private attributes array */
7629 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7630 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
7631 con
, con
->number
, sub_id
);
7634 * Expire subscriptions as needed...
7637 cupsdExpireSubscriptions(NULL
, NULL
);
7640 * Is the subscription ID valid?
7643 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7646 * Bad subscription ID...
7649 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
7659 policy
= sub
->dest
->op_policy_ptr
;
7661 policy
= DefaultPolicyPtr
;
7663 if ((status
= cupsdCheckPolicy(policy
, con
, sub
->owner
)) != HTTP_OK
)
7665 send_http_error(con
, status
, sub
->dest
);
7669 exclude
= cupsdGetPrivateAttrs(policy
, con
, sub
->dest
, sub
->owner
);
7672 * Copy the subscription attributes to the response using the
7673 * requested-attributes attribute that may be provided by the client.
7676 ra
= create_requested_array(con
->request
);
7678 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7680 cupsArrayDelete(ra
);
7682 con
->response
->request
.status
.status_code
= IPP_OK
;
7687 * 'get_subscriptions()' - Get subscriptions.
7691 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
7692 ipp_attribute_t
*uri
) /* I - Printer/job URI */
7694 http_status_t status
; /* Policy status */
7695 int count
; /* Number of subscriptions */
7696 int limit
; /* Limit */
7697 cupsd_subscription_t
*sub
; /* Subscription */
7698 cups_array_t
*ra
; /* Requested attributes array */
7699 ipp_attribute_t
*attr
; /* Attribute */
7700 cups_ptype_t dtype
; /* Destination type (printer/class) */
7701 char scheme
[HTTP_MAX_URI
],
7702 /* Scheme portion of URI */
7703 username
[HTTP_MAX_URI
],
7704 /* Username portion of URI */
7706 /* Host portion of URI */
7707 resource
[HTTP_MAX_URI
];
7708 /* Resource portion of URI */
7709 int port
; /* Port portion of URI */
7710 cupsd_job_t
*job
; /* Job pointer */
7711 cupsd_printer_t
*printer
; /* Printer */
7712 cupsd_policy_t
*policy
; /* Policy */
7713 cups_array_t
*exclude
; /* Private attributes array */
7716 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7717 "get_subscriptions(con=%p[%d], uri=%s)",
7718 con
, con
->number
, uri
->values
[0].string
.text
);
7721 * Is the destination valid?
7724 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7725 sizeof(scheme
), username
, sizeof(username
), host
,
7726 sizeof(host
), &port
, resource
, sizeof(resource
));
7728 if (!strcmp(resource
, "/") ||
7729 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
7730 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
7731 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
7736 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
7739 job
= cupsdFindJob(atoi(resource
+ 6));
7743 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7744 atoi(resource
+ 6));
7748 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7754 send_ipp_status(con
, IPP_NOT_FOUND
,
7755 _("The printer or class does not exist."));
7758 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
7759 IPP_TAG_INTEGER
)) != NULL
)
7761 job
= cupsdFindJob(attr
->values
[0].integer
);
7765 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."),
7766 attr
->values
[0].integer
);
7778 policy
= printer
->op_policy_ptr
;
7780 policy
= DefaultPolicyPtr
;
7782 if ((status
= cupsdCheckPolicy(policy
, con
, NULL
)) != HTTP_OK
)
7784 send_http_error(con
, status
, printer
);
7789 * Expire subscriptions as needed...
7792 cupsdExpireSubscriptions(NULL
, NULL
);
7795 * Copy the subscription attributes to the response using the
7796 * requested-attributes attribute that may be provided by the client.
7799 ra
= create_requested_array(con
->request
);
7801 if ((attr
= ippFindAttribute(con
->request
, "limit",
7802 IPP_TAG_INTEGER
)) != NULL
)
7803 limit
= attr
->values
[0].integer
;
7808 * See if we only want to see subscriptions for a specific user...
7811 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
7812 IPP_TAG_BOOLEAN
)) != NULL
&&
7813 attr
->values
[0].boolean
)
7814 strlcpy(username
, get_username(con
), sizeof(username
));
7818 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
7820 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
7821 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
7822 (!username
[0] || !_cups_strcasecmp(username
, sub
->owner
)))
7824 ippAddSeparator(con
->response
);
7826 exclude
= cupsdGetPrivateAttrs(sub
->dest
? sub
->dest
->op_policy_ptr
:
7827 policy
, con
, sub
->dest
,
7830 copy_subscription_attrs(con
, sub
, ra
, exclude
);
7833 if (limit
&& count
>= limit
)
7837 cupsArrayDelete(ra
);
7840 con
->response
->request
.status
.status_code
= IPP_OK
;
7842 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
7847 * 'get_username()' - Get the username associated with a request.
7850 static const char * /* O - Username */
7851 get_username(cupsd_client_t
*con
) /* I - Connection */
7853 ipp_attribute_t
*attr
; /* Attribute */
7856 if (con
->username
[0])
7857 return (con
->username
);
7858 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
7859 IPP_TAG_NAME
)) != NULL
)
7860 return (attr
->values
[0].string
.text
);
7862 return ("anonymous");
7867 * 'hold_job()' - Hold a print job.
7871 hold_job(cupsd_client_t
*con
, /* I - Client connection */
7872 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7874 ipp_attribute_t
*attr
; /* Current job-hold-until */
7875 const char *when
; /* New value */
7876 int jobid
; /* Job ID */
7877 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
7878 username
[HTTP_MAX_URI
], /* Username portion of URI */
7879 host
[HTTP_MAX_URI
], /* Host portion of URI */
7880 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7881 int port
; /* Port portion of URI */
7882 cupsd_job_t
*job
; /* Job information */
7885 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->number
,
7886 uri
->values
[0].string
.text
);
7889 * See if we have a job URI or a printer URI...
7892 if (!strcmp(uri
->name
, "printer-uri"))
7895 * Got a printer URI; see if we also have a job-id attribute...
7898 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7899 IPP_TAG_INTEGER
)) == NULL
)
7901 send_ipp_status(con
, IPP_BAD_REQUEST
,
7902 _("Got a printer-uri attribute but no job-id."));
7906 jobid
= attr
->values
[0].integer
;
7911 * Got a job URI; parse it to get the job ID...
7914 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
7915 sizeof(scheme
), username
, sizeof(username
), host
,
7916 sizeof(host
), &port
, resource
, sizeof(resource
));
7918 if (strncmp(resource
, "/jobs/", 6))
7924 send_ipp_status(con
, IPP_BAD_REQUEST
,
7925 _("Bad job-uri \"%s\"."),
7926 uri
->values
[0].string
.text
);
7930 jobid
= atoi(resource
+ 6);
7934 * See if the job exists...
7937 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7940 * Nope - return a "not found" error...
7943 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
7948 * See if the job is owned by the requesting user...
7951 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7953 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
7954 cupsdFindDest(job
->dest
));
7959 * See if the job is in a state that allows holding...
7962 if (job
->state_value
> IPP_JOB_STOPPED
)
7965 * Return a "not-possible" error...
7968 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7969 _("Job #%d is finished and cannot be altered."),
7975 * Hold the job and return...
7978 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_ZERO
)) != NULL
)
7980 if ((ippGetValueTag(attr
) != IPP_TAG_KEYWORD
&& ippGetValueTag(attr
) != IPP_TAG_NAME
&& ippGetValueTag(attr
) != IPP_TAG_NAMELANG
) || ippGetCount(attr
) != 1 || !ippValidateAttribute(attr
))
7982 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
7983 ippCopyAttribute(con
->response
, attr
, 0);
7987 when
= ippGetString(attr
, 0, NULL
);
7989 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
7990 "Job job-hold-until value changed by user.");
7993 when
= "indefinite";
7995 cupsdSetJobHoldUntil(job
, when
, 1);
7996 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".",
7999 con
->response
->request
.status
.status_code
= IPP_OK
;
8004 * 'hold_new_jobs()' - Hold pending/new jobs on a printer or class.
8008 hold_new_jobs(cupsd_client_t
*con
, /* I - Connection */
8009 ipp_attribute_t
*uri
) /* I - Printer URI */
8011 http_status_t status
; /* Policy status */
8012 cups_ptype_t dtype
; /* Destination type (printer/class) */
8013 cupsd_printer_t
*printer
; /* Printer data */
8016 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_new_jobs(%p[%d], %s)", con
,
8017 con
->number
, uri
->values
[0].string
.text
);
8020 * Is the destination valid?
8023 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8029 send_ipp_status(con
, IPP_NOT_FOUND
,
8030 _("The printer or class does not exist."));
8038 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8040 send_http_error(con
, status
, printer
);
8045 * Hold pending/new jobs sent to the printer...
8048 printer
->holding_new_jobs
= 1;
8050 cupsdSetPrinterReasons(printer
, "+hold-new-jobs");
8052 if (dtype
& CUPS_PRINTER_CLASS
)
8053 cupsdLogMessage(CUPSD_LOG_INFO
,
8054 "Class \"%s\" now holding pending/new jobs (\"%s\").",
8055 printer
->name
, get_username(con
));
8057 cupsdLogMessage(CUPSD_LOG_INFO
,
8058 "Printer \"%s\" now holding pending/new jobs (\"%s\").",
8059 printer
->name
, get_username(con
));
8062 * Everything was ok, so return OK status...
8065 con
->response
->request
.status
.status_code
= IPP_OK
;
8070 * 'move_job()' - Move a job to a new destination.
8074 move_job(cupsd_client_t
*con
, /* I - Client connection */
8075 ipp_attribute_t
*uri
) /* I - Job URI */
8077 http_status_t status
; /* Policy status */
8078 ipp_attribute_t
*attr
; /* Current attribute */
8079 int jobid
; /* Job ID */
8080 cupsd_job_t
*job
; /* Current job */
8081 const char *src
; /* Source printer/class */
8082 cups_ptype_t stype
, /* Source type (printer or class) */
8083 dtype
; /* Destination type (printer/class) */
8084 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
8085 username
[HTTP_MAX_URI
], /* Username portion of URI */
8086 host
[HTTP_MAX_URI
], /* Host portion of URI */
8087 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
8088 int port
; /* Port portion of URI */
8089 cupsd_printer_t
*sprinter
, /* Source printer */
8090 *dprinter
; /* Destination printer */
8093 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->number
,
8094 uri
->values
[0].string
.text
);
8097 * Get the new printer or class...
8100 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
8101 IPP_TAG_URI
)) == NULL
)
8104 * Need job-printer-uri...
8107 send_ipp_status(con
, IPP_BAD_REQUEST
,
8108 _("job-printer-uri attribute missing."));
8112 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
8118 send_ipp_status(con
, IPP_NOT_FOUND
,
8119 _("The printer or class does not exist."));
8124 * See if we have a job URI or a printer URI...
8127 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
8128 sizeof(scheme
), username
, sizeof(username
), host
,
8129 sizeof(host
), &port
, resource
, sizeof(resource
));
8131 if (!strcmp(uri
->name
, "printer-uri"))
8134 * Got a printer URI; see if we also have a job-id attribute...
8137 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8138 IPP_TAG_INTEGER
)) == NULL
)
8144 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
8145 &sprinter
)) == NULL
)
8151 send_ipp_status(con
, IPP_NOT_FOUND
,
8152 _("The printer or class does not exist."));
8161 * Otherwise, just move a single job...
8164 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
8167 * Nope - return a "not found" error...
8170 send_ipp_status(con
, IPP_NOT_FOUND
,
8171 _("Job #%d does not exist."), attr
->values
[0].integer
);
8177 * Job found, initialize source pointers...
8188 * Got a job URI; parse it to get the job ID...
8191 if (strncmp(resource
, "/jobs/", 6))
8197 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
8198 uri
->values
[0].string
.text
);
8203 * See if the job exists...
8206 jobid
= atoi(resource
+ 6);
8208 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8211 * Nope - return a "not found" error...
8214 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
8220 * Job found, initialize source pointers...
8229 * Check the policy of the destination printer...
8232 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
8233 job
? job
->username
: NULL
)) != HTTP_OK
)
8235 send_http_error(con
, status
, dprinter
);
8240 * Now move the job or jobs...
8246 * See if the job has been completed...
8249 if (job
->state_value
> IPP_JOB_STOPPED
)
8252 * Return a "not-possible" error...
8255 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8256 _("Job #%d is finished and cannot be altered."),
8262 * See if the job is owned by the requesting user...
8265 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8267 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
8268 cupsdFindDest(job
->dest
));
8273 * Move the job to a different printer or class...
8276 cupsdMoveJob(job
, dprinter
);
8281 * Got the source printer, now look through the jobs...
8284 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
8286 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
8289 * See if the job is pointing at the source printer or has not been
8293 if (_cups_strcasecmp(job
->dest
, src
) ||
8294 job
->state_value
> IPP_JOB_STOPPED
)
8298 * See if the job can be moved by the requesting user...
8301 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8305 * Move the job to a different printer or class...
8308 cupsdMoveJob(job
, dprinter
);
8313 * Start jobs if possible...
8319 * Return with "everything is OK" status...
8322 con
->response
->request
.status
.status_code
= IPP_OK
;
8327 * 'ppd_parse_line()' - Parse a PPD default line.
8330 static int /* O - 0 on success, -1 on failure */
8331 ppd_parse_line(const char *line
, /* I - Line */
8332 char *option
, /* O - Option name */
8333 int olen
, /* I - Size of option name */
8334 char *choice
, /* O - Choice name */
8335 int clen
) /* I - Size of choice name */
8338 * Verify this is a default option line...
8341 if (strncmp(line
, "*Default", 8))
8345 * Read the option name...
8348 for (line
+= 8, olen
--;
8349 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8360 * Skip everything else up to the colon (:)...
8363 while (*line
&& *line
!= ':')
8372 * Now grab the option choice, skipping leading whitespace...
8375 while (isspace(*line
& 255))
8379 *line
> ' ' && *line
< 0x7f && *line
!= ':' && *line
!= '/';
8390 * Return with no errors...
8398 * 'print_job()' - Print a file to a printer or class.
8402 print_job(cupsd_client_t
*con
, /* I - Client connection */
8403 ipp_attribute_t
*uri
) /* I - Printer URI */
8405 ipp_attribute_t
*attr
; /* Current attribute */
8406 ipp_attribute_t
*doc_name
; /* document-name attribute */
8407 ipp_attribute_t
*format
; /* Document-format attribute */
8408 const char *default_format
; /* document-format-default value */
8409 cupsd_job_t
*job
; /* New job */
8410 char filename
[1024]; /* Job filename */
8411 mime_type_t
*filetype
; /* Type of file */
8412 char super
[MIME_MAX_SUPER
], /* Supertype of file */
8413 type
[MIME_MAX_TYPE
], /* Subtype of file */
8414 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
8415 /* Textual name of mime type */
8416 cupsd_printer_t
*printer
; /* Printer data */
8417 struct stat fileinfo
; /* File information */
8418 int kbytes
; /* Size of file */
8419 int compression
; /* Document compression */
8422 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->number
,
8423 uri
->values
[0].string
.text
);
8426 * Validate print file attributes, for now just document-format and
8427 * compression (CUPS only supports "none" and "gzip")...
8430 compression
= CUPS_FILE_NONE
;
8432 if ((attr
= ippFindAttribute(con
->request
, "compression",
8433 IPP_TAG_KEYWORD
)) != NULL
)
8435 if (strcmp(attr
->values
[0].string
.text
, "none")
8437 && strcmp(attr
->values
[0].string
.text
, "gzip")
8438 #endif /* HAVE_LIBZ */
8441 send_ipp_status(con
, IPP_ATTRIBUTES
,
8442 _("Unsupported compression \"%s\"."),
8443 attr
->values
[0].string
.text
);
8444 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8445 "compression", NULL
, attr
->values
[0].string
.text
);
8450 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8451 compression
= CUPS_FILE_GZIP
;
8452 #endif /* HAVE_LIBZ */
8456 * Do we have a file to print?
8461 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
8466 * Is the destination valid?
8469 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
8475 send_ipp_status(con
, IPP_NOT_FOUND
,
8476 _("The printer or class does not exist."));
8481 * Is it a format we support?
8484 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8486 ippSetName(con
->request
, &doc_name
, "document-name-supplied");
8488 if ((format
= ippFindAttribute(con
->request
, "document-format",
8489 IPP_TAG_MIMETYPE
)) != NULL
)
8492 * Grab format from client...
8495 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]", super
,
8498 send_ipp_status(con
, IPP_BAD_REQUEST
,
8499 _("Bad document-format \"%s\"."),
8500 format
->values
[0].string
.text
);
8504 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
8506 else if ((default_format
= cupsGetOption("document-format",
8507 printer
->num_options
,
8508 printer
->options
)) != NULL
)
8511 * Use default document format...
8514 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
8516 send_ipp_status(con
, IPP_BAD_REQUEST
,
8517 _("Bad document-format \"%s\"."),
8528 strlcpy(super
, "application", sizeof(super
));
8529 strlcpy(type
, "octet-stream", sizeof(type
));
8532 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8535 * Auto-type the file...
8538 cupsdLogMessage(CUPSD_LOG_DEBUG
, "[Job ???] Auto-typing file...");
8541 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8542 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8546 filetype
= mimeType(MimeDatabase
, super
, type
);
8548 cupsdLogMessage(CUPSD_LOG_INFO
, "[Job ???] Request file type is %s/%s.",
8549 filetype
->super
, filetype
->type
);
8551 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
8552 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
8555 filetype
= mimeType(MimeDatabase
, super
, type
);
8559 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8562 * Replace the document-format attribute value with the auto-typed or
8566 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8570 ippSetString(con
->request
, &format
, 0, mimetype
);
8572 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8573 "document-format", NULL
, mimetype
);
8577 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8578 _("Unsupported document-format \"%s\"."),
8579 format
? format
->values
[0].string
.text
:
8580 "application/octet-stream");
8581 cupsdLogMessage(CUPSD_LOG_INFO
,
8582 "Hint: Do you have the raw file printing rules enabled?");
8585 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8586 "document-format", NULL
, format
->values
[0].string
.text
);
8592 * Read any embedded job ticket info from PS files...
8595 if (!_cups_strcasecmp(filetype
->super
, "application") &&
8596 (!_cups_strcasecmp(filetype
->type
, "postscript") ||
8597 !_cups_strcasecmp(filetype
->type
, "pdf")))
8598 read_job_ticket(con
);
8601 * Create the job object...
8604 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
8608 * Update quota data...
8611 if (stat(con
->filename
, &fileinfo
))
8614 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8616 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8618 job
->koctets
+= kbytes
;
8620 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
8621 attr
->values
[0].integer
+= kbytes
;
8624 * Add the job file...
8627 if (add_file(con
, job
, filetype
, compression
))
8630 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
8631 if (rename(con
->filename
, filename
))
8633 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
8635 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
8639 cupsdClearString(&con
->filename
);
8642 * See if we need to add the ending sheet...
8645 if (cupsdTimeoutJob(job
))
8649 * Log and save the job...
8652 cupsdLogJob(job
, CUPSD_LOG_INFO
,
8653 "File of type %s/%s queued by \"%s\".",
8654 filetype
->super
, filetype
->type
, job
->username
);
8655 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "hold_until=%d", (int)job
->hold_until
);
8656 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Queued on \"%s\" by \"%s\".",
8657 job
->dest
, job
->username
);
8660 * Start the job if possible...
8668 * 'read_job_ticket()' - Read a job ticket embedded in a print file.
8670 * This function only gets called when printing a single PDF or PostScript
8671 * file using the Print-Job operation. It doesn't work for Create-Job +
8672 * Send-File, since the job attributes need to be set at job creation
8673 * time for banners to work. The embedded job ticket stuff is here
8674 * primarily to allow the Windows printer driver for CUPS to pass in JCL
8675 * options and IPP attributes which otherwise would be lost.
8677 * The format of a job ticket is simple:
8679 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
8681 * %cupsJobTicket: attr1=value1
8682 * %cupsJobTicket: attr2=value2
8684 * %cupsJobTicket: attrN=valueN
8686 * Job ticket lines must appear immediately after the first line that
8687 * specifies PostScript (%!PS-Adobe-3.0) or PDF (%PDF) format, and CUPS
8688 * stops looking for job ticket info when it finds a line that does not begin
8689 * with "%cupsJobTicket:".
8691 * The maximum length of a job ticket line, including the prefix, is
8692 * 255 characters to conform with the Adobe DSC.
8694 * Read-only attributes are rejected with a notice to the error log in
8695 * case a malicious user tries anything. Since the job ticket is read
8696 * prior to attribute validation in print_job(), job ticket attributes
8697 * will go through the same validation as IPP attributes...
8701 read_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
8703 cups_file_t
*fp
; /* File to read from */
8704 char line
[256]; /* Line data */
8705 int num_options
; /* Number of options */
8706 cups_option_t
*options
; /* Options */
8707 ipp_t
*ticket
; /* New attributes */
8708 ipp_attribute_t
*attr
, /* Current attribute */
8709 *attr2
, /* Job attribute */
8710 *prev2
; /* Previous job attribute */
8714 * First open the print file...
8717 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
8719 cupsdLogMessage(CUPSD_LOG_ERROR
,
8720 "Unable to open print file for job ticket - %s",
8726 * Skip the first line...
8729 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
8731 cupsdLogMessage(CUPSD_LOG_ERROR
,
8732 "Unable to read from print file for job ticket - %s",
8738 if (strncmp(line
, "%!PS-Adobe-", 11) && strncmp(line
, "%PDF-", 5))
8741 * Not a DSC-compliant file, so no job ticket info will be available...
8749 * Read job ticket info from the file...
8755 while (cupsFileGets(fp
, line
, sizeof(line
)))
8758 * Stop at the first non-ticket line...
8761 if (strncmp(line
, "%cupsJobTicket:", 15))
8765 * Add the options to the option array...
8768 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
8772 * Done with the file; see if we have any options...
8777 if (num_options
== 0)
8781 * OK, convert the options to an attribute list, and apply them to
8786 cupsEncodeOptions(ticket
, num_options
, options
);
8789 * See what the user wants to change.
8792 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
8794 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8797 if (!strncmp(attr
->name
, "date-time-at-", 13) ||
8798 !strcmp(attr
->name
, "job-impressions-completed") ||
8799 !strcmp(attr
->name
, "job-media-sheets-completed") ||
8800 !strncmp(attr
->name
, "job-k-octets", 12) ||
8801 !strcmp(attr
->name
, "job-id") ||
8802 !strcmp(attr
->name
, "job-originating-host-name") ||
8803 !strcmp(attr
->name
, "job-originating-user-name") ||
8804 !strcmp(attr
->name
, "job-pages-completed") ||
8805 !strcmp(attr
->name
, "job-printer-uri") ||
8806 !strncmp(attr
->name
, "job-state", 9) ||
8807 !strcmp(attr
->name
, "job-uri") ||
8808 !strncmp(attr
->name
, "time-at-", 8))
8809 continue; /* Read-only attrs */
8811 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
8812 IPP_TAG_ZERO
)) != NULL
)
8815 * Some other value; first free the old value...
8818 if (con
->request
->attrs
== attr2
)
8820 con
->request
->attrs
= attr2
->next
;
8825 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
8826 if (prev2
->next
== attr2
)
8828 prev2
->next
= attr2
->next
;
8833 if (con
->request
->last
== attr2
)
8834 con
->request
->last
= prev2
;
8836 ippDeleteAttribute(NULL
, attr2
);
8840 * Add new option by copying it...
8843 ippCopyAttribute(con
->request
, attr
, 0);
8847 * Then free the attribute list and option array...
8851 cupsFreeOptions(num_options
, options
);
8856 * 'reject_jobs()' - Reject print jobs to a printer.
8860 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
8861 ipp_attribute_t
*uri
) /* I - Printer or class URI */
8863 http_status_t status
; /* Policy status */
8864 cups_ptype_t dtype
; /* Destination type (printer/class) */
8865 cupsd_printer_t
*printer
; /* Printer data */
8866 ipp_attribute_t
*attr
; /* printer-state-message text */
8869 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
8870 con
->number
, uri
->values
[0].string
.text
);
8873 * Is the destination valid?
8876 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8882 send_ipp_status(con
, IPP_NOT_FOUND
,
8883 _("The printer or class does not exist."));
8891 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8893 send_http_error(con
, status
, printer
);
8898 * Reject jobs sent to the printer...
8901 printer
->accepting
= 0;
8903 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8904 IPP_TAG_TEXT
)) == NULL
)
8905 strlcpy(printer
->state_message
, "Rejecting Jobs",
8906 sizeof(printer
->state_message
));
8908 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8909 sizeof(printer
->state_message
));
8911 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
8912 "No longer accepting jobs.");
8914 if (dtype
& CUPS_PRINTER_CLASS
)
8916 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
8918 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
8919 printer
->name
, get_username(con
));
8923 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
8925 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
8926 printer
->name
, get_username(con
));
8930 * Everything was ok, so return OK status...
8933 con
->response
->request
.status
.status_code
= IPP_OK
;
8938 * 'release_held_new_jobs()' - Release pending/new jobs on a printer or class.
8942 release_held_new_jobs(
8943 cupsd_client_t
*con
, /* I - Connection */
8944 ipp_attribute_t
*uri
) /* I - Printer URI */
8946 http_status_t status
; /* Policy status */
8947 cups_ptype_t dtype
; /* Destination type (printer/class) */
8948 cupsd_printer_t
*printer
; /* Printer data */
8951 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_held_new_jobs(%p[%d], %s)", con
,
8952 con
->number
, uri
->values
[0].string
.text
);
8955 * Is the destination valid?
8958 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8964 send_ipp_status(con
, IPP_NOT_FOUND
,
8965 _("The printer or class does not exist."));
8973 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8975 send_http_error(con
, status
, printer
);
8980 * Hold pending/new jobs sent to the printer...
8983 printer
->holding_new_jobs
= 0;
8985 cupsdSetPrinterReasons(printer
, "-hold-new-jobs");
8987 if (dtype
& CUPS_PRINTER_CLASS
)
8988 cupsdLogMessage(CUPSD_LOG_INFO
,
8989 "Class \"%s\" now printing pending/new jobs (\"%s\").",
8990 printer
->name
, get_username(con
));
8992 cupsdLogMessage(CUPSD_LOG_INFO
,
8993 "Printer \"%s\" now printing pending/new jobs (\"%s\").",
8994 printer
->name
, get_username(con
));
8999 * Everything was ok, so return OK status...
9002 con
->response
->request
.status
.status_code
= IPP_OK
;
9007 * 'release_job()' - Release a held print job.
9011 release_job(cupsd_client_t
*con
, /* I - Client connection */
9012 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9014 ipp_attribute_t
*attr
; /* Current attribute */
9015 int jobid
; /* Job ID */
9016 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9017 username
[HTTP_MAX_URI
], /* Username portion of URI */
9018 host
[HTTP_MAX_URI
], /* Host portion of URI */
9019 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9020 int port
; /* Port portion of URI */
9021 cupsd_job_t
*job
; /* Job information */
9024 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
9025 con
->number
, uri
->values
[0].string
.text
);
9028 * See if we have a job URI or a printer URI...
9031 if (!strcmp(uri
->name
, "printer-uri"))
9034 * Got a printer URI; see if we also have a job-id attribute...
9037 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9038 IPP_TAG_INTEGER
)) == NULL
)
9040 send_ipp_status(con
, IPP_BAD_REQUEST
,
9041 _("Got a printer-uri attribute but no job-id."));
9045 jobid
= attr
->values
[0].integer
;
9050 * Got a job URI; parse it to get the job ID...
9053 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9054 sizeof(scheme
), username
, sizeof(username
), host
,
9055 sizeof(host
), &port
, resource
, sizeof(resource
));
9057 if (strncmp(resource
, "/jobs/", 6))
9063 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9064 uri
->values
[0].string
.text
);
9068 jobid
= atoi(resource
+ 6);
9072 * See if the job exists...
9075 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9078 * Nope - return a "not found" error...
9081 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9086 * See if job is "held"...
9089 if (job
->state_value
!= IPP_JOB_HELD
)
9092 * Nope - return a "not possible" error...
9095 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held."), jobid
);
9100 * See if the job is owned by the requesting user...
9103 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9105 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9106 cupsdFindDest(job
->dest
));
9111 * Reset the job-hold-until value to "no-hold"...
9114 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9115 IPP_TAG_KEYWORD
)) == NULL
)
9116 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9120 ippSetValueTag(job
->attrs
, &attr
, IPP_TAG_KEYWORD
);
9121 ippSetString(job
->attrs
, &attr
, 0, "no-hold");
9123 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
9124 "Job job-hold-until value changed by user.");
9125 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9129 * Release the job and return...
9132 cupsdReleaseJob(job
);
9134 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
9135 "Job released by user.");
9137 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Released by \"%s\".", username
);
9139 con
->response
->request
.status
.status_code
= IPP_OK
;
9146 * 'renew_subscription()' - Renew an existing subscription...
9151 cupsd_client_t
*con
, /* I - Client connection */
9152 int sub_id
) /* I - Subscription ID */
9154 http_status_t status
; /* Policy status */
9155 cupsd_subscription_t
*sub
; /* Subscription */
9156 ipp_attribute_t
*lease
; /* notify-lease-duration */
9159 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9160 "renew_subscription(con=%p[%d], sub_id=%d)",
9161 con
, con
->number
, sub_id
);
9164 * Is the subscription ID valid?
9167 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
9170 * Bad subscription ID...
9173 send_ipp_status(con
, IPP_NOT_FOUND
, _("Subscription #%d does not exist."),
9181 * Job subscriptions cannot be renewed...
9184 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9185 _("Job subscriptions cannot be renewed."));
9193 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
9195 con
, sub
->owner
)) != HTTP_OK
)
9197 send_http_error(con
, status
, sub
->dest
);
9202 * Renew the subscription...
9205 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
9208 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
9210 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
9212 cupsdLogMessage(CUPSD_LOG_INFO
,
9213 "renew_subscription: Limiting notify-lease-duration to "
9216 sub
->lease
= MaxLeaseDuration
;
9219 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
9221 cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS
);
9223 con
->response
->request
.status
.status_code
= IPP_OK
;
9225 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
9226 "notify-lease-duration", sub
->lease
);
9231 * 'restart_job()' - Restart an old print job.
9235 restart_job(cupsd_client_t
*con
, /* I - Client connection */
9236 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
9238 ipp_attribute_t
*attr
; /* Current attribute */
9239 int jobid
; /* Job ID */
9240 cupsd_job_t
*job
; /* Job information */
9241 char scheme
[HTTP_MAX_URI
], /* Method portion of URI */
9242 username
[HTTP_MAX_URI
], /* Username portion of URI */
9243 host
[HTTP_MAX_URI
], /* Host portion of URI */
9244 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
9245 int port
; /* Port portion of URI */
9248 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
9249 con
->number
, uri
->values
[0].string
.text
);
9252 * See if we have a job URI or a printer URI...
9255 if (!strcmp(uri
->name
, "printer-uri"))
9258 * Got a printer URI; see if we also have a job-id attribute...
9261 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9262 IPP_TAG_INTEGER
)) == NULL
)
9264 send_ipp_status(con
, IPP_BAD_REQUEST
,
9265 _("Got a printer-uri attribute but no job-id."));
9269 jobid
= attr
->values
[0].integer
;
9274 * Got a job URI; parse it to get the job ID...
9277 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9278 sizeof(scheme
), username
, sizeof(username
), host
,
9279 sizeof(host
), &port
, resource
, sizeof(resource
));
9281 if (strncmp(resource
, "/jobs/", 6))
9287 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9288 uri
->values
[0].string
.text
);
9292 jobid
= atoi(resource
+ 6);
9296 * See if the job exists...
9299 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9302 * Nope - return a "not found" error...
9305 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9310 * See if job is in any of the "completed" states...
9313 if (job
->state_value
<= IPP_JOB_PROCESSING
)
9316 * Nope - return a "not possible" error...
9319 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete."),
9325 * See if we have retained the job files...
9330 if (!job
->attrs
|| job
->num_files
== 0)
9333 * Nope - return a "not possible" error...
9336 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
9337 _("Job #%d cannot be restarted - no files."), jobid
);
9342 * See if the job is owned by the requesting user...
9345 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9347 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9348 cupsdFindDest(job
->dest
));
9353 * See if the job-hold-until attribute is specified...
9356 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until",
9357 IPP_TAG_KEYWORD
)) == NULL
)
9358 attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
9360 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold"))
9363 * Return the job to a held state...
9366 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
9367 "Restarted by \"%s\" with job-hold-until=%s.",
9368 username
, attr
->values
[0].string
.text
);
9369 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
, 0);
9371 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
,
9372 NULL
, job
, "Job restarted by user with job-hold-until=%s",
9373 attr
->values
[0].string
.text
);
9378 * Restart the job...
9381 cupsdRestartJob(job
);
9385 cupsdLogJob(job
, CUPSD_LOG_INFO
, "Restarted by \"%s\".", username
);
9387 con
->response
->request
.status
.status_code
= IPP_OK
;
9392 * 'save_auth_info()' - Save authentication information for a job.
9397 cupsd_client_t
*con
, /* I - Client connection */
9398 cupsd_job_t
*job
, /* I - Job */
9399 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
9401 int i
; /* Looping var */
9402 char filename
[1024]; /* Job authentication filename */
9403 cups_file_t
*fp
; /* Job authentication file */
9404 char line
[65536]; /* Line for file */
9405 cupsd_printer_t
*dest
; /* Destination printer/class */
9409 * This function saves the in-memory authentication information for
9410 * a job so that it can be used to authenticate with a remote host.
9411 * The information is stored in a file that is readable only by the
9412 * root user. The fields are Base-64 encoded, each on a separate line,
9413 * followed by random number (up to 1024) of newlines to limit the
9414 * amount of information that is exposed.
9416 * Because of the potential for exposing of authentication information,
9417 * this functionality is only enabled when running cupsd as root.
9419 * This caching only works for the Basic and BasicDigest authentication
9420 * types. Digest authentication cannot be cached this way, and in
9421 * the future Kerberos authentication may make all of this obsolete.
9423 * Authentication information is saved whenever an authenticated
9424 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
9427 * This information is deleted after a job is completed or canceled,
9428 * so reprints may require subsequent re-authentication.
9434 if ((dest
= cupsdFindDest(job
->dest
)) == NULL
)
9438 * Create the authentication file and change permissions...
9441 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
9442 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
9444 cupsdLogMessage(CUPSD_LOG_ERROR
,
9445 "Unable to save authentication info to \"%s\" - %s",
9446 filename
, strerror(errno
));
9450 fchown(cupsFileNumber(fp
), 0, 0);
9451 fchmod(cupsFileNumber(fp
), 0400);
9453 cupsFilePuts(fp
, "CUPSD-AUTH-V3\n");
9456 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9458 cupsdClearString(job
->auth_env
+ i
);
9460 if (auth_info
&& auth_info
->num_values
== dest
->num_auth_info_required
)
9463 * Write 1 to 3 auth values...
9467 i
< auth_info
->num_values
&&
9468 i
< (int)(sizeof(job
->auth_env
) / sizeof(job
->auth_env
[0]));
9471 if (strcmp(dest
->auth_info_required
[i
], "negotiate"))
9473 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
, (int)strlen(auth_info
->values
[i
].string
.text
));
9474 cupsFilePutConf(fp
, dest
->auth_info_required
[i
], line
);
9477 cupsFilePutConf(fp
, dest
->auth_info_required
[i
],
9478 auth_info
->values
[i
].string
.text
);
9480 if (!strcmp(dest
->auth_info_required
[i
], "username"))
9481 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_USERNAME=%s",
9482 auth_info
->values
[i
].string
.text
);
9483 else if (!strcmp(dest
->auth_info_required
[i
], "domain"))
9484 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_DOMAIN=%s",
9485 auth_info
->values
[i
].string
.text
);
9486 else if (!strcmp(dest
->auth_info_required
[i
], "password"))
9487 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_PASSWORD=%s",
9488 auth_info
->values
[i
].string
.text
);
9489 else if (!strcmp(dest
->auth_info_required
[i
], "negotiate"))
9490 cupsdSetStringf(job
->auth_env
+ i
, "AUTH_NEGOTIATE=%s",
9491 auth_info
->values
[i
].string
.text
);
9496 else if (auth_info
&& auth_info
->num_values
== 2 &&
9497 dest
->num_auth_info_required
== 1 &&
9498 !strcmp(dest
->auth_info_required
[0], "negotiate"))
9501 * Allow fallback to username+password for Kerberized queues...
9504 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[0].string
.text
, (int)strlen(auth_info
->values
[0].string
.text
));
9505 cupsFilePutConf(fp
, "username", line
);
9507 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s",
9508 auth_info
->values
[0].string
.text
);
9510 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[1].string
.text
, (int)strlen(auth_info
->values
[1].string
.text
));
9511 cupsFilePutConf(fp
, "password", line
);
9513 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s",
9514 auth_info
->values
[1].string
.text
);
9516 else if (con
->username
[0])
9519 * Write the authenticated username...
9522 httpEncode64_2(line
, sizeof(line
), con
->username
, (int)strlen(con
->username
));
9523 cupsFilePutConf(fp
, "username", line
);
9525 cupsdSetStringf(job
->auth_env
+ 0, "AUTH_USERNAME=%s", con
->username
);
9528 * Write the authenticated password...
9531 httpEncode64_2(line
, sizeof(line
), con
->password
, (int)strlen(con
->password
));
9532 cupsFilePutConf(fp
, "password", line
);
9534 cupsdSetStringf(job
->auth_env
+ 1, "AUTH_PASSWORD=%s", con
->password
);
9538 if (con
->gss_uid
> 0)
9540 cupsFilePrintf(fp
, "uid %d\n", (int)con
->gss_uid
);
9541 cupsdSetStringf(&job
->auth_uid
, "AUTH_UID=%d", (int)con
->gss_uid
);
9543 #endif /* HAVE_GSSAPI */
9546 * Write a random number of newlines to the end of the file...
9549 for (i
= (CUPS_RAND() % 1024); i
>= 0; i
--)
9550 cupsFilePutChar(fp
, '\n');
9553 * Close the file and return...
9561 * 'send_document()' - Send a file to a printer or class.
9565 send_document(cupsd_client_t
*con
, /* I - Client connection */
9566 ipp_attribute_t
*uri
) /* I - Printer URI */
9568 ipp_attribute_t
*attr
; /* Current attribute */
9569 ipp_attribute_t
*format
; /* Request's document-format attribute */
9570 ipp_attribute_t
*jformat
; /* Job's document-format attribute */
9571 const char *default_format
;/* document-format-default value */
9572 int jobid
; /* Job ID number */
9573 cupsd_job_t
*job
; /* Current job */
9574 char job_uri
[HTTP_MAX_URI
],
9576 scheme
[HTTP_MAX_URI
],
9577 /* Method portion of URI */
9578 username
[HTTP_MAX_URI
],
9579 /* Username portion of URI */
9581 /* Host portion of URI */
9582 resource
[HTTP_MAX_URI
];
9583 /* Resource portion of URI */
9584 int port
; /* Port portion of URI */
9585 mime_type_t
*filetype
; /* Type of file */
9586 char super
[MIME_MAX_SUPER
],
9587 /* Supertype of file */
9588 type
[MIME_MAX_TYPE
],
9589 /* Subtype of file */
9590 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
9591 /* Textual name of mime type */
9592 char filename
[1024]; /* Job filename */
9593 cupsd_printer_t
*printer
; /* Current printer */
9594 struct stat fileinfo
; /* File information */
9595 int kbytes
; /* Size of file */
9596 int compression
; /* Type of compression */
9597 int start_job
; /* Start the job? */
9600 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
9601 con
->number
, uri
->values
[0].string
.text
);
9604 * See if we have a job URI or a printer URI...
9607 if (!strcmp(uri
->name
, "printer-uri"))
9610 * Got a printer URI; see if we also have a job-id attribute...
9613 if ((attr
= ippFindAttribute(con
->request
, "job-id",
9614 IPP_TAG_INTEGER
)) == NULL
)
9616 send_ipp_status(con
, IPP_BAD_REQUEST
,
9617 _("Got a printer-uri attribute but no job-id."));
9621 jobid
= attr
->values
[0].integer
;
9626 * Got a job URI; parse it to get the job ID...
9629 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
9630 sizeof(scheme
), username
, sizeof(username
), host
,
9631 sizeof(host
), &port
, resource
, sizeof(resource
));
9633 if (strncmp(resource
, "/jobs/", 6))
9639 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
9640 uri
->values
[0].string
.text
);
9644 jobid
= atoi(resource
+ 6);
9648 * See if the job exists...
9651 if ((job
= cupsdFindJob(jobid
)) == NULL
)
9654 * Nope - return a "not found" error...
9657 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
9661 printer
= cupsdFindDest(job
->dest
);
9664 * See if the job is owned by the requesting user...
9667 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
9669 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
9670 cupsdFindDest(job
->dest
));
9675 * OK, see if the client is sending the document compressed - CUPS
9676 * only supports "none" and "gzip".
9679 compression
= CUPS_FILE_NONE
;
9681 if ((attr
= ippFindAttribute(con
->request
, "compression",
9682 IPP_TAG_KEYWORD
)) != NULL
)
9684 if (strcmp(attr
->values
[0].string
.text
, "none")
9686 && strcmp(attr
->values
[0].string
.text
, "gzip")
9687 #endif /* HAVE_LIBZ */
9690 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"."),
9691 attr
->values
[0].string
.text
);
9692 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9693 "compression", NULL
, attr
->values
[0].string
.text
);
9698 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
9699 compression
= CUPS_FILE_GZIP
;
9700 #endif /* HAVE_LIBZ */
9704 * Do we have a file to print?
9707 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9708 IPP_TAG_BOOLEAN
)) == NULL
)
9710 send_ipp_status(con
, IPP_BAD_REQUEST
,
9711 _("Missing last-document attribute in request."));
9718 * Check for an empty request with "last-document" set to true, which is
9719 * used to close an "open" job by RFC 2911, section 3.3.2.
9722 if (job
->num_files
> 0 && attr
->values
[0].boolean
)
9725 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file in print request."));
9730 * Is it a format we support?
9735 if ((format
= ippFindAttribute(con
->request
, "document-format",
9736 IPP_TAG_MIMETYPE
)) != NULL
)
9739 * Grab format from client...
9742 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
9745 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"."),
9746 format
->values
[0].string
.text
);
9750 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-supplied", NULL
, ippGetString(format
, 0, NULL
));
9752 else if ((default_format
= cupsGetOption("document-format",
9753 printer
->num_options
,
9754 printer
->options
)) != NULL
)
9757 * Use default document format...
9760 if (sscanf(default_format
, "%15[^/]/%255[^;]", super
, type
) != 2)
9762 send_ipp_status(con
, IPP_BAD_REQUEST
,
9763 _("Bad document-format-default \"%s\"."), default_format
);
9770 * No document format attribute? Auto-type it!
9773 strlcpy(super
, "application", sizeof(super
));
9774 strlcpy(type
, "octet-stream", sizeof(type
));
9777 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
9780 * Auto-type the file...
9783 ipp_attribute_t
*doc_name
; /* document-name attribute */
9786 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Auto-typing file...");
9788 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
9789 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
9790 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
9794 filetype
= mimeType(MimeDatabase
, super
, type
);
9797 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Request file type is %s/%s.",
9798 filetype
->super
, filetype
->type
);
9800 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
, filetype
->type
);
9801 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
, "document-format-detected", NULL
, mimetype
);
9804 filetype
= mimeType(MimeDatabase
, super
, type
);
9809 * Replace the document-format attribute value with the auto-typed or
9813 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9816 if ((jformat
= ippFindAttribute(job
->attrs
, "document-format",
9817 IPP_TAG_MIMETYPE
)) != NULL
)
9818 ippSetString(job
->attrs
, &jformat
, 0, mimetype
);
9820 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
9821 "document-format", NULL
, mimetype
);
9825 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9826 _("Unsupported document-format \"%s/%s\"."), super
, type
);
9827 cupsdLogMessage(CUPSD_LOG_INFO
,
9828 "Hint: Do you have the raw file printing rules enabled?");
9831 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9832 "document-format", NULL
, format
->values
[0].string
.text
);
9837 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
9839 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
9842 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9843 _("Unsupported document-format \"%s\"."), mimetype
);
9845 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9846 "document-format", NULL
, mimetype
);
9852 * Add the file to the job...
9855 if (add_file(con
, job
, filetype
, compression
))
9858 if ((attr
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
)) != NULL
)
9859 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "document-name-supplied", NULL
, ippGetString(attr
, 0, NULL
));
9861 if (stat(con
->filename
, &fileinfo
))
9864 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
9866 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
9868 job
->koctets
+= kbytes
;
9870 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets", IPP_TAG_INTEGER
)) != NULL
)
9871 attr
->values
[0].integer
+= kbytes
;
9873 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
, job
->num_files
);
9874 if (rename(con
->filename
, filename
))
9876 cupsdLogJob(job
, CUPSD_LOG_ERROR
, "Unable to rename job document file \"%s\": %s", filename
, strerror(errno
));
9878 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to rename job document file."));
9882 cupsdClearString(&con
->filename
);
9884 cupsdLogJob(job
, CUPSD_LOG_INFO
, "File of type %s/%s queued by \"%s\".",
9885 filetype
->super
, filetype
->type
, job
->username
);
9888 * Start the job if this is the last document...
9893 if ((attr
= ippFindAttribute(con
->request
, "last-document",
9894 IPP_TAG_BOOLEAN
)) != NULL
&&
9895 attr
->values
[0].boolean
)
9898 * See if we need to add the ending sheet...
9901 if (cupsdTimeoutJob(job
))
9904 if (job
->state_value
== IPP_JOB_STOPPED
)
9906 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9907 job
->state_value
= IPP_JOB_PENDING
;
9909 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9911 else if (job
->state_value
== IPP_JOB_HELD
)
9913 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9914 IPP_TAG_KEYWORD
)) == NULL
)
9915 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9917 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9919 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
9920 job
->state_value
= IPP_JOB_PENDING
;
9922 ippSetString(job
->attrs
, &job
->reasons
, 0, "none");
9925 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-hold-until-specified");
9929 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9935 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
9936 IPP_TAG_KEYWORD
)) == NULL
)
9937 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
9939 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
9941 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
9942 job
->state_value
= IPP_JOB_HELD
;
9943 job
->hold_until
= time(NULL
) + MultipleOperationTimeout
;
9945 ippSetString(job
->attrs
, &job
->reasons
, 0, "job-incoming");
9948 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
9955 * Fill in the response info...
9958 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
9959 con
->clientname
, con
->clientport
, "/jobs/%d", jobid
);
9960 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
9963 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
9965 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
9967 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
, "job-state-reasons",
9968 NULL
, job
->reasons
->values
[0].string
.text
);
9970 con
->response
->request
.status
.status_code
= IPP_OK
;
9973 * Start the job if necessary...
9982 * 'send_http_error()' - Send a HTTP error back to the IPP client.
9987 cupsd_client_t
*con
, /* I - Client connection */
9988 http_status_t status
, /* I - HTTP status code */
9989 cupsd_printer_t
*printer
) /* I - Printer, if any */
9991 ipp_attribute_t
*uri
; /* Request URI, if any */
9994 if ((uri
= ippFindAttribute(con
->request
, "printer-uri",
9995 IPP_TAG_URI
)) == NULL
)
9996 uri
= ippFindAttribute(con
->request
, "job-uri", IPP_TAG_URI
);
9998 cupsdLogMessage(status
== HTTP_FORBIDDEN
? CUPSD_LOG_ERROR
: CUPSD_LOG_DEBUG
,
9999 "[Client %d] Returning HTTP %s for %s (%s) from %s",
10000 con
->number
, httpStatus(status
),
10002 ippOpString(con
->request
->request
.op
.operation_id
) :
10004 uri
? uri
->values
[0].string
.text
: "no URI",
10005 con
->http
->hostname
);
10009 int auth_type
; /* Type of authentication required */
10012 auth_type
= CUPSD_AUTH_NONE
;
10014 if (status
== HTTP_UNAUTHORIZED
&&
10015 printer
->num_auth_info_required
> 0 &&
10016 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
10018 (con
->request
->request
.op
.operation_id
== IPP_PRINT_JOB
||
10019 con
->request
->request
.op
.operation_id
== IPP_CREATE_JOB
||
10020 con
->request
->request
.op
.operation_id
== CUPS_AUTHENTICATE_JOB
))
10023 * Creating and authenticating jobs requires Kerberos...
10026 auth_type
= CUPSD_AUTH_NEGOTIATE
;
10031 * Use policy/location-defined authentication requirements...
10034 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
10035 cupsd_location_t
*auth
; /* Pointer to authentication element */
10038 if (printer
->type
& CUPS_PRINTER_CLASS
)
10039 snprintf(resource
, sizeof(resource
), "/classes/%s", printer
->name
);
10041 snprintf(resource
, sizeof(resource
), "/printers/%s", printer
->name
);
10043 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
10044 auth
->type
== CUPSD_AUTH_NONE
)
10045 auth
= cupsdFindPolicyOp(printer
->op_policy_ptr
,
10047 con
->request
->request
.op
.operation_id
:
10052 if (auth
->type
== CUPSD_AUTH_DEFAULT
)
10053 auth_type
= cupsdDefaultAuthType();
10055 auth_type
= auth
->type
;
10059 cupsdSendError(con
, status
, auth_type
);
10062 cupsdSendError(con
, status
, CUPSD_AUTH_NONE
);
10064 ippDelete(con
->response
);
10065 con
->response
= NULL
;
10072 * 'send_ipp_status()' - Send a status back to the IPP client.
10076 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
10077 ipp_status_t status
, /* I - IPP status code */
10078 const char *message
,/* I - Status message */
10079 ...) /* I - Additional args as needed */
10081 va_list ap
; /* Pointer to additional args */
10082 char formatted
[1024]; /* Formatted errror message */
10085 va_start(ap
, message
);
10086 vsnprintf(formatted
, sizeof(formatted
),
10087 _cupsLangString(con
->language
, message
), ap
);
10090 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
10091 ippOpString(con
->request
->request
.op
.operation_id
),
10092 ippErrorString(status
), formatted
);
10094 con
->response
->request
.status
.status_code
= status
;
10096 if (ippFindAttribute(con
->response
, "attributes-charset",
10097 IPP_TAG_ZERO
) == NULL
)
10098 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
10099 "attributes-charset", NULL
, "utf-8");
10101 if (ippFindAttribute(con
->response
, "attributes-natural-language",
10102 IPP_TAG_ZERO
) == NULL
)
10103 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
10104 "attributes-natural-language", NULL
, DefaultLanguage
);
10106 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
10107 "status-message", NULL
, formatted
);
10112 * 'set_default()' - Set the default destination...
10116 set_default(cupsd_client_t
*con
, /* I - Client connection */
10117 ipp_attribute_t
*uri
) /* I - Printer URI */
10119 http_status_t status
; /* Policy status */
10120 cups_ptype_t dtype
; /* Destination type (printer/class) */
10121 cupsd_printer_t
*printer
, /* Printer */
10122 *oldprinter
; /* Old default printer */
10125 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
10126 con
->number
, uri
->values
[0].string
.text
);
10129 * Is the destination valid?
10132 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10138 send_ipp_status(con
, IPP_NOT_FOUND
,
10139 _("The printer or class does not exist."));
10147 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
10149 send_http_error(con
, status
, NULL
);
10154 * Set it as the default...
10157 oldprinter
= DefaultPrinter
;
10158 DefaultPrinter
= printer
;
10161 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, oldprinter
, NULL
,
10162 "%s is no longer the default printer.", oldprinter
->name
);
10164 cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE
, printer
, NULL
,
10165 "%s is now the default printer.", printer
->name
);
10167 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
| CUPSD_DIRTY_CLASSES
|
10168 CUPSD_DIRTY_PRINTCAP
);
10170 cupsdLogMessage(CUPSD_LOG_INFO
,
10171 "Default destination set to \"%s\" by \"%s\".",
10172 printer
->name
, get_username(con
));
10175 * Everything was ok, so return OK status...
10178 con
->response
->request
.status
.status_code
= IPP_OK
;
10183 * 'set_job_attrs()' - Set job attributes.
10187 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
10188 ipp_attribute_t
*uri
) /* I - Job URI */
10190 ipp_attribute_t
*attr
, /* Current attribute */
10191 *attr2
; /* Job attribute */
10192 int jobid
; /* Job ID */
10193 cupsd_job_t
*job
; /* Current job */
10194 char scheme
[HTTP_MAX_URI
],
10195 /* Method portion of URI */
10196 username
[HTTP_MAX_URI
],
10197 /* Username portion of URI */
10198 host
[HTTP_MAX_URI
],
10199 /* Host portion of URI */
10200 resource
[HTTP_MAX_URI
];
10201 /* Resource portion of URI */
10202 int port
; /* Port portion of URI */
10203 int event
; /* Events? */
10204 int check_jobs
; /* Check jobs? */
10207 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
10208 con
->number
, uri
->values
[0].string
.text
);
10211 * Start with "everything is OK" status...
10214 con
->response
->request
.status
.status_code
= IPP_OK
;
10217 * See if we have a job URI or a printer URI...
10220 if (!strcmp(uri
->name
, "printer-uri"))
10223 * Got a printer URI; see if we also have a job-id attribute...
10226 if ((attr
= ippFindAttribute(con
->request
, "job-id",
10227 IPP_TAG_INTEGER
)) == NULL
)
10229 send_ipp_status(con
, IPP_BAD_REQUEST
,
10230 _("Got a printer-uri attribute but no job-id."));
10234 jobid
= attr
->values
[0].integer
;
10239 * Got a job URI; parse it to get the job ID...
10242 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
10243 sizeof(scheme
), username
, sizeof(username
), host
,
10244 sizeof(host
), &port
, resource
, sizeof(resource
));
10246 if (strncmp(resource
, "/jobs/", 6))
10252 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri \"%s\"."),
10253 uri
->values
[0].string
.text
);
10257 jobid
= atoi(resource
+ 6);
10261 * See if the job exists...
10264 if ((job
= cupsdFindJob(jobid
)) == NULL
)
10267 * Nope - return a "not found" error...
10270 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist."), jobid
);
10275 * See if the job has been completed...
10278 if (job
->state_value
> IPP_JOB_STOPPED
)
10281 * Return a "not-possible" error...
10284 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10285 _("Job #%d is finished and cannot be altered."), jobid
);
10290 * See if the job is owned by the requesting user...
10293 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
10295 send_http_error(con
, con
->username
[0] ? HTTP_FORBIDDEN
: HTTP_UNAUTHORIZED
,
10296 cupsdFindDest(job
->dest
));
10301 * See what the user wants to change.
10309 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10311 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
10314 if (!strcmp(attr
->name
, "attributes-charset") ||
10315 !strcmp(attr
->name
, "attributes-natural-language") ||
10316 !strncmp(attr
->name
, "date-time-at-", 13) ||
10317 !strncmp(attr
->name
, "document-compression", 20) ||
10318 !strncmp(attr
->name
, "document-format", 15) ||
10319 !strcmp(attr
->name
, "job-detailed-status-messages") ||
10320 !strcmp(attr
->name
, "job-document-access-errors") ||
10321 !strcmp(attr
->name
, "job-id") ||
10322 !strcmp(attr
->name
, "job-impressions-completed") ||
10323 !strcmp(attr
->name
, "job-k-octets-completed") ||
10324 !strcmp(attr
->name
, "job-media-sheets-completed") ||
10325 !strcmp(attr
->name
, "job-originating-host-name") ||
10326 !strcmp(attr
->name
, "job-originating-user-name") ||
10327 !strcmp(attr
->name
, "job-pages-completed") ||
10328 !strcmp(attr
->name
, "job-printer-up-time") ||
10329 !strcmp(attr
->name
, "job-printer-uri") ||
10330 !strcmp(attr
->name
, "job-sheets") ||
10331 !strcmp(attr
->name
, "job-state-message") ||
10332 !strcmp(attr
->name
, "job-state-reasons") ||
10333 !strcmp(attr
->name
, "job-uri") ||
10334 !strcmp(attr
->name
, "number-of-documents") ||
10335 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
10336 !strcmp(attr
->name
, "output-device-assigned") ||
10337 !strncmp(attr
->name
, "time-at-", 8))
10343 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
10344 _("%s cannot be changed."), attr
->name
);
10346 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10347 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10351 if (!ippValidateAttribute(attr
))
10353 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Bad '%s' value."), attr
->name
);
10354 ippCopyAttribute(con
->response
, attr
, 0);
10358 if (!strcmp(attr
->name
, "job-hold-until"))
10360 const char *when
= ippGetString(attr
, 0, NULL
);
10361 /* job-hold-until value */
10363 if ((ippGetValueTag(attr
) != IPP_TAG_KEYWORD
&& ippGetValueTag(attr
) != IPP_TAG_NAME
&& ippGetValueTag(attr
) != IPP_TAG_NAMELANG
) || ippGetCount(attr
) != 1)
10365 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
10366 ippCopyAttribute(con
->response
, attr
, 0);
10370 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-hold-until to %s", when
);
10371 cupsdSetJobHoldUntil(job
, when
, 0);
10373 if (!strcmp(when
, "no-hold"))
10375 cupsdReleaseJob(job
);
10379 cupsdSetJobState(job
, IPP_JOB_HELD
, CUPSD_JOB_DEFAULT
, "Job held by \"%s\".", username
);
10381 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
10383 else if (!strcmp(attr
->name
, "job-priority"))
10386 * Change the job priority...
10389 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10391 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value."));
10393 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10394 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10396 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
10398 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10399 _("Job is completed and cannot be changed."));
10402 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10404 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-priority to %d",
10405 attr
->values
[0].integer
);
10406 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
10409 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
|
10410 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
;
10413 else if (!strcmp(attr
->name
, "job-state"))
10416 * Change the job state...
10419 if (attr
->value_tag
!= IPP_TAG_ENUM
)
10421 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value."));
10423 attr2
= ippCopyAttribute(con
->response
, attr
, 0);
10424 ippSetGroupTag(con
->response
, &attr2
, IPP_TAG_UNSUPPORTED_GROUP
);
10428 switch (attr
->values
[0].integer
)
10430 case IPP_JOB_PENDING
:
10431 case IPP_JOB_HELD
:
10432 if (job
->state_value
> IPP_JOB_HELD
)
10434 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10435 _("Job state cannot be changed."));
10438 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10440 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10441 attr
->values
[0].integer
);
10442 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
, CUPSD_JOB_DEFAULT
, "Job state changed by \"%s\"", username
);
10447 case IPP_JOB_PROCESSING
:
10448 case IPP_JOB_STOPPED
:
10449 if (job
->state_value
!= attr
->values
[0].integer
)
10451 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10452 _("Job state cannot be changed."));
10457 case IPP_JOB_CANCELED
:
10458 case IPP_JOB_ABORTED
:
10459 case IPP_JOB_COMPLETED
:
10460 if (job
->state_value
> IPP_JOB_PROCESSING
)
10462 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10463 _("Job state cannot be changed."));
10466 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
10468 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "Setting job-state to %d",
10469 attr
->values
[0].integer
);
10470 cupsdSetJobState(job
, (ipp_jstate_t
)attr
->values
[0].integer
,
10472 "Job state changed by \"%s\"", username
);
10479 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
10481 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10482 IPP_TAG_ZERO
)) != NULL
)
10485 * Some other value; first free the old value...
10488 if (job
->attrs
->prev
)
10489 job
->attrs
->prev
->next
= attr2
->next
;
10491 job
->attrs
->attrs
= attr2
->next
;
10493 if (job
->attrs
->last
== attr2
)
10494 job
->attrs
->last
= job
->attrs
->prev
;
10496 ippDeleteAttribute(NULL
, attr2
);
10499 * Then copy the attribute...
10502 ippCopyAttribute(job
->attrs
, attr
, 0);
10504 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
10507 * Delete the attribute...
10510 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
10511 IPP_TAG_ZERO
)) != NULL
)
10513 if (job
->attrs
->prev
)
10514 job
->attrs
->prev
->next
= attr2
->next
;
10516 job
->attrs
->attrs
= attr2
->next
;
10518 if (attr2
== job
->attrs
->last
)
10519 job
->attrs
->last
= job
->attrs
->prev
;
10521 ippDeleteAttribute(NULL
, attr2
);
10523 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10529 * Add new option by copying it...
10532 ippCopyAttribute(job
->attrs
, attr
, 0);
10534 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
10543 cupsdMarkDirty(CUPSD_DIRTY_JOBS
);
10546 * Send events as needed...
10549 if (event
& CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
)
10550 cupsdAddEvent(CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED
,
10551 cupsdFindDest(job
->dest
), job
,
10552 "Job priority changed by user.");
10554 if (event
& CUPSD_EVENT_JOB_STATE
)
10555 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, cupsdFindDest(job
->dest
), job
,
10556 job
->state_value
== IPP_JOB_HELD
?
10557 "Job held by user." : "Job restarted by user.");
10559 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
10560 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, cupsdFindDest(job
->dest
), job
,
10561 "Job options changed by user.");
10564 * Start jobs if possible...
10573 * 'set_printer_attrs()' - Set printer attributes.
10577 set_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
10578 ipp_attribute_t
*uri
) /* I - Printer */
10580 http_status_t status
; /* Policy status */
10581 cups_ptype_t dtype
; /* Destination type (printer/class) */
10582 cupsd_printer_t
*printer
; /* Printer/class */
10583 ipp_attribute_t
*attr
; /* Printer attribute */
10584 int changed
= 0; /* Was anything changed? */
10587 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_attrs(%p[%d], %s)", con
,
10588 con
->number
, uri
->values
[0].string
.text
);
10591 * Is the destination valid?
10594 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10600 send_ipp_status(con
, IPP_NOT_FOUND
,
10601 _("The printer or class does not exist."));
10609 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10611 send_http_error(con
, status
, printer
);
10616 * Return a list of attributes that can be set via Set-Printer-Attributes.
10619 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
10620 IPP_TAG_TEXT
)) != NULL
)
10622 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
10626 if ((attr
= ippFindAttribute(con
->request
, "printer-geo-location", IPP_TAG_URI
)) != NULL
&& !strncmp(attr
->values
[0].string
.text
, "geo:", 4))
10628 cupsdSetString(&printer
->geo_location
, attr
->values
[0].string
.text
);
10632 if ((attr
= ippFindAttribute(con
->request
, "printer-organization", IPP_TAG_TEXT
)) != NULL
)
10634 cupsdSetString(&printer
->organization
, attr
->values
[0].string
.text
);
10638 if ((attr
= ippFindAttribute(con
->request
, "printer-organizational-unit", IPP_TAG_TEXT
)) != NULL
)
10640 cupsdSetString(&printer
->organizational_unit
, attr
->values
[0].string
.text
);
10644 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
10645 IPP_TAG_TEXT
)) != NULL
)
10647 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
10652 * Update the printer attributes and return...
10657 printer
->config_time
= time(NULL
);
10659 cupsdSetPrinterAttrs(printer
);
10660 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
10662 cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG
, printer
, NULL
,
10663 "Printer \"%s\" description or location changed by \"%s\".",
10664 printer
->name
, get_username(con
));
10666 cupsdLogMessage(CUPSD_LOG_INFO
,
10667 "Printer \"%s\" description or location changed by \"%s\".",
10668 printer
->name
, get_username(con
));
10671 con
->response
->request
.status
.status_code
= IPP_OK
;
10676 * 'set_printer_defaults()' - Set printer default options from a request.
10679 static int /* O - 1 on success, 0 on failure */
10680 set_printer_defaults(
10681 cupsd_client_t
*con
, /* I - Client connection */
10682 cupsd_printer_t
*printer
) /* I - Printer */
10684 int i
; /* Looping var */
10685 ipp_attribute_t
*attr
; /* Current attribute */
10686 size_t namelen
; /* Length of attribute name */
10687 char name
[256], /* New attribute name */
10688 value
[256]; /* String version of integer attrs */
10691 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
10694 * Skip non-printer attributes...
10697 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
10700 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
10702 if (!strcmp(attr
->name
, "job-sheets-default"))
10705 * Only allow keywords and names...
10708 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10712 * Only allow job-sheets-default to be set when running without a
10713 * system high classification level...
10716 if (Classification
)
10719 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
10721 if (attr
->num_values
> 1)
10722 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
10724 cupsdSetString(&printer
->job_sheets
[1], "none");
10726 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
10728 cupsdFreeStrings(&(printer
->users
));
10730 printer
->deny_users
= 0;
10732 if (attr
->value_tag
== IPP_TAG_NAME
&&
10733 (attr
->num_values
> 1 ||
10734 strcmp(attr
->values
[0].string
.text
, "all")))
10736 for (i
= 0; i
< attr
->num_values
; i
++)
10737 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10740 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
10742 cupsdFreeStrings(&(printer
->users
));
10744 printer
->deny_users
= 1;
10746 if (attr
->value_tag
== IPP_TAG_NAME
&&
10747 (attr
->num_values
> 1 ||
10748 strcmp(attr
->values
[0].string
.text
, "none")))
10750 for (i
= 0; i
< attr
->num_values
; i
++)
10751 cupsdAddString(&(printer
->users
), attr
->values
[i
].string
.text
);
10754 else if (!strcmp(attr
->name
, "job-quota-period"))
10756 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10759 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
10760 attr
->values
[0].integer
);
10761 cupsdFreeQuotas(printer
);
10763 printer
->quota_period
= attr
->values
[0].integer
;
10765 else if (!strcmp(attr
->name
, "job-k-limit"))
10767 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10770 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
10771 attr
->values
[0].integer
);
10772 cupsdFreeQuotas(printer
);
10774 printer
->k_limit
= attr
->values
[0].integer
;
10776 else if (!strcmp(attr
->name
, "job-page-limit"))
10778 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
10781 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
10782 attr
->values
[0].integer
);
10783 cupsdFreeQuotas(printer
);
10785 printer
->page_limit
= attr
->values
[0].integer
;
10787 else if (!strcmp(attr
->name
, "printer-op-policy"))
10789 cupsd_policy_t
*p
; /* Policy */
10792 if (attr
->value_tag
!= IPP_TAG_NAME
)
10795 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
10797 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10798 "Setting printer-op-policy to \"%s\"...",
10799 attr
->values
[0].string
.text
);
10800 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
10801 printer
->op_policy_ptr
= p
;
10805 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10806 _("Unknown printer-op-policy \"%s\"."),
10807 attr
->values
[0].string
.text
);
10811 else if (!strcmp(attr
->name
, "printer-error-policy"))
10813 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
10816 if (strcmp(attr
->values
[0].string
.text
, "retry-current-job") &&
10817 ((printer
->type
& CUPS_PRINTER_CLASS
) ||
10818 (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
10819 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
10820 strcmp(attr
->values
[0].string
.text
, "stop-printer"))))
10822 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
10823 _("Unknown printer-error-policy \"%s\"."),
10824 attr
->values
[0].string
.text
);
10828 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10829 "Setting printer-error-policy to \"%s\"...",
10830 attr
->values
[0].string
.text
);
10831 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
10835 * Skip any other non-default attributes...
10838 namelen
= strlen(attr
->name
);
10839 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
10840 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
10844 * OK, anything else must be a user-defined default...
10847 strlcpy(name
, attr
->name
, sizeof(name
));
10848 name
[namelen
- 8] = '\0'; /* Strip "-default" */
10850 switch (attr
->value_tag
)
10852 case IPP_TAG_DELETEATTR
:
10853 printer
->num_options
= cupsRemoveOption(name
,
10854 printer
->num_options
,
10855 &(printer
->options
));
10856 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10857 "Deleting %s", attr
->name
);
10860 case IPP_TAG_NAME
:
10861 case IPP_TAG_TEXT
:
10862 case IPP_TAG_KEYWORD
:
10864 printer
->num_options
= cupsAddOption(name
,
10865 attr
->values
[0].string
.text
,
10866 printer
->num_options
,
10867 &(printer
->options
));
10868 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10869 "Setting %s to \"%s\"...", attr
->name
,
10870 attr
->values
[0].string
.text
);
10873 case IPP_TAG_BOOLEAN
:
10874 printer
->num_options
= cupsAddOption(name
,
10875 attr
->values
[0].boolean
?
10877 printer
->num_options
,
10878 &(printer
->options
));
10879 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10880 "Setting %s to %s...", attr
->name
,
10881 attr
->values
[0].boolean
? "true" : "false");
10884 case IPP_TAG_INTEGER
:
10885 case IPP_TAG_ENUM
:
10886 sprintf(value
, "%d", attr
->values
[0].integer
);
10887 printer
->num_options
= cupsAddOption(name
, value
,
10888 printer
->num_options
,
10889 &(printer
->options
));
10890 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10891 "Setting %s to %s...", attr
->name
, value
);
10894 case IPP_TAG_RANGE
:
10895 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
10896 attr
->values
[0].range
.upper
);
10897 printer
->num_options
= cupsAddOption(name
, value
,
10898 printer
->num_options
,
10899 &(printer
->options
));
10900 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10901 "Setting %s to %s...", attr
->name
, value
);
10904 case IPP_TAG_RESOLUTION
:
10905 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
10906 attr
->values
[0].resolution
.yres
,
10907 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
10909 printer
->num_options
= cupsAddOption(name
, value
,
10910 printer
->num_options
,
10911 &(printer
->options
));
10912 cupsdLogMessage(CUPSD_LOG_DEBUG
,
10913 "Setting %s to %s...", attr
->name
, value
);
10917 /* Do nothing for other values */
10927 * 'start_printer()' - Start a printer.
10931 start_printer(cupsd_client_t
*con
, /* I - Client connection */
10932 ipp_attribute_t
*uri
) /* I - Printer URI */
10934 int i
; /* Temporary variable */
10935 http_status_t status
; /* Policy status */
10936 cups_ptype_t dtype
; /* Destination type (printer/class) */
10937 cupsd_printer_t
*printer
; /* Printer data */
10940 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
10941 con
->number
, uri
->values
[0].string
.text
);
10944 * Is the destination valid?
10947 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
10953 send_ipp_status(con
, IPP_NOT_FOUND
,
10954 _("The printer or class does not exist."));
10962 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
10964 send_http_error(con
, status
, printer
);
10969 * Start the printer...
10972 printer
->state_message
[0] = '\0';
10974 cupsdStartPrinter(printer
, 1);
10976 if (dtype
& CUPS_PRINTER_CLASS
)
10977 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
10978 printer
->name
, get_username(con
));
10980 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
10981 printer
->name
, get_username(con
));
10989 if ((i
= check_quotas(con
, printer
)) < 0)
10991 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
10996 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Not allowed to print."));
11001 * Everything was ok, so return OK status...
11004 con
->response
->request
.status
.status_code
= IPP_OK
;
11009 * 'stop_printer()' - Stop a printer.
11013 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
11014 ipp_attribute_t
*uri
) /* I - Printer URI */
11016 http_status_t status
; /* Policy status */
11017 cups_ptype_t dtype
; /* Destination type (printer/class) */
11018 cupsd_printer_t
*printer
; /* Printer data */
11019 ipp_attribute_t
*attr
; /* printer-state-message attribute */
11022 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
11023 con
->number
, uri
->values
[0].string
.text
);
11026 * Is the destination valid?
11029 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11035 send_ipp_status(con
, IPP_NOT_FOUND
,
11036 _("The printer or class does not exist."));
11044 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11046 send_http_error(con
, status
, printer
);
11051 * Stop the printer...
11054 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
11055 IPP_TAG_TEXT
)) == NULL
)
11056 strlcpy(printer
->state_message
, "Paused", sizeof(printer
->state_message
));
11059 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
11060 sizeof(printer
->state_message
));
11063 cupsdStopPrinter(printer
, 1);
11065 if (dtype
& CUPS_PRINTER_CLASS
)
11066 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
11067 printer
->name
, get_username(con
));
11069 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
11070 printer
->name
, get_username(con
));
11073 * Everything was ok, so return OK status...
11076 con
->response
->request
.status
.status_code
= IPP_OK
;
11081 * 'url_encode_attr()' - URL-encode a string attribute.
11085 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
11086 char *buffer
,/* I - String buffer */
11087 size_t bufsize
)/* I - Size of buffer */
11089 int i
; /* Looping var */
11090 char *bufptr
, /* Pointer into buffer */
11091 *bufend
; /* End of buffer */
11094 strlcpy(buffer
, attr
->name
, bufsize
);
11095 bufptr
= buffer
+ strlen(buffer
);
11096 bufend
= buffer
+ bufsize
- 1;
11098 for (i
= 0; i
< attr
->num_values
; i
++)
11100 if (bufptr
>= bufend
)
11108 if (bufptr
>= bufend
)
11113 bufptr
= url_encode_string(attr
->values
[i
].string
.text
, bufptr
, (size_t)(bufend
- bufptr
+ 1));
11115 if (bufptr
>= bufend
)
11126 * 'url_encode_string()' - URL-encode a string.
11129 static char * /* O - End of string */
11130 url_encode_string(const char *s
, /* I - String */
11131 char *buffer
, /* I - String buffer */
11132 size_t bufsize
) /* I - Size of buffer */
11134 char *bufptr
, /* Pointer into buffer */
11135 *bufend
; /* End of buffer */
11136 static const char *hex
= "0123456789ABCDEF";
11141 bufend
= buffer
+ bufsize
- 1;
11143 while (*s
&& bufptr
< bufend
)
11145 if (*s
== ' ' || *s
== '%' || *s
== '+')
11147 if (bufptr
>= (bufend
- 2))
11151 *bufptr
++ = hex
[(*s
>> 4) & 15];
11152 *bufptr
++ = hex
[*s
& 15];
11156 else if (*s
== '\'' || *s
== '\\')
11158 if (bufptr
>= (bufend
- 1))
11175 * 'user_allowed()' - See if a user is allowed to print to a queue.
11178 static int /* O - 0 if not allowed, 1 if allowed */
11179 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
11180 const char *username
) /* I - Username */
11182 struct passwd
*pw
; /* User password data */
11183 char baseuser
[256], /* Base username */
11184 *baseptr
, /* Pointer to "@" in base username */
11185 *name
; /* Current user name */
11188 if (cupsArrayCount(p
->users
) == 0)
11191 if (!strcmp(username
, "root"))
11194 if (strchr(username
, '@'))
11197 * Strip @REALM for username check...
11200 strlcpy(baseuser
, username
, sizeof(baseuser
));
11202 if ((baseptr
= strchr(baseuser
, '@')) != NULL
)
11205 username
= baseuser
;
11208 pw
= getpwnam(username
);
11211 for (name
= (char *)cupsArrayFirst(p
->users
);
11213 name
= (char *)cupsArrayNext(p
->users
))
11215 if (name
[0] == '@')
11218 * Check group membership...
11221 if (cupsdCheckGroup(username
, pw
, name
+ 1))
11224 else if (name
[0] == '#')
11230 if (cupsdCheckGroup(username
, pw
, name
))
11233 else if (!_cups_strcasecmp(username
, name
))
11237 return ((name
!= NULL
) != p
->deny_users
);
11242 * 'validate_job()' - Validate printer options and destination.
11246 validate_job(cupsd_client_t
*con
, /* I - Client connection */
11247 ipp_attribute_t
*uri
) /* I - Printer URI */
11249 http_status_t status
; /* Policy status */
11250 ipp_attribute_t
*attr
; /* Current attribute */
11252 ipp_attribute_t
*auth_info
; /* auth-info attribute */
11253 #endif /* HAVE_SSL */
11254 ipp_attribute_t
*format
, /* Document-format attribute */
11255 *name
; /* Job-name attribute */
11256 cups_ptype_t dtype
; /* Destination type (printer/class) */
11257 char super
[MIME_MAX_SUPER
],
11258 /* Supertype of file */
11259 type
[MIME_MAX_TYPE
];
11260 /* Subtype of file */
11261 cupsd_printer_t
*printer
; /* Printer */
11264 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
11265 con
->number
, uri
->values
[0].string
.text
);
11268 * OK, see if the client is sending the document compressed - CUPS
11269 * doesn't support compression yet...
11272 if ((attr
= ippFindAttribute(con
->request
, "compression",
11273 IPP_TAG_KEYWORD
)) != NULL
)
11275 if (strcmp(attr
->values
[0].string
.text
, "none")
11277 && strcmp(attr
->values
[0].string
.text
, "gzip")
11278 #endif /* HAVE_LIBZ */
11281 send_ipp_status(con
, IPP_ATTRIBUTES
,
11282 _("Unsupported 'compression' value \"%s\"."),
11283 attr
->values
[0].string
.text
);
11284 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
11285 "compression", NULL
, attr
->values
[0].string
.text
);
11291 * Is it a format we support?
11294 if ((format
= ippFindAttribute(con
->request
, "document-format",
11295 IPP_TAG_MIMETYPE
)) != NULL
)
11297 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%255[^;]",
11300 send_ipp_status(con
, IPP_BAD_REQUEST
,
11301 _("Bad 'document-format' value \"%s\"."),
11302 format
->values
[0].string
.text
);
11306 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
11307 !mimeType(MimeDatabase
, super
, type
))
11309 cupsdLogMessage(CUPSD_LOG_INFO
,
11310 "Hint: Do you have the raw file printing rules enabled?");
11311 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
11312 _("Unsupported 'document-format' value \"%s\"."),
11313 format
->values
[0].string
.text
);
11314 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
11315 "document-format", NULL
, format
->values
[0].string
.text
);
11321 * Is the job-hold-until value valid?
11324 if ((attr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_ZERO
)) != NULL
&& ((ippGetValueTag(attr
) != IPP_TAG_KEYWORD
&& ippGetValueTag(attr
) != IPP_TAG_NAME
&& ippGetValueTag(attr
) != IPP_TAG_NAMELANG
) || ippGetCount(attr
) != 1 || !ippValidateAttribute(attr
)))
11326 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-hold-until' value."));
11327 ippCopyAttribute(con
->response
, attr
, 0);
11332 * Is the job-name valid?
11335 if ((name
= ippFindAttribute(con
->request
, "job-name", IPP_TAG_ZERO
)) != NULL
)
11337 if ((name
->value_tag
!= IPP_TAG_NAME
&& name
->value_tag
!= IPP_TAG_NAMELANG
) ||
11338 name
->num_values
!= 1 || !ippValidateAttribute(name
))
11340 if (StrictConformance
)
11342 send_ipp_status(con
, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES
, _("Unsupported 'job-name' value."));
11343 ippCopyAttribute(con
->response
, name
, 0);
11348 cupsdLogMessage(CUPSD_LOG_WARN
, "Unsupported 'job-name' value, deleting from request.");
11349 ippDeleteAttribute(con
->request
, name
);
11355 * Is the destination valid?
11358 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
11364 send_ipp_status(con
, IPP_NOT_FOUND
,
11365 _("The printer or class does not exist."));
11374 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
11375 #endif /* HAVE_SSL */
11377 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
11379 send_http_error(con
, status
, printer
);
11382 else if (printer
->num_auth_info_required
== 1 &&
11383 !strcmp(printer
->auth_info_required
[0], "negotiate") &&
11386 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
11390 else if (auth_info
&& !con
->http
->tls
&&
11391 !httpAddrLocalhost(con
->http
->hostaddr
))
11394 * Require encryption of auth-info over non-local connections...
11397 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
11400 #endif /* HAVE_SSL */
11403 * Everything was ok, so return OK status...
11406 con
->response
->request
.status
.status_code
= IPP_OK
;
11411 * 'validate_name()' - Make sure the printer name only contains valid chars.
11414 static int /* O - 0 if name is no good, 1 if good */
11415 validate_name(const char *name
) /* I - Name to check */
11417 const char *ptr
; /* Pointer into name */
11421 * Scan the whole name...
11424 for (ptr
= name
; *ptr
; ptr
++)
11425 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
11429 * All the characters are good; validate the length, too...
11432 return ((ptr
- name
) < 128);
11437 * 'validate_user()' - Validate the user for the request.
11440 static int /* O - 1 if permitted, 0 otherwise */
11441 validate_user(cupsd_job_t
*job
, /* I - Job */
11442 cupsd_client_t
*con
, /* I - Client connection */
11443 const char *owner
, /* I - Owner of job/resource */
11444 char *username
, /* O - Authenticated username */
11445 size_t userlen
) /* I - Length of username */
11447 cupsd_printer_t
*printer
; /* Printer for job */
11450 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
);
11453 * Validate input...
11456 if (!con
|| !owner
|| !username
|| userlen
<= 0)
11460 * Get the best authenticated username that is available.
11463 strlcpy(username
, get_username(con
), userlen
);
11466 * Check the username against the owner...
11469 printer
= cupsdFindDest(job
->dest
);
11471 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
11472 con
, owner
) == HTTP_OK
);