2 * "$Id: ipp.c 6383 2007-03-21 20:01:20Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 * This file contains Kerberos support code, copyright 2006 by
11 * These coded instructions, statements, and computer programs are the
12 * property of Easy Software Products and are protected by Federal
13 * copyright law. Distribution and use rights are outlined in the file
14 * "LICENSE.txt" which should have been included with this file. If this
15 * file is missing or damaged please contact Easy Software Products
18 * Attn: CUPS Licensing Information
19 * Easy Software Products
20 * 44141 Airport View Drive, Suite 204
21 * Hollywood, Maryland 20636 USA
23 * Voice: (301) 373-9600
24 * EMail: cups-info@cups.org
25 * WWW: http://www.cups.org
29 * cupsdProcessIPPRequest() - Process an incoming IPP request...
30 * accept_jobs() - Accept print jobs to a printer.
31 * add_class() - Add a class to the system.
32 * add_file() - Add a file to a job.
33 * add_job() - Add a job to a print queue.
34 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
35 * upon the job and printer state...
36 * add_job_subscriptions() - Add any subcriptions for a job.
37 * add_job_uuid() - Add job-uuid attribute to a job.
38 * add_printer() - Add a printer to the system.
39 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
40 * based upon the printer state...
41 * add_queued_job_count() - Add the "queued-job-count" attribute for
42 * apply_printer_defaults() - Apply printer default options to a job.
43 * authenticate_job() - Set job authentication info.
44 * cancel_all_jobs() - Cancel all print jobs.
45 * cancel_job() - Cancel a print job.
46 * cancel_subscription() - Cancel a subscription.
47 * check_quotas() - Check quotas for a printer and user.
48 * copy_attribute() - Copy a single attribute.
49 * copy_attrs() - Copy attributes from one request to another.
50 * copy_banner() - Copy a banner file to the requests directory
51 * for the specified job.
52 * copy_file() - Copy a PPD file or interface script...
53 * copy_model() - Copy a PPD model file, substituting default
55 * copy_job_attrs() - Copy job attributes.
56 * copy_printer_attrs() - Copy printer attributes.
57 * copy_subscription_attrs() - Copy subscription attributes.
58 * create_job() - Print a file to a printer or class.
59 * create_requested_array() - Create an array for the requested-attributes.
60 * create_subscription() - Create a notification subscription.
61 * delete_printer() - Remove a printer or class from the system.
62 * get_default() - Get the default destination.
63 * get_devices() - Get the list of available devices on the
65 * get_job_attrs() - Get job attributes.
66 * get_jobs() - Get a list of jobs for the specified printer.
67 * get_notifications() - Get events for a subscription.
68 * get_ppds() - Get the list of PPD files on the local
70 * get_printer_attrs() - Get printer attributes.
71 * get_printers() - Get a list of printers.
72 * get_subscription_attrs() - Get subscription attributes.
73 * get_subscriptions() - Get subscriptions.
74 * get_username() - Get the username associated with a request.
75 * hold_job() - Hold a print job.
76 * move_job() - Move a job to a new destination.
77 * ppd_parse_line() - Parse a PPD default line.
78 * print_job() - Print a file to a printer or class.
79 * read_ps_line() - Read a line from a PS file...
80 * read_ps_job_ticket() - Reads a job ticket embedded in a PS file.
81 * reject_jobs() - Reject print jobs to a printer.
82 * release_job() - Release a held print job.
83 * restart_job() - Restart an old print job.
84 * save_auth_info() - Save authentication information for a job.
85 * save_krb5_creds() - Save Kerberos credentials for a job.
86 * send_document() - Send a file to a printer or class.
87 * send_http_error() - Send a HTTP error back to the IPP client.
88 * send_ipp_status() - Send a status back to the IPP client.
89 * set_default() - Set the default destination...
90 * set_job_attrs() - Set job attributes.
91 * set_printer_defaults() - Set printer default options from a request.
92 * start_printer() - Start a printer.
93 * stop_printer() - Stop a printer.
94 * url_encode_attr() - URL-encode a string attribute.
95 * user_allowed() - See if a user is allowed to print to a queue.
96 * validate_job() - Validate printer options and destination.
97 * validate_name() - Make sure the printer name only contains
99 * validate_user() - Validate the user for the request.
103 * Include necessary headers...
110 #endif /* HAVE_KRB5_H */
114 #endif /* HAVE_LIBPAPER */
117 # ifdef HAVE_MEMBERSHIP_H
118 # include <membership.h>
119 # endif /* HAVE_MEMBERSHIP_H */
120 # ifdef HAVE_MEMBERSHIPPRIV_H
121 # include <membershipPriv.h>
123 extern int mbr_user_name_to_uuid(const char* name
, uuid_t uu
);
124 extern int mbr_group_name_to_uuid(const char* name
, uuid_t uu
);
125 extern int mbr_check_membership_by_id(uuid_t user
, gid_t group
, int* ismember
);
126 # endif /* HAVE_MEMBERSHIPPRIV_H */
127 #endif /* __APPLE__ */
134 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
135 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
136 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
137 mime_type_t
*filetype
, int compression
);
138 static cupsd_job_t
*add_job(cupsd_client_t
*con
, cupsd_printer_t
*printer
,
139 mime_type_t
*filetype
);
140 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
141 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
142 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
143 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
144 static void add_printer_state_reasons(cupsd_client_t
*con
,
146 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
147 static void apply_printer_defaults(cupsd_printer_t
*printer
,
149 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
150 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
151 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
152 static void cancel_subscription(cupsd_client_t
*con
, int id
);
153 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
154 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
156 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
157 ipp_tag_t group
, int quickcopy
);
158 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
160 static int copy_file(const char *from
, const char *to
);
161 static int copy_model(cupsd_client_t
*con
, const char *from
,
163 static void copy_job_attrs(cupsd_client_t
*con
,
166 static void copy_printer_attrs(cupsd_client_t
*con
,
167 cupsd_printer_t
*printer
,
169 static void copy_subscription_attrs(cupsd_client_t
*con
,
170 cupsd_subscription_t
*sub
,
172 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
173 static cups_array_t
*create_requested_array(ipp_t
*request
);
174 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
175 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
176 static void get_default(cupsd_client_t
*con
);
177 static void get_devices(cupsd_client_t
*con
);
178 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
179 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static void get_notifications(cupsd_client_t
*con
);
181 static void get_ppds(cupsd_client_t
*con
);
182 static void get_printers(cupsd_client_t
*con
, int type
);
183 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
184 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
185 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static const char *get_username(cupsd_client_t
*con
);
187 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
189 static int ppd_parse_line(const char *line
, char *option
, int olen
,
190 char *choice
, int clen
);
191 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
192 static void read_ps_job_ticket(cupsd_client_t
*con
);
193 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
194 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
195 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
196 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
197 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
,
198 ipp_attribute_t
*auth_info
);
199 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
200 static void save_krb5_creds(cupsd_client_t
*con
, cupsd_job_t
*job
);
201 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
202 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
203 static void send_http_error(cupsd_client_t
*con
, http_status_t status
,
204 cupsd_printer_t
*printer
);
205 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
206 const char *message
, ...)
208 __attribute__ ((__format__ (__printf__
, 3, 4)))
209 # endif /* __GNUC__ */
211 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
212 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
213 static void set_printer_defaults(cupsd_client_t
*con
,
214 cupsd_printer_t
*printer
);
215 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
216 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
217 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
219 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
220 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
221 static int validate_name(const char *name
);
222 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
223 const char *owner
, char *username
,
228 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request...
231 int /* O - 1 on success, 0 on failure */
232 cupsdProcessIPPRequest(
233 cupsd_client_t
*con
) /* I - Client connection */
235 ipp_tag_t group
; /* Current group tag */
236 ipp_attribute_t
*attr
; /* Current attribute */
237 ipp_attribute_t
*charset
; /* Character set attribute */
238 ipp_attribute_t
*language
; /* Language attribute */
239 ipp_attribute_t
*uri
; /* Printer URI attribute */
240 ipp_attribute_t
*username
; /* requesting-user-name attr */
241 int sub_id
; /* Subscription ID */
244 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
245 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
246 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
249 * First build an empty response message for this request...
252 con
->response
= ippNew();
254 con
->response
->request
.status
.version
[0] = con
->request
->request
.op
.version
[0];
255 con
->response
->request
.status
.version
[1] = con
->request
->request
.op
.version
[1];
256 con
->response
->request
.status
.request_id
= con
->request
->request
.op
.request_id
;
259 * Then validate the request header and required attributes...
262 if (con
->request
->request
.any
.version
[0] != 1)
265 * Return an error, since we only support IPP 1.x.
268 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
269 "%04X %s Bad request version number %d.%d",
270 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
271 con
->request
->request
.any
.version
[0],
272 con
->request
->request
.any
.version
[1]);
274 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
275 _("Bad request version number %d.%d!"),
276 con
->request
->request
.any
.version
[0],
277 con
->request
->request
.any
.version
[1]);
279 else if (!con
->request
->attrs
)
281 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
282 "%04X %s No attributes in request",
283 IPP_BAD_REQUEST
, con
->http
.hostname
);
285 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
290 * Make sure that the attributes are provided in the correct order and
291 * don't repeat groups...
294 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
297 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
300 * Out of order; return an error...
303 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
304 "%04X %s Attribute groups are out of order",
305 IPP_BAD_REQUEST
, con
->http
.hostname
);
307 send_ipp_status(con
, IPP_BAD_REQUEST
,
308 _("Attribute groups are out of order (%x < %x)!"),
309 attr
->group_tag
, group
);
313 group
= attr
->group_tag
;
318 * Then make sure that the first three attributes are:
321 * attributes-natural-language
322 * printer-uri/job-uri
325 attr
= con
->request
->attrs
;
326 if (attr
&& !strcmp(attr
->name
, "attributes-charset") &&
327 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
335 if (attr
&& !strcmp(attr
->name
, "attributes-natural-language") &&
336 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
341 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
342 IPP_TAG_URI
)) != NULL
)
344 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
345 IPP_TAG_URI
)) != NULL
)
351 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
352 "attributes-charset", NULL
, charset
->values
[0].string
.text
);
354 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
355 "attributes-charset", NULL
, DefaultCharset
);
358 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
359 "attributes-natural-language", NULL
,
360 language
->values
[0].string
.text
);
362 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
363 "attributes-natural-language", NULL
, DefaultLanguage
);
365 if (!charset
|| !language
||
367 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
368 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
369 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
370 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
371 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
374 * Return an error, since attributes-charset,
375 * attributes-natural-language, and printer-uri/job-uri are required
376 * for all operations.
381 cupsdLogMessage(CUPSD_LOG_ERROR
,
382 "Missing attributes-charset attribute!");
384 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
385 "%04X %s Missing attributes-charset attribute",
386 IPP_BAD_REQUEST
, con
->http
.hostname
);
391 cupsdLogMessage(CUPSD_LOG_ERROR
,
392 "Missing attributes-natural-language attribute!");
394 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
395 "%04X %s Missing attributes-natural-language attribute",
396 IPP_BAD_REQUEST
, con
->http
.hostname
);
401 cupsdLogMessage(CUPSD_LOG_ERROR
,
402 "Missing printer-uri or job-uri attribute!");
404 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
405 "%04X %s Missing printer-uri or job-uri attribute",
406 IPP_BAD_REQUEST
, con
->http
.hostname
);
409 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
411 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
412 cupsdLogMessage(CUPSD_LOG_DEBUG
,
413 "attr \"%s\": group_tag = %x, value_tag = %x",
414 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
417 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
419 send_ipp_status(con
, IPP_BAD_REQUEST
,
420 _("Missing required attributes!"));
425 * OK, all the checks pass so far; make sure requesting-user-name is
426 * not "root" from a remote host...
429 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
430 IPP_TAG_NAME
)) != NULL
)
433 * Check for root user...
436 if (!strcmp(username
->values
[0].string
.text
, "root") &&
437 strcasecmp(con
->http
.hostname
, "localhost") &&
438 strcmp(con
->username
, "root"))
441 * Remote unauthenticated user masquerading as local root...
444 _cupsStrFree(username
->values
[0].string
.text
);
445 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
449 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
450 IPP_TAG_INTEGER
)) != NULL
)
451 sub_id
= attr
->values
[0].integer
;
456 * Then try processing the operation...
460 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
461 ippOpString(con
->request
->request
.op
.operation_id
),
462 uri
->values
[0].string
.text
);
464 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
465 ippOpString(con
->request
->request
.op
.operation_id
));
467 switch (con
->request
->request
.op
.operation_id
)
473 case IPP_VALIDATE_JOB
:
474 validate_job(con
, uri
);
477 case IPP_CREATE_JOB
:
478 create_job(con
, uri
);
481 case IPP_SEND_DOCUMENT
:
482 send_document(con
, uri
);
485 case IPP_CANCEL_JOB
:
486 cancel_job(con
, uri
);
489 case IPP_GET_JOB_ATTRIBUTES
:
490 get_job_attrs(con
, uri
);
497 case IPP_GET_PRINTER_ATTRIBUTES
:
498 get_printer_attrs(con
, uri
);
505 case IPP_RELEASE_JOB
:
506 release_job(con
, uri
);
509 case IPP_RESTART_JOB
:
510 restart_job(con
, uri
);
513 case IPP_PAUSE_PRINTER
:
514 stop_printer(con
, uri
);
517 case IPP_RESUME_PRINTER
:
518 start_printer(con
, uri
);
521 case IPP_PURGE_JOBS
:
522 cancel_all_jobs(con
, uri
);
525 case IPP_SET_JOB_ATTRIBUTES
:
526 set_job_attrs(con
, uri
);
529 case CUPS_GET_DEFAULT
:
533 case CUPS_GET_PRINTERS
:
534 get_printers(con
, 0);
537 case CUPS_GET_CLASSES
:
538 get_printers(con
, CUPS_PRINTER_CLASS
);
541 case CUPS_ADD_PRINTER
:
542 add_printer(con
, uri
);
545 case CUPS_DELETE_PRINTER
:
546 delete_printer(con
, uri
);
549 case CUPS_ADD_CLASS
:
553 case CUPS_DELETE_CLASS
:
554 delete_printer(con
, uri
);
557 case CUPS_ACCEPT_JOBS
:
558 case IPP_ENABLE_PRINTER
:
559 accept_jobs(con
, uri
);
562 case CUPS_REJECT_JOBS
:
563 case IPP_DISABLE_PRINTER
:
564 reject_jobs(con
, uri
);
567 case CUPS_SET_DEFAULT
:
568 set_default(con
, uri
);
571 case CUPS_GET_DEVICES
:
583 case CUPS_AUTHENTICATE_JOB
:
584 authenticate_job(con
, uri
);
587 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
588 case IPP_CREATE_JOB_SUBSCRIPTION
:
589 create_subscription(con
, uri
);
592 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
593 get_subscription_attrs(con
, sub_id
);
596 case IPP_GET_SUBSCRIPTIONS
:
597 get_subscriptions(con
, uri
);
600 case IPP_RENEW_SUBSCRIPTION
:
601 renew_subscription(con
, sub_id
);
604 case IPP_CANCEL_SUBSCRIPTION
:
605 cancel_subscription(con
, sub_id
);
608 case IPP_GET_NOTIFICATIONS
:
609 get_notifications(con
);
613 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
614 "%04X %s Operation %04X (%s) not supported",
615 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
616 con
->request
->request
.op
.operation_id
,
617 ippOpString(con
->request
->request
.op
.operation_id
));
619 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
620 _("%s not supported!"),
621 ippOpString(con
->request
->request
.op
.operation_id
));
631 * Sending data from the scheduler...
634 cupsdLogMessage(CUPSD_LOG_DEBUG
,
635 "cupsdProcessIPPRequest: %d status_code=%x (%s)",
636 con
->http
.fd
, con
->response
->request
.status
.status_code
,
637 ippErrorString(con
->response
->request
.status
.status_code
));
639 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp", AUTH_NONE
))
641 #ifdef CUPSD_USE_CHUNKING
643 * Because older versions of CUPS (1.1.17 and older) and some IPP
644 * clients do not implement chunking properly, we cannot use
645 * chunking by default. This may become the default in future
646 * CUPS releases, or we might add a configuration directive for
650 if (con
->http
.version
== HTTP_1_1
)
652 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
655 if (cupsdFlushHeader(con
) < 0)
658 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
661 #endif /* CUPSD_USE_CHUNKING */
663 size_t length
; /* Length of response */
666 length
= ippLength(con
->response
);
668 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
669 CUPS_LLCAST length
) < 0)
672 if (cupsdFlushHeader(con
) < 0)
675 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
676 con
->http
.data_remaining
= length
;
679 cupsdAddSelect(con
->http
.fd
, (cupsd_selfunc_t
)cupsdReadClient
,
680 (cupsd_selfunc_t
)cupsdWriteClient
, con
);
683 * Tell the caller the response header was sent successfully...
691 * Tell the caller the response header could not be sent...
700 * Sending data from a subprocess like cups-deviced; tell the caller
701 * everything is A-OK so far...
710 * 'accept_jobs()' - Accept print jobs to a printer.
714 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
715 ipp_attribute_t
*uri
) /* I - Printer or class URI */
717 http_status_t status
; /* Policy status */
718 cups_ptype_t dtype
; /* Destination type (printer or class) */
719 cupsd_printer_t
*printer
; /* Printer data */
722 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
723 con
->http
.fd
, uri
->values
[0].string
.text
);
726 * Is the destination valid?
729 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
735 send_ipp_status(con
, IPP_NOT_FOUND
,
736 _("The printer or class was not found."));
744 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
746 send_http_error(con
, status
, printer
);
751 * Accept jobs sent to the printer...
754 printer
->accepting
= 1;
755 printer
->state_message
[0] = '\0';
757 cupsdAddPrinterHistory(printer
);
759 if (dtype
& CUPS_PRINTER_CLASS
)
761 cupsdSaveAllClasses();
763 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" now accepting jobs (\"%s\").",
764 printer
->name
, get_username(con
));
768 cupsdSaveAllPrinters();
770 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" now accepting jobs (\"%s\").",
771 printer
->name
, get_username(con
));
775 * Everything was ok, so return OK status...
778 con
->response
->request
.status
.status_code
= IPP_OK
;
783 * 'add_class()' - Add a class to the system.
787 add_class(cupsd_client_t
*con
, /* I - Client connection */
788 ipp_attribute_t
*uri
) /* I - URI of class */
790 http_status_t status
; /* Policy status */
791 int i
; /* Looping var */
792 char method
[HTTP_MAX_URI
], /* Method portion of URI */
793 username
[HTTP_MAX_URI
], /* Username portion of URI */
794 host
[HTTP_MAX_URI
], /* Host portion of URI */
795 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
796 int port
; /* Port portion of URI */
797 cupsd_printer_t
*pclass
, /* Class */
798 *member
; /* Member printer/class */
799 cups_ptype_t dtype
; /* Destination type */
800 ipp_attribute_t
*attr
; /* Printer attribute */
801 int modify
; /* Non-zero if we just modified */
802 char newname
[IPP_MAX_NAME
]; /* New class name */
803 int need_restart_job
; /* Need to restart job? */
806 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
807 con
->http
.fd
, uri
->values
[0].string
.text
);
810 * Do we have a valid URI?
813 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
814 sizeof(method
), username
, sizeof(username
), host
,
815 sizeof(host
), &port
, resource
, sizeof(resource
));
818 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
821 * No, return an error...
824 send_ipp_status(con
, IPP_BAD_REQUEST
,
825 _("The printer-uri must be of the form "
826 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
831 * Do we have a valid printer name?
834 if (!validate_name(resource
+ 9))
837 * No, return an error...
840 send_ipp_status(con
, IPP_BAD_REQUEST
,
841 _("The printer-uri \"%s\" contains invalid characters."),
842 uri
->values
[0].string
.text
);
850 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
852 send_http_error(con
, status
, NULL
);
857 * See if the class already exists; if not, create a new class...
860 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
863 * Class doesn't exist; see if we have a printer of the same name...
866 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
867 !(pclass
->type
& CUPS_PRINTER_REMOTE
))
870 * Yes, return an error...
873 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
874 _("A printer named \"%s\" already exists!"),
880 * No, add the pclass...
883 pclass
= cupsdAddClass(resource
+ 9);
886 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
889 * Rename the implicit class to "AnyClass" or remove it...
892 if (ImplicitAnyClasses
)
894 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
895 cupsdRenamePrinter(pclass
, newname
);
898 cupsdDeletePrinter(pclass
, 1);
901 * Add the class as a new local class...
904 pclass
= cupsdAddClass(resource
+ 9);
907 else if (pclass
->type
& CUPS_PRINTER_REMOTE
)
910 * Rename the remote class to "Class"...
913 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
914 cupsdRenamePrinter(pclass
, newname
);
917 * Add the class as a new local class...
920 pclass
= cupsdAddClass(resource
+ 9);
927 * Look for attributes and copy them over as needed...
930 need_restart_job
= 0;
932 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
933 IPP_TAG_TEXT
)) != NULL
)
934 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
936 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
937 IPP_TAG_TEXT
)) != NULL
)
938 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
940 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
941 IPP_TAG_BOOLEAN
)) != NULL
)
943 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-is-accepting-jobs to %d (was %d.)",
944 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
946 pclass
->accepting
= attr
->values
[0].boolean
;
947 cupsdAddPrinterHistory(pclass
);
950 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
951 IPP_TAG_BOOLEAN
)) != NULL
)
953 if (pclass
->shared
&& !attr
->values
[0].boolean
)
954 cupsdDeregisterPrinter(pclass
, 1);
956 cupsdLogMessage(CUPSD_LOG_INFO
,
957 "Setting %s printer-is-shared to %d (was %d.)",
958 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
960 pclass
->shared
= attr
->values
[0].boolean
;
963 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
964 IPP_TAG_ENUM
)) != NULL
)
966 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
967 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
969 send_ipp_status(con
, IPP_BAD_REQUEST
,
970 _("Attempt to set %s printer-state to bad value %d!"),
971 pclass
->name
, attr
->values
[0].integer
);
975 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)", pclass
->name
,
976 attr
->values
[0].integer
, pclass
->state
);
978 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
979 cupsdStopPrinter(pclass
, 0);
982 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
983 need_restart_job
= 1;
986 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
987 IPP_TAG_TEXT
)) != NULL
)
989 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
990 sizeof(pclass
->state_message
));
991 cupsdAddPrinterHistory(pclass
);
993 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
994 IPP_TAG_URI
)) != NULL
)
997 * Clear the printer array as needed...
1000 need_restart_job
= 1;
1002 if (pclass
->num_printers
> 0)
1004 free(pclass
->printers
);
1005 pclass
->num_printers
= 0;
1009 * Add each printer or class that is listed...
1012 for (i
= 0; i
< attr
->num_values
; i
++)
1015 * Search for the printer or class URI...
1018 if (!cupsdValidateDest(attr
->values
[i
].string
.text
, &dtype
, &member
))
1024 send_ipp_status(con
, IPP_NOT_FOUND
,
1025 _("The printer or class was not found."));
1030 * Add it to the class...
1033 cupsdAddPrinterToClass(pclass
, member
);
1037 set_printer_defaults(con
, pclass
);
1040 * Update the printer class attributes and return...
1043 cupsdSetPrinterAttrs(pclass
);
1044 cupsdSaveAllClasses();
1046 if (need_restart_job
&& pclass
->job
)
1051 * Stop the current job and then restart it below...
1054 job
= (cupsd_job_t
*)pclass
->job
;
1056 cupsdStopJob(job
, 1);
1058 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1059 job
->state_value
= IPP_JOB_PENDING
;
1062 if (need_restart_job
)
1065 cupsdWritePrintcap();
1069 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1070 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1073 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1074 pclass
->name
, get_username(con
));
1078 cupsdAddPrinterHistory(pclass
);
1080 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1081 "New class \"%s\" added by \"%s\".", pclass
->name
,
1084 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1085 pclass
->name
, get_username(con
));
1088 con
->response
->request
.status
.status_code
= IPP_OK
;
1093 * 'add_file()' - Add a file to a job.
1096 static int /* O - 0 on success, -1 on error */
1097 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1098 cupsd_job_t
*job
, /* I - Job to add to */
1099 mime_type_t
*filetype
, /* I - Type of file */
1100 int compression
) /* I - Compression */
1102 mime_type_t
**filetypes
; /* New filetypes array... */
1103 int *compressions
; /* New compressions array... */
1106 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1107 "add_file(con=%p[%d], job=%d, filetype=%s/%s, compression=%d)",
1108 con
, con
->http
.fd
, job
->id
, filetype
->super
, filetype
->type
,
1112 * Add the file to the job...
1115 if (job
->num_files
== 0)
1117 compressions
= (int *)malloc(sizeof(int));
1118 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1122 compressions
= (int *)realloc(job
->compressions
,
1123 (job
->num_files
+ 1) * sizeof(int));
1124 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1125 (job
->num_files
+ 1) *
1126 sizeof(mime_type_t
*));
1129 if (!compressions
|| !filetypes
)
1131 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
1133 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1134 _("Unable to allocate memory for file types!"));
1138 job
->compressions
= compressions
;
1139 job
->compressions
[job
->num_files
] = compression
;
1140 job
->filetypes
= filetypes
;
1141 job
->filetypes
[job
->num_files
] = filetype
;
1150 * 'add_job()' - Add a job to a print queue.
1153 static cupsd_job_t
* /* O - Job object */
1154 add_job(cupsd_client_t
*con
, /* I - Client connection */
1155 cupsd_printer_t
*printer
, /* I - Destination printer */
1156 mime_type_t
*filetype
) /* I - First print file type, if any */
1158 http_status_t status
; /* Policy status */
1159 ipp_attribute_t
*attr
, /* Current attribute */
1160 *auth_info
; /* auth-info attribute */
1161 const char *val
; /* Default option value */
1162 int priority
; /* Job priority */
1163 char *title
; /* Job name/title */
1164 cupsd_job_t
*job
; /* Current job */
1165 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
1166 int kbytes
; /* Size of print file */
1167 int i
; /* Looping var */
1168 int lowerpagerange
; /* Page range bound */
1171 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %p(%s), %p(%s/%s))",
1172 con
, con
->http
.fd
, printer
, printer
->name
,
1173 filetype
, filetype
->super
, filetype
->type
);
1176 * Check remote printing to non-shared printer...
1179 if (!printer
->shared
&&
1180 strcasecmp(con
->http
.hostname
, "localhost") &&
1181 strcasecmp(con
->http
.hostname
, ServerName
))
1183 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1184 _("The printer or class is not shared!"));
1192 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
1194 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1196 send_http_error(con
, status
, printer
);
1199 else if ((printer
->type
& CUPS_PRINTER_AUTHENTICATED
) &&
1200 !con
->username
[0] && !auth_info
)
1202 send_http_error(con
, HTTP_UNAUTHORIZED
, printer
);
1206 else if (auth_info
&& !con
->http
.tls
&&
1207 !httpAddrLocalhost(con
->http
.hostaddr
))
1210 * Require encryption of auth-info over non-local connections...
1213 send_http_error(con
, HTTP_UPGRADE_REQUIRED
, printer
);
1216 #endif /* HAVE_SSL */
1219 * See if the printer is accepting jobs...
1222 if (!printer
->accepting
)
1224 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1225 _("Destination \"%s\" is not accepting jobs."),
1231 * Validate job template attributes; for now just document-format,
1232 * copies, number-up, and page-ranges...
1235 if (filetype
&& printer
->filetypes
&&
1236 !cupsArrayFind(printer
->filetypes
, filetype
))
1238 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1239 /* MIME media type string */
1242 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1245 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1246 _("Unsupported format \'%s\'!"), mimetype
);
1248 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1249 "document-format", NULL
, mimetype
);
1254 if ((attr
= ippFindAttribute(con
->request
, "copies",
1255 IPP_TAG_INTEGER
)) != NULL
)
1257 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1259 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1260 attr
->values
[0].integer
);
1261 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1262 "copies", attr
->values
[0].integer
);
1267 if ((attr
= ippFindAttribute(con
->request
, "number-up",
1268 IPP_TAG_INTEGER
)) != NULL
)
1270 if (attr
->values
[0].integer
!= 1 &&
1271 attr
->values
[0].integer
!= 2 &&
1272 attr
->values
[0].integer
!= 4 &&
1273 attr
->values
[0].integer
!= 6 &&
1274 attr
->values
[0].integer
!= 9 &&
1275 attr
->values
[0].integer
!= 16)
1277 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad number-up value %d."),
1278 attr
->values
[0].integer
);
1279 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1280 "number-up", attr
->values
[0].integer
);
1285 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1286 IPP_TAG_RANGE
)) != NULL
)
1288 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1290 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1291 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1293 send_ipp_status(con
, IPP_BAD_REQUEST
,
1294 _("Bad page-ranges values %d-%d."),
1295 attr
->values
[i
].range
.lower
,
1296 attr
->values
[i
].range
.upper
);
1300 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1305 * Make sure we aren't over our limit...
1308 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1311 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1313 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1314 _("Too many active jobs."));
1318 if (!check_quotas(con
, printer
))
1320 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1325 * Create the job and set things up...
1328 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1329 IPP_TAG_INTEGER
)) != NULL
)
1330 priority
= attr
->values
[0].integer
;
1333 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1334 printer
->options
)) != NULL
)
1335 priority
= atoi(val
);
1339 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1343 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1344 IPP_TAG_NAME
)) != NULL
)
1345 title
= attr
->values
[0].string
.text
;
1347 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1348 title
= "Untitled");
1350 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1352 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1353 _("Unable to add job for destination \"%s\"!"),
1358 job
->dtype
= printer
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
|
1359 CUPS_PRINTER_REMOTE
);
1360 job
->attrs
= con
->request
;
1361 con
->request
= ippNewRequest(job
->attrs
->request
.op
.operation_id
);
1363 add_job_uuid(con
, job
);
1364 apply_printer_defaults(printer
, job
);
1366 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1368 if (con
->username
[0])
1370 cupsdSetString(&job
->username
, con
->username
);
1373 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1377 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1378 "add_job: requesting-user-name=\"%s\"",
1379 attr
->values
[0].string
.text
);
1381 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1384 cupsdSetString(&job
->username
, "anonymous");
1387 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1388 "job-originating-user-name", NULL
, job
->username
);
1391 attr
->group_tag
= IPP_TAG_JOB
;
1392 _cupsStrFree(attr
->name
);
1393 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1396 if (con
->username
[0] || auth_info
)
1398 save_auth_info(con
, job
, auth_info
);
1401 * Remove the auth-info attribute from the attribute data...
1406 if (job
->attrs
->prev
)
1407 job
->attrs
->prev
->next
= auth_info
->next
;
1409 job
->attrs
->attrs
= auth_info
->next
;
1411 if (job
->attrs
->last
== auth_info
)
1412 job
->attrs
->last
= job
->attrs
->prev
;
1414 _ippFreeAttr(auth_info
);
1418 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1419 IPP_TAG_ZERO
)) != NULL
)
1422 * Request contains a job-originating-host-name attribute; validate it...
1425 if (attr
->value_tag
!= IPP_TAG_NAME
||
1426 attr
->num_values
!= 1 ||
1427 strcmp(con
->http
.hostname
, "localhost"))
1430 * Can't override the value if we aren't connected via localhost.
1431 * Also, we can only have 1 value and it must be a name value.
1434 switch (attr
->value_tag
)
1436 case IPP_TAG_STRING
:
1437 case IPP_TAG_TEXTLANG
:
1438 case IPP_TAG_NAMELANG
:
1441 case IPP_TAG_KEYWORD
:
1443 case IPP_TAG_URISCHEME
:
1444 case IPP_TAG_CHARSET
:
1445 case IPP_TAG_LANGUAGE
:
1446 case IPP_TAG_MIMETYPE
:
1448 * Free old strings...
1451 for (i
= 0; i
< attr
->num_values
; i
++)
1453 _cupsStrFree(attr
->values
[i
].string
.text
);
1454 attr
->values
[i
].string
.text
= NULL
;
1455 if (attr
->values
[i
].string
.charset
)
1457 _cupsStrFree(attr
->values
[i
].string
.charset
);
1458 attr
->values
[i
].string
.charset
= NULL
;
1467 * Use the default connection hostname instead...
1470 attr
->value_tag
= IPP_TAG_NAME
;
1471 attr
->num_values
= 1;
1472 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1475 attr
->group_tag
= IPP_TAG_JOB
;
1480 * No job-originating-host-name attribute, so use the hostname from
1484 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1485 "job-originating-host-name", NULL
, con
->http
.hostname
);
1488 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1490 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1491 "time-at-processing", 0);
1492 attr
->value_tag
= IPP_TAG_NOVALUE
;
1493 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1494 "time-at-completed", 0);
1495 attr
->value_tag
= IPP_TAG_NOVALUE
;
1498 * Add remaining job attributes...
1501 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1502 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1503 "job-state", IPP_JOB_STOPPED
);
1504 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1505 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1506 "job-media-sheets-completed", 0);
1507 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1509 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1512 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1513 IPP_TAG_INTEGER
)) != NULL
)
1514 attr
->values
[0].integer
= 0;
1516 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1519 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1520 IPP_TAG_KEYWORD
)) == NULL
)
1521 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1524 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1525 printer
->options
)) == NULL
)
1528 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1529 "job-hold-until", NULL
, val
);
1531 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1532 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1535 * Hold job until specified time...
1538 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1540 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1541 job
->state_value
= IPP_JOB_HELD
;
1543 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1545 job
->hold_until
= time(NULL
) + 60;
1546 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1547 job
->state_value
= IPP_JOB_HELD
;
1551 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1552 job
->state_value
= IPP_JOB_PENDING
;
1555 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1559 * Add job sheets options...
1562 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1563 IPP_TAG_ZERO
)) == NULL
)
1565 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1566 "Adding default job-sheets values \"%s,%s\"...",
1567 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1569 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1571 attr
->values
[0].string
.text
= _cupsStrAlloc(printer
->job_sheets
[0]);
1572 attr
->values
[1].string
.text
= _cupsStrAlloc(printer
->job_sheets
[1]);
1575 job
->job_sheets
= attr
;
1578 * Enforce classification level if set...
1583 cupsdLogMessage(CUPSD_LOG_INFO
,
1584 "Classification=\"%s\", ClassifyOverride=%d",
1585 Classification
? Classification
: "(null)",
1588 if (ClassifyOverride
)
1590 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1591 (attr
->num_values
== 1 ||
1592 !strcmp(attr
->values
[1].string
.text
, "none")))
1595 * Force the leading banner to have the classification on it...
1598 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1600 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
1601 "job-sheets=\"%s,none\", "
1602 "job-originating-user-name=\"%s\"",
1603 job
->id
, Classification
, job
->username
);
1605 else if (attr
->num_values
== 2 &&
1606 strcmp(attr
->values
[0].string
.text
,
1607 attr
->values
[1].string
.text
) &&
1608 strcmp(attr
->values
[0].string
.text
, "none") &&
1609 strcmp(attr
->values
[1].string
.text
, "none"))
1612 * Can't put two different security markings on the same document!
1615 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1617 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
1618 "job-sheets=\"%s,%s\", "
1619 "job-originating-user-name=\"%s\"",
1620 job
->id
, attr
->values
[0].string
.text
,
1621 attr
->values
[1].string
.text
, job
->username
);
1623 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1624 strcmp(attr
->values
[0].string
.text
, "none") &&
1625 (attr
->num_values
== 1 ||
1626 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1627 strcmp(attr
->values
[1].string
.text
, "none"))))
1629 if (attr
->num_values
== 1)
1630 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1631 "[Job %d] CLASSIFICATION OVERRIDDEN "
1632 "job-sheets=\"%s\", "
1633 "job-originating-user-name=\"%s\"",
1634 job
->id
, attr
->values
[0].string
.text
, job
->username
);
1636 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1637 "[Job %d] CLASSIFICATION OVERRIDDEN "
1638 "job-sheets=\"%s,%s\",fffff "
1639 "job-originating-user-name=\"%s\"",
1640 job
->id
, attr
->values
[0].string
.text
,
1641 attr
->values
[1].string
.text
, job
->username
);
1644 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1645 (attr
->num_values
== 1 ||
1646 strcmp(attr
->values
[1].string
.text
, Classification
)))
1649 * Force the banner to have the classification on it...
1652 if (attr
->num_values
> 1 &&
1653 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1655 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1656 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1660 if (attr
->num_values
== 1 ||
1661 strcmp(attr
->values
[0].string
.text
, "none"))
1662 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1664 if (attr
->num_values
> 1 &&
1665 strcmp(attr
->values
[1].string
.text
, "none"))
1666 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1669 if (attr
->num_values
> 1)
1670 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1671 "[Job %d] CLASSIFICATION FORCED "
1672 "job-sheets=\"%s,%s\", "
1673 "job-originating-user-name=\"%s\"",
1674 job
->id
, attr
->values
[0].string
.text
,
1675 attr
->values
[1].string
.text
, job
->username
);
1677 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1678 "[Job %d] CLASSIFICATION FORCED "
1679 "job-sheets=\"%s\", "
1680 "job-originating-user-name=\"%s\"",
1681 job
->id
, Classification
, job
->username
);
1686 * See if we need to add the starting sheet...
1689 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1691 cupsdLogMessage(CUPSD_LOG_INFO
,
1692 "Adding start banner page \"%s\" to job %d.",
1693 attr
->values
[0].string
.text
, job
->id
);
1695 kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
);
1697 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1700 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1701 IPP_TAG_ZERO
)) != NULL
)
1705 * Fill in the response info...
1708 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1709 LocalPort
, job
->id
);
1711 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1714 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1716 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1718 add_job_state_reasons(con
, job
);
1720 con
->response
->request
.status
.status_code
= IPP_OK
;
1723 * Add any job subscriptions...
1726 add_job_subscriptions(con
, job
);
1729 * Set all but the first two attributes to the job attributes group...
1732 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1733 attr
->group_tag
= IPP_TAG_JOB
;
1736 * Fire the "job created" event...
1739 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1742 * Return the new job...
1750 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1751 * upon the job and printer state...
1755 add_job_state_reasons(
1756 cupsd_client_t
*con
, /* I - Client connection */
1757 cupsd_job_t
*job
) /* I - Job info */
1759 cupsd_printer_t
*dest
; /* Destination printer */
1762 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1763 con
, con
->http
.fd
, job
? job
->id
: 0);
1765 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1767 case IPP_JOB_PENDING
:
1768 dest
= cupsdFindDest(job
->dest
);
1770 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1771 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1772 "job-state-reasons", NULL
, "printer-stopped");
1774 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1775 "job-state-reasons", NULL
, "none");
1779 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1780 IPP_TAG_KEYWORD
) != NULL
||
1781 ippFindAttribute(job
->attrs
, "job-hold-until",
1782 IPP_TAG_NAME
) != NULL
)
1783 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1784 "job-state-reasons", NULL
, "job-hold-until-specified");
1786 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1787 "job-state-reasons", NULL
, "job-incoming");
1790 case IPP_JOB_PROCESSING
:
1791 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1792 "job-state-reasons", NULL
, "job-printing");
1795 case IPP_JOB_STOPPED
:
1796 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1797 "job-state-reasons", NULL
, "job-stopped");
1800 case IPP_JOB_CANCELED
:
1801 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1802 "job-state-reasons", NULL
, "job-canceled-by-user");
1805 case IPP_JOB_ABORTED
:
1806 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1807 "job-state-reasons", NULL
, "aborted-by-system");
1810 case IPP_JOB_COMPLETED
:
1811 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1812 "job-state-reasons", NULL
, "job-completed-successfully");
1819 * 'add_job_subscriptions()' - Add any subcriptions for a job.
1823 add_job_subscriptions(
1824 cupsd_client_t
*con
, /* I - Client connection */
1825 cupsd_job_t
*job
) /* I - Newly created job */
1827 int i
; /* Looping var */
1828 ipp_attribute_t
*prev
, /* Previous attribute */
1829 *next
, /* Next attribute */
1830 *attr
; /* Current attribute */
1831 cupsd_subscription_t
*sub
; /* Subscription object */
1832 const char *recipient
, /* notify-recipient-uri */
1833 *pullmethod
; /* notify-pull-method */
1834 ipp_attribute_t
*user_data
; /* notify-user-data */
1835 int interval
; /* notify-time-interval */
1836 unsigned mask
; /* notify-events */
1840 * Find the first subscription group attribute; return if we have
1844 for (attr
= job
->attrs
->attrs
, prev
= NULL
;
1846 prev
= attr
, attr
= attr
->next
)
1847 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1854 * Process the subscription attributes in the request...
1863 mask
= CUPSD_EVENT_NONE
;
1865 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1867 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
1868 attr
->value_tag
== IPP_TAG_URI
)
1869 recipient
= attr
->values
[0].string
.text
;
1870 else if (!strcmp(attr
->name
, "notify-pull-method") &&
1871 attr
->value_tag
== IPP_TAG_KEYWORD
)
1872 pullmethod
= attr
->values
[0].string
.text
;
1873 else if (!strcmp(attr
->name
, "notify-charset") &&
1874 attr
->value_tag
== IPP_TAG_CHARSET
&&
1875 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
1876 strcmp(attr
->values
[0].string
.text
, "utf-8"))
1878 send_ipp_status(con
, IPP_CHARSET
,
1879 _("Character set \"%s\" not supported!"),
1880 attr
->values
[0].string
.text
);
1883 else if (!strcmp(attr
->name
, "notify-natural-language") &&
1884 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
1885 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
1887 send_ipp_status(con
, IPP_CHARSET
,
1888 _("Language \"%s\" not supported!"),
1889 attr
->values
[0].string
.text
);
1892 else if (!strcmp(attr
->name
, "notify-user-data") &&
1893 attr
->value_tag
== IPP_TAG_STRING
)
1895 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
1897 send_ipp_status(con
, IPP_REQUEST_VALUE
,
1898 _("The notify-user-data value is too large "
1899 "(%d > 63 octets)!"),
1900 attr
->values
[0].unknown
.length
);
1906 else if (!strcmp(attr
->name
, "notify-events") &&
1907 attr
->value_tag
== IPP_TAG_KEYWORD
)
1909 for (i
= 0; i
< attr
->num_values
; i
++)
1910 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
1912 else if (!strcmp(attr
->name
, "notify-lease-duration"))
1914 send_ipp_status(con
, IPP_BAD_REQUEST
,
1915 _("The notify-lease-duration attribute cannot be "
1916 "used with job subscriptions."));
1919 else if (!strcmp(attr
->name
, "notify-time-interval") &&
1920 attr
->value_tag
== IPP_TAG_INTEGER
)
1921 interval
= attr
->values
[0].integer
;
1926 if (!recipient
&& !pullmethod
)
1929 if (mask
== CUPSD_EVENT_NONE
)
1930 mask
= CUPSD_EVENT_JOB_COMPLETED
;
1932 sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
, recipient
,
1935 sub
->interval
= interval
;
1937 cupsdSetString(&sub
->owner
, job
->username
);
1941 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
1942 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
1943 sub
->user_data_len
);
1946 ippAddSeparator(con
->response
);
1947 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
1948 "notify-subscription-id", sub
->id
);
1954 cupsdSaveAllSubscriptions();
1957 * Remove all of the subscription attributes from the job request...
1960 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
1964 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
1965 attr
->group_tag
== IPP_TAG_ZERO
)
1968 * Free and remove this attribute...
1976 job
->attrs
->attrs
= next
;
1982 job
->attrs
->last
= prev
;
1983 job
->attrs
->current
= prev
;
1988 * 'add_job_uuid()' - Add job-uuid attribute to a job.
1990 * See RFC 4122 for the definition of UUIDs and the format.
1994 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
1995 cupsd_job_t
*job
) /* I - Job */
1997 char uuid
[1024]; /* job-uuid string */
1998 _cups_md5_state_t md5state
; /* MD5 state */
1999 unsigned char md5sum
[16]; /* MD5 digest/sum */
2003 * First see if the job already has a job-uuid attribute; if so, return...
2006 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
2010 * No job-uuid attribute, so build a version 3 UUID with the local job
2011 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
2012 * the ServerName, server name and port that the client connected to,
2013 * and local job ID...
2016 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
2017 con
->serverport
, job
->id
);
2019 _cupsMD5Init(&md5state
);
2020 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
2021 _cupsMD5Finish(&md5state
, md5sum
);
2024 * Format the UUID URI using the MD5 sum and job ID.
2027 snprintf(uuid
, sizeof(uuid
),
2028 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2029 "%02x%02x%02x%02x%02x%02x",
2030 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2031 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2032 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2033 md5sum
[14], md5sum
[15]);
2035 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2040 * 'add_printer()' - Add a printer to the system.
2044 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2045 ipp_attribute_t
*uri
) /* I - URI of printer */
2047 http_status_t status
; /* Policy status */
2048 int i
; /* Looping var */
2049 char method
[HTTP_MAX_URI
], /* Method portion of URI */
2050 username
[HTTP_MAX_URI
], /* Username portion of URI */
2051 host
[HTTP_MAX_URI
], /* Host portion of URI */
2052 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2053 int port
; /* Port portion of URI */
2054 cupsd_printer_t
*printer
; /* Printer/class */
2055 ipp_attribute_t
*attr
; /* Printer attribute */
2056 cups_file_t
*fp
; /* Script/PPD file */
2057 char line
[1024]; /* Line from file... */
2058 char srcfile
[1024], /* Source Script/PPD file */
2059 dstfile
[1024]; /* Destination Script/PPD file */
2060 int modify
; /* Non-zero if we are modifying */
2061 char newname
[IPP_MAX_NAME
]; /* New printer name */
2062 int need_restart_job
; /* Need to restart job? */
2065 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2066 con
->http
.fd
, uri
->values
[0].string
.text
);
2069 * Do we have a valid URI?
2072 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2073 sizeof(method
), username
, sizeof(username
), host
,
2074 sizeof(host
), &port
, resource
, sizeof(resource
));
2076 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2079 * No, return an error...
2082 send_ipp_status(con
, IPP_BAD_REQUEST
,
2083 _("The printer-uri must be of the form "
2084 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2089 * Do we have a valid printer name?
2092 if (!validate_name(resource
+ 10))
2095 * No, return an error...
2098 send_ipp_status(con
, IPP_BAD_REQUEST
,
2099 _("The printer-uri \"%s\" contains invalid characters."),
2100 uri
->values
[0].string
.text
);
2108 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2110 send_http_error(con
, status
, NULL
);
2115 * See if the printer already exists; if not, create a new printer...
2118 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2121 * Printer doesn't exist; see if we have a class of the same name...
2124 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2125 !(printer
->type
& CUPS_PRINTER_REMOTE
))
2128 * Yes, return an error...
2131 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2132 _("A class named \"%s\" already exists!"),
2138 * No, add the printer...
2141 printer
= cupsdAddPrinter(resource
+ 10);
2144 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2147 * Rename the implicit printer to "AnyPrinter" or delete it...
2150 if (ImplicitAnyClasses
)
2152 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2153 cupsdRenamePrinter(printer
, newname
);
2156 cupsdDeletePrinter(printer
, 1);
2159 * Add the printer as a new local printer...
2162 printer
= cupsdAddPrinter(resource
+ 10);
2165 else if (printer
->type
& CUPS_PRINTER_REMOTE
)
2168 * Rename the remote printer to "Printer@server"...
2171 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2173 cupsdRenamePrinter(printer
, newname
);
2176 * Add the printer as a new local printer...
2179 printer
= cupsdAddPrinter(resource
+ 10);
2186 * Look for attributes and copy them over as needed...
2189 need_restart_job
= 0;
2191 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2192 IPP_TAG_TEXT
)) != NULL
)
2193 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2195 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2196 IPP_TAG_TEXT
)) != NULL
)
2197 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2199 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2200 IPP_TAG_URI
)) != NULL
)
2203 * Do we have a valid device URI?
2206 need_restart_job
= 1;
2208 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[0].string
.text
, method
,
2209 sizeof(method
), username
, sizeof(username
), host
,
2210 sizeof(host
), &port
, resource
, sizeof(resource
));
2212 if (!strcmp(method
, "file"))
2215 * See if the administrator has enabled file devices...
2218 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2221 * File devices are disabled and the URL is not file:/dev/null...
2224 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2225 _("File device URIs have been disabled! "
2226 "To enable, see the FileDevice directive in "
2227 "\"%s/cupsd.conf\"."),
2235 * See if the backend exists and is executable...
2238 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, method
);
2239 if (access(srcfile
, X_OK
))
2242 * Could not find device in list!
2245 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2246 attr
->values
[0].string
.text
);
2251 cupsdLogMessage(CUPSD_LOG_INFO
,
2252 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2254 cupsdSanitizeURI(attr
->values
[0].string
.text
, line
,
2256 cupsdSanitizeURI(printer
->device_uri
, resource
,
2259 cupsdSetString(&printer
->device_uri
, attr
->values
[0].string
.text
);
2262 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2263 IPP_TAG_KEYWORD
)) != NULL
)
2265 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2268 need_restart_job
= 1;
2270 supported
= ippFindAttribute(printer
->attrs
, "port-monitor-supported",
2272 for (i
= 0; i
< supported
->num_values
; i
++)
2273 if (!strcmp(supported
->values
[i
].string
.text
,
2274 attr
->values
[0].string
.text
))
2277 if (i
>= supported
->num_values
)
2279 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2280 attr
->values
[0].string
.text
);
2284 cupsdLogMessage(CUPSD_LOG_INFO
,
2285 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2286 printer
->name
, attr
->values
[0].string
.text
,
2287 printer
->port_monitor
);
2289 if (strcmp(attr
->values
[0].string
.text
, "none"))
2290 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2292 cupsdClearString(&printer
->port_monitor
);
2295 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2296 IPP_TAG_BOOLEAN
)) != NULL
)
2298 cupsdLogMessage(CUPSD_LOG_INFO
,
2299 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2300 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2302 printer
->accepting
= attr
->values
[0].boolean
;
2303 cupsdAddPrinterHistory(printer
);
2306 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2307 IPP_TAG_BOOLEAN
)) != NULL
)
2309 if (printer
->shared
&& !attr
->values
[0].boolean
)
2310 cupsdDeregisterPrinter(printer
, 1);
2312 cupsdLogMessage(CUPSD_LOG_INFO
,
2313 "Setting %s printer-is-shared to %d (was %d.)",
2314 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2316 printer
->shared
= attr
->values
[0].boolean
;
2319 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2320 IPP_TAG_ENUM
)) != NULL
)
2322 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2323 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2325 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2326 attr
->values
[0].integer
);
2330 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)", printer
->name
,
2331 attr
->values
[0].integer
, printer
->state
);
2333 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2334 cupsdStopPrinter(printer
, 0);
2337 need_restart_job
= 1;
2338 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2341 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2342 IPP_TAG_TEXT
)) != NULL
)
2344 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2345 sizeof(printer
->state_message
));
2346 cupsdAddPrinterHistory(printer
);
2349 set_printer_defaults(con
, printer
);
2352 * See if we have all required attributes...
2355 if (!printer
->device_uri
)
2356 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2359 * See if we have an interface script or PPD file attached to the request...
2364 need_restart_job
= 1;
2366 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2368 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2371 * Yes; get the first line from it...
2375 cupsFileGets(fp
, line
, sizeof(line
));
2379 * Then see what kind of file it is...
2382 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2385 if (!strncmp(line
, "*PPD-Adobe", 10))
2388 * The new file is a PPD file, so remove any old interface script
2389 * that might be lying around...
2397 * This must be an interface script, so move the file over to the
2398 * interfaces directory and make it executable...
2401 if (copy_file(srcfile
, dstfile
))
2403 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2404 _("Unable to copy interface script - %s!"),
2410 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2411 "Copied interface script successfully!");
2412 chmod(dstfile
, 0755);
2416 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2419 if (!strncmp(line
, "*PPD-Adobe", 10))
2422 * The new file is a PPD file, so move the file over to the
2423 * ppd directory and make it readable by all...
2426 if (copy_file(srcfile
, dstfile
))
2428 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2429 _("Unable to copy PPD file - %s!"),
2435 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2436 "Copied PPD file successfully!");
2437 chmod(dstfile
, 0644);
2443 * This must be an interface script, so remove any old PPD file that
2444 * may be lying around...
2451 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2452 IPP_TAG_NAME
)) != NULL
)
2454 need_restart_job
= 1;
2456 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2459 * Raw driver, remove any existing PPD or interface script files.
2462 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2466 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2476 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2480 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2483 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2485 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2490 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2491 "Copied PPD file successfully!");
2492 chmod(dstfile
, 0644);
2498 * Update the printer attributes and return...
2501 cupsdSetPrinterAttrs(printer
);
2502 cupsdSaveAllPrinters();
2504 if (need_restart_job
&& printer
->job
)
2509 * Stop the current job and then restart it below...
2512 job
= (cupsd_job_t
*)printer
->job
;
2514 cupsdStopJob(job
, 1);
2516 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2517 job
->state_value
= IPP_JOB_PENDING
;
2520 if (need_restart_job
)
2523 cupsdWritePrintcap();
2527 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2528 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2531 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2532 printer
->name
, get_username(con
));
2536 cupsdAddPrinterHistory(printer
);
2538 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2539 "New printer \"%s\" added by \"%s\".", printer
->name
,
2542 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2543 printer
->name
, get_username(con
));
2546 con
->response
->request
.status
.status_code
= IPP_OK
;
2551 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2552 * based upon the printer state...
2556 add_printer_state_reasons(
2557 cupsd_client_t
*con
, /* I - Client connection */
2558 cupsd_printer_t
*p
) /* I - Printer info */
2560 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2561 "add_printer_state_reasons(%p[%d], %p[%s])",
2562 con
, con
->http
.fd
, p
, p
->name
);
2564 if (p
->num_reasons
== 0)
2565 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2566 "printer-state-reasons", NULL
,
2567 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2569 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2570 "printer-state-reasons", p
->num_reasons
, NULL
,
2571 (const char * const *)p
->reasons
);
2576 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2577 * the specified printer or class.
2581 add_queued_job_count(
2582 cupsd_client_t
*con
, /* I - Client connection */
2583 cupsd_printer_t
*p
) /* I - Printer or class */
2585 int count
; /* Number of jobs on destination */
2588 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2589 con
, con
->http
.fd
, p
, p
->name
);
2591 count
= cupsdGetPrinterJobCount(p
->name
);
2593 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2594 "queued-job-count", count
);
2599 * 'apply_printer_defaults()' - Apply printer default options to a job.
2603 apply_printer_defaults(
2604 cupsd_printer_t
*printer
, /* I - Printer */
2605 cupsd_job_t
*job
) /* I - Job */
2607 int i
, /* Looping var */
2608 num_options
; /* Number of default options */
2609 cups_option_t
*options
, /* Default options */
2610 *option
; /* Current option */
2614 * Collect all of the default options and add the missing ones to the
2618 for (i
= printer
->num_options
, num_options
= 0, option
= printer
->options
;
2621 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2623 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2628 * Encode these options as attributes in the job object...
2631 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2632 cupsFreeOptions(num_options
, options
);
2637 * 'authenticate_job()' - Set job authentication info.
2641 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2642 ipp_attribute_t
*uri
) /* I - Job URI */
2644 ipp_attribute_t
*attr
, /* job-id attribute */
2645 *auth_info
; /* auth-info attribute */
2646 int jobid
; /* Job ID */
2647 cupsd_job_t
*job
; /* Current job */
2648 char method
[HTTP_MAX_URI
],
2649 /* Method portion of URI */
2650 username
[HTTP_MAX_URI
],
2651 /* Username portion of URI */
2653 /* Host portion of URI */
2654 resource
[HTTP_MAX_URI
];
2655 /* Resource portion of URI */
2656 int port
; /* Port portion of URI */
2659 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2660 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
2663 * Start with "everything is OK" status...
2666 con
->response
->request
.status
.status_code
= IPP_OK
;
2669 * See if we have a job URI or a printer URI...
2672 if (!strcmp(uri
->name
, "printer-uri"))
2675 * Got a printer URI; see if we also have a job-id attribute...
2678 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2679 IPP_TAG_INTEGER
)) == NULL
)
2681 send_ipp_status(con
, IPP_BAD_REQUEST
,
2682 _("Got a printer-uri attribute but no job-id!"));
2686 jobid
= attr
->values
[0].integer
;
2691 * Got a job URI; parse it to get the job ID...
2694 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2695 sizeof(method
), username
, sizeof(username
), host
,
2696 sizeof(host
), &port
, resource
, sizeof(resource
));
2698 if (strncmp(resource
, "/jobs/", 6))
2704 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
2705 uri
->values
[0].string
.text
);
2709 jobid
= atoi(resource
+ 6);
2713 * See if the job exists...
2716 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2719 * Nope - return a "not found" error...
2722 send_ipp_status(con
, IPP_NOT_FOUND
,
2723 _("Job #%d does not exist!"), jobid
);
2728 * See if the job has been completed...
2731 if (job
->state_value
!= IPP_JOB_HELD
)
2734 * Return a "not-possible" error...
2737 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2738 _("Job #%d is not held for authentication!"),
2744 * See if we have already authenticated...
2747 auth_info
= ippFindAttribute(con
->request
, "auth-info", IPP_TAG_TEXT
);
2749 if (!con
->username
[0] && !auth_info
)
2751 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
2752 _("No authentication information provided!"));
2757 * See if the job is owned by the requesting user...
2760 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
2762 send_http_error(con
, HTTP_UNAUTHORIZED
, NULL
);
2767 * Save the authentication information for this job...
2770 save_auth_info(con
, job
, auth_info
);
2773 * Reset the job-hold-until value to "no-hold"...
2776 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
2777 IPP_TAG_KEYWORD
)) == NULL
)
2778 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
2782 attr
->value_tag
= IPP_TAG_KEYWORD
;
2783 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
2787 * Release the job and return...
2790 cupsdReleaseJob(job
);
2792 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was authenticated by \"%s\".", jobid
,
2798 * 'cancel_all_jobs()' - Cancel all print jobs.
2802 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
2803 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
2805 http_status_t status
; /* Policy status */
2806 cups_ptype_t dtype
; /* Destination type */
2807 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2808 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2809 hostname
[HTTP_MAX_URI
], /* Host portion of URI */
2810 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2811 int port
; /* Port portion of URI */
2812 ipp_attribute_t
*attr
; /* Attribute in request */
2813 const char *username
; /* Username */
2814 int purge
; /* Purge? */
2815 cupsd_printer_t
*printer
; /* Printer */
2818 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
2819 con
->http
.fd
, uri
->values
[0].string
.text
);
2822 * See if we have a printer URI...
2825 if (strcmp(uri
->name
, "printer-uri"))
2827 send_ipp_status(con
, IPP_BAD_REQUEST
,
2828 _("The printer-uri attribute is required!"));
2833 * Get the username (if any) for the jobs we want to cancel (only if
2834 * "my-jobs" is specified...
2837 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
2838 IPP_TAG_BOOLEAN
)) != NULL
&&
2839 attr
->values
[0].boolean
)
2841 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
2842 IPP_TAG_NAME
)) != NULL
)
2843 username
= attr
->values
[0].string
.text
;
2846 send_ipp_status(con
, IPP_BAD_REQUEST
,
2847 _("Missing requesting-user-name attribute!"));
2855 * Look for the "purge-jobs" attribute...
2858 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
2859 IPP_TAG_BOOLEAN
)) != NULL
)
2860 purge
= attr
->values
[0].boolean
;
2865 * And if the destination is valid...
2868 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
2874 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
,
2875 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
2876 hostname
, sizeof(hostname
), &port
,
2877 resource
, sizeof(resource
));
2879 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
2880 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
2882 send_ipp_status(con
, IPP_NOT_FOUND
,
2883 _("The printer or class was not found."));
2891 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2893 send_http_error(con
, status
, NULL
);
2898 * Cancel all jobs on all printers...
2901 cupsdCancelJobs(NULL
, username
, purge
);
2903 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
2904 purge
? "purged" : "canceled", get_username(con
));
2912 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
2915 send_http_error(con
, status
, printer
);
2920 * Cancel all of the jobs on the named printer...
2923 cupsdCancelJobs(printer
->name
, username
, purge
);
2925 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
2926 printer
->name
, purge
? "purged" : "canceled",
2930 con
->response
->request
.status
.status_code
= IPP_OK
;
2935 * 'cancel_job()' - Cancel a print job.
2939 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
2940 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
2942 ipp_attribute_t
*attr
; /* Current attribute */
2943 int jobid
; /* Job ID */
2944 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
2945 username
[HTTP_MAX_URI
], /* Username portion of URI */
2946 host
[HTTP_MAX_URI
], /* Host portion of URI */
2947 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2948 int port
; /* Port portion of URI */
2949 cupsd_job_t
*job
; /* Job information */
2950 cups_ptype_t dtype
; /* Destination type (printer or class) */
2951 cupsd_printer_t
*printer
; /* Printer data */
2954 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
2955 con
->http
.fd
, uri
->values
[0].string
.text
);
2958 * See if we have a job URI or a printer URI...
2961 if (!strcmp(uri
->name
, "printer-uri"))
2964 * Got a printer URI; see if we also have a job-id attribute...
2967 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2968 IPP_TAG_INTEGER
)) == NULL
)
2970 send_ipp_status(con
, IPP_BAD_REQUEST
,
2971 _("Got a printer-uri attribute but no job-id!"));
2975 if ((jobid
= attr
->values
[0].integer
) == 0)
2978 * Find the current job on the specified printer...
2981 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
2987 send_ipp_status(con
, IPP_NOT_FOUND
,
2988 _("The printer or class was not found."));
2993 * See if the printer is currently printing a job...
2997 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
3001 * No, see if there are any pending jobs...
3004 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
3006 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
3007 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
3008 !strcasecmp(job
->dest
, printer
->name
))
3015 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
3025 * Got a job URI; parse it to get the job ID...
3028 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
3029 sizeof(scheme
), username
, sizeof(username
), host
,
3030 sizeof(host
), &port
, resource
, sizeof(resource
));
3032 if (strncmp(resource
, "/jobs/", 6))
3038 send_ipp_status(con
, IPP_BAD_REQUEST
,
3039 _("Bad job-uri attribute \"%s\"!"),
3040 uri
->values
[0].string
.text
);
3044 jobid
= atoi(resource
+ 6);
3048 * See if the job exists...
3051 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3054 * Nope - return a "not found" error...
3057 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
3062 * See if the job is owned by the requesting user...
3065 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3067 send_http_error(con
, HTTP_UNAUTHORIZED
, NULL
);
3072 * See if the job is already completed, canceled, or aborted; if so,
3073 * we can't cancel...
3076 if (job
->state_value
>= IPP_JOB_CANCELED
)
3078 switch (job
->state_value
)
3080 case IPP_JOB_CANCELED
:
3081 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3082 _("Job #%d is already canceled - can\'t cancel."),
3086 case IPP_JOB_ABORTED
:
3087 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3088 _("Job #%d is already aborted - can\'t cancel."),
3093 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3094 _("Job #%d is already completed - can\'t cancel."),
3103 * Cancel the job and return...
3106 cupsdCancelJob(job
, 0, IPP_JOB_CANCELED
);
3109 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was canceled by \"%s\".", jobid
,
3112 con
->response
->request
.status
.status_code
= IPP_OK
;
3117 * 'cancel_subscription()' - Cancel a subscription.
3121 cancel_subscription(
3122 cupsd_client_t
*con
, /* I - Client connection */
3123 int sub_id
) /* I - Subscription ID */
3125 http_status_t status
; /* Policy status */
3126 cupsd_subscription_t
*sub
; /* Subscription */
3129 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3130 "cancel_subscription(con=%p[%d], sub_id=%d)",
3131 con
, con
->http
.fd
, sub_id
);
3134 * Is the subscription ID valid?
3137 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3140 * Bad subscription ID...
3143 send_ipp_status(con
, IPP_NOT_FOUND
,
3144 _("notify-subscription-id %d no good!"), sub_id
);
3152 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3154 con
, sub
->owner
)) != HTTP_OK
)
3156 send_http_error(con
, status
, sub
->dest
);
3161 * Cancel the subscription...
3164 cupsdDeleteSubscription(sub
, 1);
3166 con
->response
->request
.status
.status_code
= IPP_OK
;
3171 * 'check_quotas()' - Check quotas for a printer and user.
3174 static int /* O - 1 if OK, 0 if not */
3175 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3176 cupsd_printer_t
*p
) /* I - Printer or class */
3178 int i
; /* Looping var */
3179 char username
[33]; /* Username */
3180 cupsd_quota_t
*q
; /* Quota data */
3181 #ifdef HAVE_MBR_UID_TO_UUID
3183 * Use Apple membership APIs which require that all names represent
3184 * valid user account or group records accessible by the server.
3187 uuid_t usr_uuid
; /* UUID for job requesting user */
3188 uuid_t usr2_uuid
; /* UUID for ACL user name entry */
3189 uuid_t grp_uuid
; /* UUID for ACL group name entry */
3190 int mbr_err
; /* Error from membership function */
3191 int is_member
; /* Is this user a member? */
3194 * Use standard POSIX APIs for checking users and groups...
3197 struct passwd
*pw
; /* User password data */
3198 #endif /* HAVE_MBR_UID_TO_UUID */
3201 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3202 con
, con
->http
.fd
, p
, p
->name
);
3212 * Figure out who is printing...
3215 strlcpy(username
, get_username(con
), sizeof(username
));
3218 * Check global active job limits for printers and users...
3221 if (MaxJobsPerPrinter
)
3224 * Check if there are too many pending jobs on this printer...
3227 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3229 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3238 * Check if there are too many pending jobs for this user...
3241 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3243 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3250 * Check against users...
3253 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3258 #ifdef HAVE_MBR_UID_TO_UUID
3260 * Get UUID for job requesting user...
3263 if (mbr_user_name_to_uuid((char *)username
, usr_uuid
))
3269 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3270 "check_quotas: UUID lookup failed for user \"%s\"",
3272 cupsdLogMessage(CUPSD_LOG_INFO
,
3273 "Denying user \"%s\" access to printer \"%s\" "
3274 "(unknown user)...",
3280 * Get UID and GID of requesting user...
3283 pw
= getpwnam(username
);
3285 #endif /* HAVE_MBR_UID_TO_UUID */
3287 for (i
= 0; i
< p
->num_users
; i
++)
3288 if (p
->users
[i
][0] == '@')
3291 * Check group membership...
3294 #ifdef HAVE_MBR_UID_TO_UUID
3295 if ((mbr_err
= mbr_group_name_to_uuid((char *)p
->users
[i
] + 1,
3299 * Invalid ACL entries are ignored for matching; just record a
3300 * warning in the log...
3303 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3304 "check_quotas: UUID lookup failed for ACL entry "
3305 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
3306 cupsdLogMessage(CUPSD_LOG_WARN
,
3307 "Access control entry \"%s\" not a valid group name; "
3308 "entry ignored", p
->users
[i
]);
3312 if ((mbr_err
= mbr_check_membership(usr_uuid
, grp_uuid
,
3316 * At this point, there should be no errors, but check anyways...
3319 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3320 "check_quotas: group \"%s\" membership check "
3321 "failed (err=%d)", p
->users
[i
] + 1, mbr_err
);
3326 * Stop if we found a match...
3333 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
3335 #endif /* HAVE_MBR_UID_TO_UUID */
3337 #ifdef HAVE_MBR_UID_TO_UUID
3340 if ((mbr_err
= mbr_user_name_to_uuid((char *)p
->users
[i
],
3344 * Invalid ACL entries are ignored for matching; just record a
3345 * warning in the log...
3348 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3349 "check_quotas: UUID lookup failed for ACL entry "
3350 "\"%s\" (err=%d)", p
->users
[i
], mbr_err
);
3351 cupsdLogMessage(CUPSD_LOG_WARN
,
3352 "Access control entry \"%s\" not a valid user name; "
3353 "entry ignored", p
->users
[i
]);
3357 if ((mbr_err
= mbr_check_membership(usr_uuid
, usr2_uuid
,
3360 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3361 "check_quotas: User \"%s\" identity check failed "
3362 "(err=%d)", p
->users
[i
], mbr_err
);
3371 else if (!strcasecmp(username
, p
->users
[i
]))
3373 #endif /* HAVE_MBR_UID_TO_UUID */
3375 if ((i
< p
->num_users
) == p
->deny_users
)
3377 cupsdLogMessage(CUPSD_LOG_INFO
,
3378 "Denying user \"%s\" access to printer \"%s\"...",
3392 * TODO: Define these special page count values as constants!
3395 if (q
->page_count
== -4) /* special case: unlimited user */
3397 cupsdLogMessage(CUPSD_LOG_INFO
,
3398 "User \"%s\" request approved for printer %s (%s): "
3400 username
, p
->name
, p
->info
);
3401 q
->page_count
= 0; /* allow user to print */
3404 else if (q
->page_count
== -3) /* quota exceeded */
3406 cupsdLogMessage(CUPSD_LOG_INFO
,
3407 "User \"%s\" request denied for printer %s (%s): "
3408 "quota limit exceeded.",
3409 username
, p
->name
, p
->info
);
3410 q
->page_count
= 2; /* force quota exceeded failure */
3413 else if (q
->page_count
== -2) /* quota disabled for user */
3415 cupsdLogMessage(CUPSD_LOG_INFO
,
3416 "User \"%s\" request denied for printer %s (%s): "
3417 "printing disabled for user.",
3418 username
, p
->name
, p
->info
);
3419 q
->page_count
= 2; /* force quota exceeded failure */
3422 else if (q
->page_count
== -1) /* quota access error */
3424 cupsdLogMessage(CUPSD_LOG_INFO
,
3425 "User \"%s\" request denied for printer %s (%s): "
3426 "unable to determine quota limit.",
3427 username
, p
->name
, p
->info
);
3428 q
->page_count
= 2; /* force quota exceeded failure */
3431 else if (q
->page_count
< 0) /* user not found or other error */
3433 cupsdLogMessage(CUPSD_LOG_INFO
,
3434 "User \"%s\" request denied for printer %s (%s): "
3435 "user disabled / missing quota.",
3436 username
, p
->name
, p
->info
);
3437 q
->page_count
= 2; /* force quota exceeded failure */
3440 else /* page within user limits */
3442 q
->page_count
= 0; /* allow user to print */
3447 #endif /* __APPLE__ */
3448 if (p
->k_limit
|| p
->page_limit
)
3450 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3452 cupsdLogMessage(CUPSD_LOG_ERROR
,
3453 "Unable to allocate quota data for user \"%s\"!",
3458 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3459 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3461 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3468 * If we have gotten this far, we're done!
3476 * 'copy_attribute()' - Copy a single attribute.
3479 static ipp_attribute_t
* /* O - New attribute */
3481 ipp_t
*to
, /* O - Destination request/response */
3482 ipp_attribute_t
*attr
, /* I - Attribute to copy */
3483 int quickcopy
) /* I - Do a quick copy? */
3485 int i
; /* Looping var */
3486 ipp_attribute_t
*toattr
; /* Destination attribute */
3489 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3490 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
3491 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
3494 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
3497 toattr
= ippAddSeparator(to
);
3500 case IPP_TAG_INTEGER
:
3502 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
3503 attr
->name
, attr
->num_values
, NULL
);
3505 for (i
= 0; i
< attr
->num_values
; i
++)
3506 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
3509 case IPP_TAG_BOOLEAN
:
3510 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
3511 attr
->num_values
, NULL
);
3513 for (i
= 0; i
< attr
->num_values
; i
++)
3514 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
3517 case IPP_TAG_STRING
:
3520 case IPP_TAG_KEYWORD
:
3522 case IPP_TAG_URISCHEME
:
3523 case IPP_TAG_CHARSET
:
3524 case IPP_TAG_LANGUAGE
:
3525 case IPP_TAG_MIMETYPE
:
3526 toattr
= ippAddStrings(to
, attr
->group_tag
,
3527 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
3528 attr
->name
, attr
->num_values
, NULL
, NULL
);
3532 for (i
= 0; i
< attr
->num_values
; i
++)
3533 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
3537 for (i
= 0; i
< attr
->num_values
; i
++)
3538 toattr
->values
[i
].string
.text
= _cupsStrAlloc(attr
->values
[i
].string
.text
);
3543 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
3544 attr
->values
[0].date
);
3547 case IPP_TAG_RESOLUTION
:
3548 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
3549 attr
->num_values
, IPP_RES_PER_INCH
,
3552 for (i
= 0; i
< attr
->num_values
; i
++)
3554 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
3555 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
3556 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
3560 case IPP_TAG_RANGE
:
3561 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
3562 attr
->num_values
, NULL
, NULL
);
3564 for (i
= 0; i
< attr
->num_values
; i
++)
3566 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
3567 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
3571 case IPP_TAG_TEXTLANG
:
3572 case IPP_TAG_NAMELANG
:
3573 toattr
= ippAddStrings(to
, attr
->group_tag
,
3574 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
3575 attr
->name
, attr
->num_values
, NULL
, NULL
);
3579 for (i
= 0; i
< attr
->num_values
; i
++)
3581 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
3582 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
3587 for (i
= 0; i
< attr
->num_values
; i
++)
3590 toattr
->values
[i
].string
.charset
=
3591 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
3593 toattr
->values
[i
].string
.charset
=
3594 toattr
->values
[0].string
.charset
;
3596 toattr
->values
[i
].string
.text
= _cupsStrAlloc(attr
->values
[i
].string
.text
);
3601 case IPP_TAG_BEGIN_COLLECTION
:
3602 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
3603 attr
->num_values
, NULL
);
3605 for (i
= 0; i
< attr
->num_values
; i
++)
3607 toattr
->values
[i
].collection
= ippNew();
3608 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
3609 NULL
, IPP_TAG_ZERO
, 0);
3614 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
3615 attr
->name
, attr
->num_values
, NULL
);
3617 for (i
= 0; i
< attr
->num_values
; i
++)
3619 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
3621 if (toattr
->values
[i
].unknown
.length
> 0)
3623 if ((toattr
->values
[i
].unknown
.data
=
3624 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
3625 toattr
->values
[i
].unknown
.length
= 0;
3627 memcpy(toattr
->values
[i
].unknown
.data
,
3628 attr
->values
[i
].unknown
.data
,
3629 toattr
->values
[i
].unknown
.length
);
3632 break; /* anti-compiler-warning-code */
3640 * 'copy_attrs()' - Copy attributes from one request to another.
3644 copy_attrs(ipp_t
*to
, /* I - Destination request */
3645 ipp_t
*from
, /* I - Source request */
3646 cups_array_t
*ra
, /* I - Requested attributes */
3647 ipp_tag_t group
, /* I - Group to copy */
3648 int quickcopy
) /* I - Do a quick copy? */
3650 ipp_attribute_t
*fromattr
; /* Source attribute */
3653 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3654 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
3655 to
, from
, ra
, group
, quickcopy
);
3660 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
3663 * Filter attributes as needed...
3666 if ((group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
3667 fromattr
->group_tag
!= IPP_TAG_ZERO
) || !fromattr
->name
)
3670 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
3671 copy_attribute(to
, fromattr
, quickcopy
);
3677 * 'copy_banner()' - Copy a banner file to the requests directory for the
3681 static int /* O - Size of banner file in kbytes */
3682 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
3683 cupsd_job_t
*job
, /* I - Job information */
3684 const char *name
) /* I - Name of banner */
3686 int i
; /* Looping var */
3687 int kbytes
; /* Size of banner file in kbytes */
3688 char filename
[1024]; /* Job filename */
3689 cupsd_banner_t
*banner
; /* Pointer to banner */
3690 cups_file_t
*in
; /* Input file */
3691 cups_file_t
*out
; /* Output file */
3692 int ch
; /* Character from file */
3693 char attrname
[255], /* Name of attribute */
3694 *s
; /* Pointer into name */
3695 ipp_attribute_t
*attr
; /* Attribute */
3698 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_banner(%p[%d], %p[%d], %s)",
3699 con
, con
->http
.fd
, job
, job
->id
, name
? name
: "(null)");
3702 * Find the banner; return if not found or "none"...
3705 if (!name
|| !strcmp(name
, "none") ||
3706 (banner
= cupsdFindBanner(name
)) == NULL
)
3710 * Open the banner and job files...
3713 if (add_file(con
, job
, banner
->filetype
, 0))
3716 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
3718 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
3720 cupsdLogMessage(CUPSD_LOG_ERROR
,
3721 "copy_banner: Unable to create banner job file %s - %s",
3722 filename
, strerror(errno
));
3727 fchmod(cupsFileNumber(out
), 0640);
3728 fchown(cupsFileNumber(out
), RunUser
, Group
);
3731 * Try the localized banner file under the subdirectory...
3734 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
3736 if (strlen(attrname
) > 2 && attrname
[2] == '-')
3739 * Convert ll-cc to ll_CC...
3743 attrname
[3] = toupper(attrname
[3] & 255);
3744 attrname
[4] = toupper(attrname
[4] & 255);
3747 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
3750 if (access(filename
, 0) && strlen(attrname
) > 2)
3753 * Wasn't able to find "ll_CC" locale file; try the non-national
3754 * localization banner directory.
3759 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
3763 if (access(filename
, 0))
3766 * Use the non-localized banner file.
3769 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
3772 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
3776 cupsdLogMessage(CUPSD_LOG_ERROR
,
3777 "copy_banner: Unable to open banner template file %s - %s",
3778 filename
, strerror(errno
));
3784 * Parse the file to the end...
3787 while ((ch
= cupsFileGetChar(in
)) != EOF
)
3791 * Get an attribute name...
3794 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
3795 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
3797 else if (s
< (attrname
+ sizeof(attrname
) - 1))
3807 * Ignore { followed by stuff that is not an attribute name...
3810 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
3815 * See if it is defined...
3818 if (attrname
[0] == '?')
3823 if (!strcmp(s
, "printer-name"))
3825 cupsFilePuts(out
, job
->dest
);
3828 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
3831 * See if we have a leading question mark...
3834 if (attrname
[0] != '?')
3837 * Nope, write to file as-is; probably a PostScript procedure...
3840 cupsFilePrintf(out
, "{%s}", attrname
);
3847 * Output value(s)...
3850 for (i
= 0; i
< attr
->num_values
; i
++)
3853 cupsFilePutChar(out
, ',');
3855 switch (attr
->value_tag
)
3857 case IPP_TAG_INTEGER
:
3859 if (!strncmp(s
, "time-at-", 8))
3860 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
3862 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
3865 case IPP_TAG_BOOLEAN
:
3866 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
3869 case IPP_TAG_NOVALUE
:
3870 cupsFilePuts(out
, "novalue");
3873 case IPP_TAG_RANGE
:
3874 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
3875 attr
->values
[i
].range
.upper
);
3878 case IPP_TAG_RESOLUTION
:
3879 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
3880 attr
->values
[i
].resolution
.yres
,
3881 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
3886 case IPP_TAG_STRING
:
3889 case IPP_TAG_KEYWORD
:
3890 case IPP_TAG_CHARSET
:
3891 case IPP_TAG_LANGUAGE
:
3892 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
3895 * Need to quote strings for PS banners...
3900 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
3902 if (*p
== '(' || *p
== ')' || *p
== '\\')
3904 cupsFilePutChar(out
, '\\');
3905 cupsFilePutChar(out
, *p
);
3907 else if (*p
< 32 || *p
> 126)
3908 cupsFilePrintf(out
, "\\%03o", *p
& 255);
3910 cupsFilePutChar(out
, *p
);
3914 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
3918 break; /* anti-compiler-warning-code */
3922 else if (ch
== '\\') /* Quoted char */
3924 ch
= cupsFileGetChar(in
);
3926 if (ch
!= '{') /* Only do special handling for \{ */
3927 cupsFilePutChar(out
, '\\');
3929 cupsFilePutChar(out
, ch
);
3932 cupsFilePutChar(out
, ch
);
3936 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
3938 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
3939 IPP_TAG_INTEGER
)) != NULL
)
3940 attr
->values
[0].integer
+= kbytes
;
3949 * 'copy_file()' - Copy a PPD file or interface script...
3952 static int /* O - 0 = success, -1 = error */
3953 copy_file(const char *from
, /* I - Source file */
3954 const char *to
) /* I - Destination file */
3956 cups_file_t
*src
, /* Source file */
3957 *dst
; /* Destination file */
3958 int bytes
; /* Bytes to read/write */
3959 char buffer
[2048]; /* Copy buffer */
3962 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
3965 * Open the source and destination file for a copy...
3968 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
3971 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
3978 * Copy the source file to the destination...
3981 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
3982 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
3990 * Close both files and return...
3995 return (cupsFileClose(dst
));
4000 * 'copy_model()' - Copy a PPD model file, substituting default values
4004 static int /* O - 0 = success, -1 = error */
4005 copy_model(cupsd_client_t
*con
, /* I - Client connection */
4006 const char *from
, /* I - Source file */
4007 const char *to
) /* I - Destination file */
4009 fd_set input
; /* select() input set */
4010 struct timeval timeout
; /* select() timeout */
4011 int maxfd
; /* Maximum file descriptor for select() */
4012 char tempfile
[1024]; /* Temporary PPD file */
4013 int tempfd
; /* Temporary PPD file descriptor */
4014 int temppid
; /* Process ID of cups-driverd */
4015 int temppipe
[2]; /* Temporary pipes */
4016 char *argv
[4], /* Command-line arguments */
4017 *envp
[MAX_ENV
]; /* Environment */
4018 cups_file_t
*src
, /* Source file */
4019 *dst
; /* Destination file */
4020 ppd_file_t
*ppd
; /* PPD file */
4021 int bytes
, /* Bytes from pipe */
4022 total
; /* Total bytes from pipe */
4023 char buffer
[2048]; /* Copy buffer */
4024 int i
; /* Looping var */
4025 char option
[PPD_MAX_NAME
], /* Option name */
4026 choice
[PPD_MAX_NAME
]; /* Choice name */
4027 int num_defaults
; /* Number of default options */
4028 cups_option_t
*defaults
; /* Default options */
4029 char cups_protocol
[PPD_MAX_LINE
];
4030 /* cupsProtocol attribute */
4031 int have_letter
, /* Have Letter size */
4032 have_a4
; /* Have A4 size */
4033 #ifdef HAVE_LIBPAPER
4034 char *paper_result
; /* Paper size name from libpaper */
4035 char system_paper
[64]; /* Paper size name buffer */
4036 #endif /* HAVE_LIBPAPER */
4039 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
4040 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
4044 * Run cups-driverd to get the PPD file...
4047 argv
[0] = "cups-driverd";
4049 argv
[2] = (char *)from
;
4052 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
4054 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
4055 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
4056 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
4060 cupsdOpenPipe(temppipe
);
4062 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4063 "copy_model: Running \"cups-driverd cat %s\"...", from
);
4065 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
4066 -1, -1, 0, &temppid
))
4076 * Wait up to 30 seconds for the PPD file to be copied...
4081 if (temppipe
[0] > CGIPipes
[0])
4082 maxfd
= temppipe
[0] + 1;
4084 maxfd
= CGIPipes
[0] + 1;
4089 * See if we have data ready...
4095 FD_SET(temppipe
[0], &input
);
4096 FD_SET(CGIPipes
[0], &input
);
4098 timeout
.tv_sec
= 30;
4099 timeout
.tv_usec
= 0;
4101 if ((i
= select(maxfd
, &input
, NULL
, NULL
, &timeout
)) < 0)
4111 * We have timed out...
4117 if (FD_ISSET(temppipe
[0], &input
))
4120 * Read the PPD file from the pipe, and write it to the PPD file.
4123 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
4125 if (write(tempfd
, buffer
, bytes
) < bytes
)
4134 if (FD_ISSET(CGIPipes
[0], &input
))
4144 * No data from cups-deviced...
4147 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
4153 * Read the source file and see what page sizes are supported...
4156 if ((ppd
= ppdOpenFile(tempfile
)) == NULL
)
4162 have_letter
= ppdPageSize(ppd
, "Letter") != NULL
;
4163 have_a4
= ppdPageSize(ppd
, "A4") != NULL
;
4166 * Open the destination (if possible) and set the default options...
4171 cups_protocol
[0] = '\0';
4173 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4176 * Read all of the default lines from the old PPD...
4179 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4180 if (!strncmp(buffer
, "*Default", 8))
4183 * Add the default option...
4186 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4187 choice
, sizeof(choice
)))
4189 ppd_option_t
*ppdo
; /* PPD option */
4193 * Only add the default if the default hasn't already been
4194 * set and the choice exists in the new PPD...
4197 if (!cupsGetOption(option
, num_defaults
, defaults
) &&
4198 (ppdo
= ppdFindOption(ppd
, option
)) != NULL
&&
4199 ppdFindChoice(ppdo
, choice
))
4200 num_defaults
= cupsAddOption(option
, choice
, num_defaults
,
4204 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4205 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4209 #ifdef HAVE_LIBPAPER
4210 else if ((paper_result
= systempapername()) != NULL
)
4213 * Set the default media sizes from the systemwide default...
4216 strlcpy(system_paper
, paper_result
, sizeof(system_paper
));
4217 system_paper
[0] = toupper(system_paper
[0] & 255);
4219 if ((!strcmp(system_paper
, "Letter") && have_letter
) ||
4220 (!strcmp(system_paper
, "A4") && have_a4
))
4222 num_defaults
= cupsAddOption("PageSize", system_paper
,
4223 num_defaults
, &defaults
);
4224 num_defaults
= cupsAddOption("PageRegion", system_paper
,
4225 num_defaults
, &defaults
);
4226 num_defaults
= cupsAddOption("PaperDimension", system_paper
,
4227 num_defaults
, &defaults
);
4228 num_defaults
= cupsAddOption("ImageableArea", system_paper
,
4229 num_defaults
, &defaults
);
4232 #endif /* HAVE_LIBPAPER */
4236 * Add the default media sizes...
4238 * Note: These values are generally not valid for large-format devices
4239 * like plotters, however it is probably safe to say that those
4240 * users will configure the media size after initially adding
4241 * the device anyways...
4244 if (!DefaultLanguage
||
4245 !strcasecmp(DefaultLanguage
, "C") ||
4246 !strcasecmp(DefaultLanguage
, "POSIX") ||
4247 !strcasecmp(DefaultLanguage
, "en") ||
4248 !strncasecmp(DefaultLanguage
, "en.", 3) ||
4249 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
4250 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
4251 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
4254 * These are the only locales that will default to "letter" size...
4259 num_defaults
= cupsAddOption("PageSize", "Letter", num_defaults
,
4261 num_defaults
= cupsAddOption("PageRegion", "Letter", num_defaults
,
4263 num_defaults
= cupsAddOption("PaperDimension", "Letter", num_defaults
,
4265 num_defaults
= cupsAddOption("ImageableArea", "Letter", num_defaults
,
4272 * The rest default to "a4" size...
4275 num_defaults
= cupsAddOption("PageSize", "A4", num_defaults
,
4277 num_defaults
= cupsAddOption("PageRegion", "A4", num_defaults
,
4279 num_defaults
= cupsAddOption("PaperDimension", "A4", num_defaults
,
4281 num_defaults
= cupsAddOption("ImageableArea", "A4", num_defaults
,
4289 * Open the source file for a copy...
4292 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
4294 cupsFreeOptions(num_defaults
, defaults
);
4300 * Open the destination file for a copy...
4303 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4305 cupsFreeOptions(num_defaults
, defaults
);
4312 * Copy the source file to the destination...
4315 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4317 if (!strncmp(buffer
, "*Default", 8))
4320 * Check for an previous default option choice...
4323 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4324 choice
, sizeof(choice
)))
4326 const char *val
; /* Default option value */
4329 if ((val
= cupsGetOption(option
, num_defaults
, defaults
)) != NULL
)
4332 * Substitute the previous choice...
4335 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
, val
);
4340 cupsFilePrintf(dst
, "%s\n", buffer
);
4343 if (cups_protocol
[0])
4344 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4346 cupsFreeOptions(num_defaults
, defaults
);
4349 * Close both files and return...
4356 return (cupsFileClose(dst
));
4361 * 'copy_job_attrs()' - Copy job attributes.
4365 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4366 cupsd_job_t
*job
, /* I - Job */
4367 cups_array_t
*ra
) /* I - Requested attributes array */
4369 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4373 * Send the requested attributes for each job...
4376 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4377 con
->servername
, con
->serverport
, "/jobs/%d",
4380 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
4381 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4382 "job-more-info", NULL
, job_uri
);
4384 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4385 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4386 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4387 job
->num_files
> 0);
4389 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
4390 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4391 "job-printer-up-time", time(NULL
));
4393 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4394 add_job_state_reasons(con
, job
);
4396 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4397 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4398 "job-uri", NULL
, job_uri
);
4400 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
4405 * 'copy_printer_attrs()' - Copy printer attributes.
4410 cupsd_client_t
*con
, /* I - Client connection */
4411 cupsd_printer_t
*printer
, /* I - Printer */
4412 cups_array_t
*ra
) /* I - Requested attributes array */
4414 char printer_uri
[HTTP_MAX_URI
];
4416 time_t curtime
; /* Current time */
4417 int i
; /* Looping var */
4418 ipp_attribute_t
*history
; /* History collection */
4422 * Copy the printer attributes to the response using requested-attributes
4423 * and document-format attributes that may be provided by the client.
4426 curtime
= time(NULL
);
4429 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
4430 printer
->recoverable
)
4431 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4432 "com.apple.print.recoverable-message", NULL
,
4433 printer
->recoverable
);
4434 #endif /* __APPLE__ */
4436 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4437 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4438 ippTimeToDate(curtime
));
4440 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4441 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4442 "printer-error-policy", NULL
, printer
->error_policy
);
4444 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4445 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
4446 printer
->accepting
);
4448 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4449 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
4452 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4453 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4454 "printer-op-policy", NULL
, printer
->op_policy
);
4456 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4457 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4460 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4461 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4462 "printer-state-change-time", printer
->state_time
);
4464 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
4465 cupsArrayFind(ra
, "printer-state-history"))
4468 * Printer history is only sent if specifically requested, so that
4469 * older CUPS/IPP clients won't barf on the collection attributes.
4472 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
4473 "printer-state-history",
4474 printer
->num_history
, NULL
);
4476 for (i
= 0; i
< printer
->num_history
; i
++)
4477 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
4478 NULL
, IPP_TAG_ZERO
, 0);
4481 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4482 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4483 "printer-state-message", NULL
, printer
->state_message
);
4485 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4486 add_printer_state_reasons(con
, printer
);
4488 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4490 int type
; /* printer-type value */
4494 * Add the CUPS-specific printer-type attribute...
4497 type
= printer
->type
;
4499 if (printer
== DefaultPrinter
)
4500 type
|= CUPS_PRINTER_DEFAULT
;
4502 if (!printer
->accepting
)
4503 type
|= CUPS_PRINTER_REJECTING
;
4505 if (!printer
->shared
)
4506 type
|= CUPS_PRINTER_NOT_SHARED
;
4508 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
4512 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4513 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4514 "printer-up-time", curtime
);
4516 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
4517 !ippFindAttribute(printer
->attrs
, "printer-uri-supported",
4520 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4521 "ipp", NULL
, con
->servername
, con
->serverport
,
4522 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4523 "/classes/%s" : "/printers/%s", printer
->name
);
4524 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4525 "printer-uri-supported", NULL
, printer_uri
);
4526 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4530 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4531 add_queued_job_count(con
, printer
);
4533 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
4534 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
4539 * 'copy_subscription_attrs()' - Copy subscription attributes.
4543 copy_subscription_attrs(
4544 cupsd_client_t
*con
, /* I - Client connection */
4545 cupsd_subscription_t
*sub
, /* I - Subscription */
4546 cups_array_t
*ra
) /* I - Requested attributes array */
4548 ipp_attribute_t
*attr
; /* Current attribute */
4549 char printer_uri
[HTTP_MAX_URI
];
4551 int count
; /* Number of events */
4552 unsigned mask
; /* Current event mask */
4553 const char *name
; /* Current event name */
4557 * Copy the subscription attributes to the response using the
4558 * requested-attributes attribute that may be provided by the client.
4561 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
4563 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
4566 * Simple event list...
4569 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
4570 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
4571 "notify-events", NULL
, name
);
4576 * Complex event list...
4579 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
4580 if (sub
->mask
& mask
)
4583 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
4584 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
4585 "notify-events", count
, NULL
, NULL
);
4587 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
4588 if (sub
->mask
& mask
)
4590 attr
->values
[count
].string
.text
=
4591 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
4598 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
4599 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4600 "notify-job-id", sub
->job
->id
);
4602 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
4603 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4604 "notify-lease-duration", sub
->lease
);
4606 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
4608 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4609 "ipp", NULL
, con
->servername
, con
->serverport
,
4610 "/printers/%s", sub
->dest
->name
);
4611 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
4612 "notify-printer-uri", NULL
, printer_uri
);
4615 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
4616 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
4617 "notify-recipient-uri", NULL
, sub
->recipient
);
4618 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
4619 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
4620 "notify-pull-method", NULL
, "ippget");
4622 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
4623 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
4624 "notify-subscriber-user-name", NULL
, sub
->owner
);
4626 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
4627 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4628 "notify-subscription-id", sub
->id
);
4630 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
4631 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4632 "notify-time-interval", sub
->interval
);
4634 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
4635 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
4636 sub
->user_data
, sub
->user_data_len
);
4641 * 'create_job()' - Print a file to a printer or class.
4645 create_job(cupsd_client_t
*con
, /* I - Client connection */
4646 ipp_attribute_t
*uri
) /* I - Printer URI */
4648 cupsd_printer_t
*printer
; /* Printer */
4649 cupsd_job_t
*job
; /* New job */
4652 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
4653 con
->http
.fd
, uri
->values
[0].string
.text
);
4656 * Is the destination valid?
4659 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
4665 send_ipp_status(con
, IPP_NOT_FOUND
,
4666 _("The printer or class was not found."));
4671 * Create the job object...
4674 if ((job
= add_job(con
, printer
, NULL
)) == NULL
)
4678 * Save and log the job...
4683 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d created on \"%s\" by \"%s\".",
4684 job
->id
, job
->dest
, job
->username
);
4689 * 'create_requested_array()' - Create an array for the requested-attributes.
4692 static cups_array_t
* /* O - Array of attributes or NULL */
4693 create_requested_array(ipp_t
*request
) /* I - IPP request */
4695 int i
; /* Looping var */
4696 ipp_attribute_t
*requested
; /* requested-attributes attribute */
4697 cups_array_t
*ra
; /* Requested attributes array */
4698 char *value
; /* Current value */
4702 * Get the requested-attributes attribute, and return NULL if we don't
4706 if ((requested
= ippFindAttribute(request
, "requested-attributes",
4707 IPP_TAG_KEYWORD
)) == NULL
)
4711 * If the attribute contains a single "all" keyword, return NULL...
4714 if (requested
->num_values
== 1 &&
4715 !strcmp(requested
->values
[0].string
.text
, "all"))
4719 * Create an array using "strcmp" as the comparison function...
4722 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4724 for (i
= 0; i
< requested
->num_values
; i
++)
4726 value
= requested
->values
[i
].string
.text
;
4728 if (!strcmp(value
, "job-template"))
4730 cupsArrayAdd(ra
, "copies");
4731 cupsArrayAdd(ra
, "copies-default");
4732 cupsArrayAdd(ra
, "copies-supported");
4733 cupsArrayAdd(ra
, "finishings");
4734 cupsArrayAdd(ra
, "finishings-default");
4735 cupsArrayAdd(ra
, "finishings-supported");
4736 cupsArrayAdd(ra
, "job-hold-until");
4737 cupsArrayAdd(ra
, "job-hold-until-default");
4738 cupsArrayAdd(ra
, "job-hold-until-supported");
4739 cupsArrayAdd(ra
, "job-priority");
4740 cupsArrayAdd(ra
, "job-priority-default");
4741 cupsArrayAdd(ra
, "job-priority-supported");
4742 cupsArrayAdd(ra
, "job-sheets");
4743 cupsArrayAdd(ra
, "job-sheets-default");
4744 cupsArrayAdd(ra
, "job-sheets-supported");
4745 cupsArrayAdd(ra
, "media");
4746 cupsArrayAdd(ra
, "media-default");
4747 cupsArrayAdd(ra
, "media-supported");
4748 cupsArrayAdd(ra
, "multiple-document-handling");
4749 cupsArrayAdd(ra
, "multiple-document-handling-default");
4750 cupsArrayAdd(ra
, "multiple-document-handling-supported");
4751 cupsArrayAdd(ra
, "number-up");
4752 cupsArrayAdd(ra
, "number-up-default");
4753 cupsArrayAdd(ra
, "number-up-supported");
4754 cupsArrayAdd(ra
, "orientation-requested");
4755 cupsArrayAdd(ra
, "orientation-requested-default");
4756 cupsArrayAdd(ra
, "orientation-requested-supported");
4757 cupsArrayAdd(ra
, "page-ranges");
4758 cupsArrayAdd(ra
, "page-ranges-supported");
4759 cupsArrayAdd(ra
, "printer-resolution");
4760 cupsArrayAdd(ra
, "printer-resolution-default");
4761 cupsArrayAdd(ra
, "printer-resolution-supported");
4762 cupsArrayAdd(ra
, "print-quality");
4763 cupsArrayAdd(ra
, "print-quality-default");
4764 cupsArrayAdd(ra
, "print-quality-supported");
4765 cupsArrayAdd(ra
, "sides");
4766 cupsArrayAdd(ra
, "sides-default");
4767 cupsArrayAdd(ra
, "sides-supported");
4769 else if (!strcmp(value
, "job-description"))
4771 cupsArrayAdd(ra
, "date-time-at-completed");
4772 cupsArrayAdd(ra
, "date-time-at-creation");
4773 cupsArrayAdd(ra
, "date-time-at-processing");
4774 cupsArrayAdd(ra
, "job-detailed-status-message");
4775 cupsArrayAdd(ra
, "job-document-access-errors");
4776 cupsArrayAdd(ra
, "job-id");
4777 cupsArrayAdd(ra
, "job-impressions");
4778 cupsArrayAdd(ra
, "job-impressions-completed");
4779 cupsArrayAdd(ra
, "job-k-octets");
4780 cupsArrayAdd(ra
, "job-k-octets-processed");
4781 cupsArrayAdd(ra
, "job-media-sheets");
4782 cupsArrayAdd(ra
, "job-media-sheets-completed");
4783 cupsArrayAdd(ra
, "job-message-from-operator");
4784 cupsArrayAdd(ra
, "job-more-info");
4785 cupsArrayAdd(ra
, "job-name");
4786 cupsArrayAdd(ra
, "job-originating-user-name");
4787 cupsArrayAdd(ra
, "job-printer-up-time");
4788 cupsArrayAdd(ra
, "job-printer-uri");
4789 cupsArrayAdd(ra
, "job-state");
4790 cupsArrayAdd(ra
, "job-state-message");
4791 cupsArrayAdd(ra
, "job-state-reasons");
4792 cupsArrayAdd(ra
, "job-uri");
4793 cupsArrayAdd(ra
, "number-of-documents");
4794 cupsArrayAdd(ra
, "number-of-intervening-jobs");
4795 cupsArrayAdd(ra
, "output-device-assigned");
4796 cupsArrayAdd(ra
, "time-at-completed");
4797 cupsArrayAdd(ra
, "time-at-creation");
4798 cupsArrayAdd(ra
, "time-at-processing");
4800 else if (!strcmp(value
, "printer-description"))
4802 cupsArrayAdd(ra
, "charset-configured");
4803 cupsArrayAdd(ra
, "charset-supported");
4804 cupsArrayAdd(ra
, "color-supported");
4805 cupsArrayAdd(ra
, "compression-supported");
4806 cupsArrayAdd(ra
, "document-format-default");
4807 cupsArrayAdd(ra
, "document-format-supported");
4808 cupsArrayAdd(ra
, "generated-natural-language-supported");
4809 cupsArrayAdd(ra
, "ipp-versions-supported");
4810 cupsArrayAdd(ra
, "job-impressions-supported");
4811 cupsArrayAdd(ra
, "job-k-octets-supported");
4812 cupsArrayAdd(ra
, "job-media-sheets-supported");
4813 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
4814 cupsArrayAdd(ra
, "multiple-operation-time-out");
4815 cupsArrayAdd(ra
, "natural-language-configured");
4816 cupsArrayAdd(ra
, "notify-attributes-supported");
4817 cupsArrayAdd(ra
, "notify-lease-duration-default");
4818 cupsArrayAdd(ra
, "notify-lease-duration-supported");
4819 cupsArrayAdd(ra
, "notify-max-events-supported");
4820 cupsArrayAdd(ra
, "notify-events-default");
4821 cupsArrayAdd(ra
, "notify-events-supported");
4822 cupsArrayAdd(ra
, "notify-pull-method-supported");
4823 cupsArrayAdd(ra
, "notify-schemes-supported");
4824 cupsArrayAdd(ra
, "operations-supported");
4825 cupsArrayAdd(ra
, "pages-per-minute");
4826 cupsArrayAdd(ra
, "pages-per-minute-color");
4827 cupsArrayAdd(ra
, "pdl-override-supported");
4828 cupsArrayAdd(ra
, "printer-current-time");
4829 cupsArrayAdd(ra
, "printer-driver-installer");
4830 cupsArrayAdd(ra
, "printer-info");
4831 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
4832 cupsArrayAdd(ra
, "printer-location");
4833 cupsArrayAdd(ra
, "printer-make-and-model");
4834 cupsArrayAdd(ra
, "printer-message-from-operator");
4835 cupsArrayAdd(ra
, "printer-more-info");
4836 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
4837 cupsArrayAdd(ra
, "printer-name");
4838 cupsArrayAdd(ra
, "printer-state");
4839 cupsArrayAdd(ra
, "printer-state-message");
4840 cupsArrayAdd(ra
, "printer-state-reasons");
4841 cupsArrayAdd(ra
, "printer-up-time");
4842 cupsArrayAdd(ra
, "printer-uri-supported");
4843 cupsArrayAdd(ra
, "queued-job-count");
4844 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
4845 cupsArrayAdd(ra
, "uri-authentication-supported");
4846 cupsArrayAdd(ra
, "uri-security-supported");
4848 else if (!strcmp(value
, "printer-defaults"))
4850 char *name
; /* Option name */
4853 for (name
= (char *)cupsArrayFirst(CommonDefaults
);
4855 name
= (char *)cupsArrayNext(CommonDefaults
))
4856 cupsArrayAdd(ra
, name
);
4858 else if (!strcmp(value
, "subscription-template"))
4860 cupsArrayAdd(ra
, "notify-attributes");
4861 cupsArrayAdd(ra
, "notify-charset");
4862 cupsArrayAdd(ra
, "notify-events");
4863 cupsArrayAdd(ra
, "notify-lease-duration");
4864 cupsArrayAdd(ra
, "notify-natural-language");
4865 cupsArrayAdd(ra
, "notify-pull-method");
4866 cupsArrayAdd(ra
, "notify-recipient-uri");
4867 cupsArrayAdd(ra
, "notify-time-interval");
4868 cupsArrayAdd(ra
, "notify-user-data");
4871 cupsArrayAdd(ra
, value
);
4879 * 'create_subscription()' - Create a notification subscription.
4883 create_subscription(
4884 cupsd_client_t
*con
, /* I - Client connection */
4885 ipp_attribute_t
*uri
) /* I - Printer URI */
4887 http_status_t status
; /* Policy status */
4888 int i
; /* Looping var */
4889 ipp_attribute_t
*attr
; /* Current attribute */
4890 cups_ptype_t dtype
; /* Destination type (printer or class) */
4891 char scheme
[HTTP_MAX_URI
],
4892 /* Scheme portion of URI */
4893 userpass
[HTTP_MAX_URI
],
4894 /* Username portion of URI */
4896 /* Host portion of URI */
4897 resource
[HTTP_MAX_URI
];
4898 /* Resource portion of URI */
4899 int port
; /* Port portion of URI */
4900 cupsd_printer_t
*printer
; /* Printer/class */
4901 cupsd_job_t
*job
; /* Job */
4902 int jobid
; /* Job ID */
4903 cupsd_subscription_t
*sub
; /* Subscription object */
4904 const char *username
, /* requesting-user-name or authenticated username */
4905 *recipient
, /* notify-recipient-uri */
4906 *pullmethod
; /* notify-pull-method */
4907 ipp_attribute_t
*user_data
; /* notify-user-data */
4908 int interval
, /* notify-time-interval */
4909 lease
; /* notify-lease-duration */
4910 unsigned mask
; /* notify-events */
4911 ipp_attribute_t
*notify_events
,/* notify-events(-default) */
4912 *notify_lease
; /* notify-lease-duration(-default) */
4916 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
4918 if (attr
->group_tag
!= IPP_TAG_ZERO
)
4919 cupsdLogMessage(CUPSD_LOG_DEBUG
, "g%04x v%04x %s", attr
->group_tag
,
4920 attr
->value_tag
, attr
->name
);
4922 cupsdLogMessage(CUPSD_LOG_DEBUG
, "----SEP----");
4927 * Is the destination valid?
4930 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4931 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
4932 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4934 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4935 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
4936 sizeof(host
), &port
, resource
, sizeof(resource
));
4938 if (!strcmp(resource
, "/"))
4940 dtype
= (cups_ptype_t
)0;
4943 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
4945 dtype
= (cups_ptype_t
)0;
4948 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
4950 dtype
= CUPS_PRINTER_CLASS
;
4953 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
4959 send_ipp_status(con
, IPP_NOT_FOUND
,
4960 _("The printer or class was not found."));
4970 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
4973 send_http_error(con
, status
, printer
);
4977 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4979 send_http_error(con
, status
, NULL
);
4984 * Get the user that is requesting the subscription...
4987 username
= get_username(con
);
4990 * Find the first subscription group attribute; return if we have
4994 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
4995 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
5000 send_ipp_status(con
, IPP_BAD_REQUEST
,
5001 _("No subscription attributes in request!"));
5006 * Process the subscription attributes in the request...
5009 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
5017 lease
= DefaultLeaseDuration
;
5019 mask
= CUPSD_EVENT_NONE
;
5023 notify_events
= ippFindAttribute(printer
->attrs
, "notify-events-default",
5025 notify_lease
= ippFindAttribute(printer
->attrs
,
5026 "notify-lease-duration-default",
5030 lease
= notify_lease
->values
[0].integer
;
5034 notify_events
= NULL
;
5035 notify_lease
= NULL
;
5038 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
5040 if (!strcmp(attr
->name
, "notify-recipient-uri") &&
5041 attr
->value_tag
== IPP_TAG_URI
)
5044 * Validate the recipient scheme against the ServerBin/notifier
5048 char notifier
[1024]; /* Notifier filename */
5051 recipient
= attr
->values
[0].string
.text
;
5053 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
5054 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
5055 host
, sizeof(host
), &port
,
5056 resource
, sizeof(resource
)) < HTTP_URI_OK
)
5058 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5059 _("Bad notify-recipient-uri URI \"%s\"!"), recipient
);
5060 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5061 "notify-status-code", IPP_URI_SCHEME
);
5065 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
5067 if (access(notifier
, X_OK
))
5069 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5070 _("notify-recipient-uri URI \"%s\" uses unknown scheme!"),
5072 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5073 "notify-status-code", IPP_URI_SCHEME
);
5077 else if (!strcmp(attr
->name
, "notify-pull-method") &&
5078 attr
->value_tag
== IPP_TAG_KEYWORD
)
5080 pullmethod
= attr
->values
[0].string
.text
;
5082 if (strcmp(pullmethod
, "ippget"))
5084 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
5085 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
5086 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
5087 "notify-status-code", IPP_ATTRIBUTES
);
5091 else if (!strcmp(attr
->name
, "notify-charset") &&
5092 attr
->value_tag
== IPP_TAG_CHARSET
&&
5093 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
5094 strcmp(attr
->values
[0].string
.text
, "utf-8"))
5096 send_ipp_status(con
, IPP_CHARSET
,
5097 _("Character set \"%s\" not supported!"),
5098 attr
->values
[0].string
.text
);
5101 else if (!strcmp(attr
->name
, "notify-natural-language") &&
5102 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
5103 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
5105 send_ipp_status(con
, IPP_CHARSET
,
5106 _("Language \"%s\" not supported!"),
5107 attr
->values
[0].string
.text
);
5110 else if (!strcmp(attr
->name
, "notify-user-data") &&
5111 attr
->value_tag
== IPP_TAG_STRING
)
5113 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
5115 send_ipp_status(con
, IPP_REQUEST_VALUE
,
5116 _("The notify-user-data value is too large "
5117 "(%d > 63 octets)!"),
5118 attr
->values
[0].unknown
.length
);
5124 else if (!strcmp(attr
->name
, "notify-events") &&
5125 attr
->value_tag
== IPP_TAG_KEYWORD
)
5126 notify_events
= attr
;
5127 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
5128 attr
->value_tag
== IPP_TAG_INTEGER
)
5129 lease
= attr
->values
[0].integer
;
5130 else if (!strcmp(attr
->name
, "notify-time-interval") &&
5131 attr
->value_tag
== IPP_TAG_INTEGER
)
5132 interval
= attr
->values
[0].integer
;
5133 else if (!strcmp(attr
->name
, "notify-job-id") &&
5134 attr
->value_tag
== IPP_TAG_INTEGER
)
5135 jobid
= attr
->values
[0].integer
;
5142 for (i
= 0; i
< notify_events
->num_values
; i
++)
5143 mask
|= cupsdEventValue(notify_events
->values
[i
].string
.text
);
5147 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
5149 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
5150 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
5151 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
5153 if (!recipient
&& !pullmethod
)
5156 if (mask
== CUPSD_EVENT_NONE
)
5159 mask
= CUPSD_EVENT_JOB_COMPLETED
;
5161 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
5164 send_ipp_status(con
, IPP_BAD_REQUEST
,
5165 _("notify-events not specified!"));
5170 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
5172 cupsdLogMessage(CUPSD_LOG_INFO
,
5173 "create_subscription: Limiting notify-lease-duration to "
5176 lease
= MaxLeaseDuration
;
5181 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5183 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
5190 sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0);
5193 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
5196 cupsdLogMessage(CUPSD_LOG_DEBUG
,
5197 "Added subscription %d for printer \"%s\"",
5198 sub
->id
, printer
->name
);
5200 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
5203 sub
->interval
= interval
;
5205 sub
->expire
= lease
? time(NULL
) + lease
: 0;
5207 cupsdSetString(&sub
->owner
, username
);
5211 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
5212 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
5213 sub
->user_data_len
);
5216 ippAddSeparator(con
->response
);
5217 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
5218 "notify-subscription-id", sub
->id
);
5220 con
->response
->request
.status
.status_code
= IPP_OK
;
5226 cupsdSaveAllSubscriptions();
5232 * 'delete_printer()' - Remove a printer or class from the system.
5236 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5237 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5239 http_status_t status
; /* Policy status */
5240 cups_ptype_t dtype
; /* Destination type (printer or class) */
5241 cupsd_printer_t
*printer
; /* Printer/class */
5242 char filename
[1024]; /* Script/PPD filename */
5245 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5246 con
->http
.fd
, uri
->values
[0].string
.text
);
5249 * Do we have a valid URI?
5252 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5258 send_ipp_status(con
, IPP_NOT_FOUND
,
5259 _("The printer or class was not found."));
5267 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5269 send_http_error(con
, status
, NULL
);
5274 * Remove old jobs...
5277 cupsdCancelJobs(printer
->name
, NULL
, 1);
5280 * Remove old subscriptions and send a "deleted printer" event...
5283 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5284 "%s \"%s\" deleted by \"%s\".",
5285 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5286 printer
->name
, get_username(con
));
5288 cupsdExpireSubscriptions(printer
, NULL
);
5291 * Remove any old PPD or script files...
5294 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
,
5298 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
,
5302 if (dtype
& CUPS_PRINTER_CLASS
)
5304 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".",
5305 printer
->name
, get_username(con
));
5307 cupsdDeletePrinter(printer
, 0);
5308 cupsdSaveAllClasses();
5312 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".",
5313 printer
->name
, get_username(con
));
5315 cupsdDeletePrinter(printer
, 0);
5316 cupsdSaveAllPrinters();
5319 cupsdWritePrintcap();
5322 * Return with no errors...
5325 con
->response
->request
.status
.status_code
= IPP_OK
;
5330 * 'get_default()' - Get the default destination.
5334 get_default(cupsd_client_t
*con
) /* I - Client connection */
5336 http_status_t status
; /* Policy status */
5337 cups_array_t
*ra
; /* Requested attributes array */
5340 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5346 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5348 send_http_error(con
, status
, NULL
);
5354 ra
= create_requested_array(con
->request
);
5356 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5358 cupsArrayDelete(ra
);
5360 con
->response
->request
.status
.status_code
= IPP_OK
;
5363 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
5368 * 'get_devices()' - Get the list of available devices on the local system.
5372 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5374 http_status_t status
; /* Policy status */
5375 ipp_attribute_t
*limit
, /* Limit attribute */
5376 *requested
; /* requested-attributes attribute */
5377 char command
[1024], /* cups-deviced command */
5378 options
[1024], /* Options to pass to command */
5380 /* String for requested attributes */
5383 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
5389 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5391 send_http_error(con
, status
, NULL
);
5396 * Run cups-deviced command with the given options...
5399 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5400 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5404 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5406 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5408 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5409 snprintf(options
, sizeof(options
),
5411 con
->request
->request
.op
.request_id
,
5412 limit
? limit
->values
[0].integer
: 0, (int)User
,
5415 if (cupsdSendCommand(con
, command
, options
, 1))
5418 * Command started successfully, don't send an IPP response here...
5421 ippDelete(con
->response
);
5422 con
->response
= NULL
;
5427 * Command failed, return "internal error" so the user knows something
5431 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5432 _("cups-deviced failed to execute."));
5438 * 'get_job_attrs()' - Get job attributes.
5442 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5443 ipp_attribute_t
*uri
) /* I - Job URI */
5445 http_status_t status
; /* Policy status */
5446 ipp_attribute_t
*attr
; /* Current attribute */
5447 int jobid
; /* Job ID */
5448 cupsd_job_t
*job
; /* Current job */
5449 char method
[HTTP_MAX_URI
], /* Method portion of URI */
5450 username
[HTTP_MAX_URI
], /* Username portion of URI */
5451 host
[HTTP_MAX_URI
], /* Host portion of URI */
5452 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5453 int port
; /* Port portion of URI */
5454 cups_array_t
*ra
; /* Requested attributes array */
5457 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
5458 con
->http
.fd
, uri
->values
[0].string
.text
);
5461 * See if we have a job URI or a printer URI...
5464 if (!strcmp(uri
->name
, "printer-uri"))
5467 * Got a printer URI; see if we also have a job-id attribute...
5470 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5471 IPP_TAG_INTEGER
)) == NULL
)
5473 send_ipp_status(con
, IPP_BAD_REQUEST
,
5474 _("Got a printer-uri attribute but no job-id!"));
5478 jobid
= attr
->values
[0].integer
;
5483 * Got a job URI; parse it to get the job ID...
5486 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5487 sizeof(method
), username
, sizeof(username
), host
,
5488 sizeof(host
), &port
, resource
, sizeof(resource
));
5490 if (strncmp(resource
, "/jobs/", 6))
5496 send_ipp_status(con
, IPP_BAD_REQUEST
,
5497 _("Bad job-uri attribute \"%s\"!"),
5498 uri
->values
[0].string
.text
);
5502 jobid
= atoi(resource
+ 6);
5506 * See if the job exists...
5509 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5512 * Nope - return a "not found" error...
5515 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
5523 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5525 send_http_error(con
, status
, NULL
);
5530 * Copy attributes...
5535 ra
= create_requested_array(con
->request
);
5536 copy_job_attrs(con
, job
, ra
);
5537 cupsArrayDelete(ra
);
5539 con
->response
->request
.status
.status_code
= IPP_OK
;
5544 * 'get_jobs()' - Get a list of jobs for the specified printer.
5548 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
5549 ipp_attribute_t
*uri
) /* I - Printer URI */
5551 http_status_t status
; /* Policy status */
5552 ipp_attribute_t
*attr
; /* Current attribute */
5553 const char *dest
; /* Destination */
5554 cups_ptype_t dtype
; /* Destination type (printer or class) */
5555 cups_ptype_t dmask
; /* Destination type mask */
5556 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
5557 username
[HTTP_MAX_URI
], /* Username portion of URI */
5558 host
[HTTP_MAX_URI
], /* Host portion of URI */
5559 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5560 int port
; /* Port portion of URI */
5561 int completed
; /* Completed jobs? */
5562 int first_job_id
; /* First job ID */
5563 int limit
; /* Maximum number of jobs to return */
5564 int count
; /* Number of jobs that match */
5565 cupsd_job_t
*job
; /* Current job pointer */
5566 cupsd_printer_t
*printer
; /* Printer */
5567 cups_array_t
*list
; /* Which job list... */
5568 cups_array_t
*ra
; /* Requested attributes array */
5571 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
5572 uri
->values
[0].string
.text
);
5575 * Is the destination valid?
5578 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
5579 sizeof(scheme
), username
, sizeof(username
), host
,
5580 sizeof(host
), &port
, resource
, sizeof(resource
));
5582 if (!strcmp(resource
, "/") ||
5583 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
5586 dtype
= (cups_ptype_t
)0;
5587 dmask
= (cups_ptype_t
)0;
5590 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5593 dtype
= (cups_ptype_t
)0;
5594 dmask
= CUPS_PRINTER_CLASS
;
5597 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5600 dtype
= CUPS_PRINTER_CLASS
;
5601 dmask
= CUPS_PRINTER_CLASS
;
5604 else if ((dest
= cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
,
5611 send_ipp_status(con
, IPP_NOT_FOUND
,
5612 _("The printer or class was not found."));
5617 dtype
&= CUPS_PRINTER_CLASS
;
5618 dmask
= CUPS_PRINTER_CLASS
;
5627 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
,
5630 send_http_error(con
, status
, printer
);
5634 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5636 send_http_error(con
, status
, NULL
);
5641 * See if the "which-jobs" attribute have been specified...
5644 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
5645 IPP_TAG_KEYWORD
)) != NULL
&&
5646 !strcmp(attr
->values
[0].string
.text
, "completed"))
5651 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
5663 * See if they want to limit the number of jobs reported...
5666 if ((attr
= ippFindAttribute(con
->request
, "limit",
5667 IPP_TAG_INTEGER
)) != NULL
)
5668 limit
= attr
->values
[0].integer
;
5672 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
5673 IPP_TAG_INTEGER
)) != NULL
)
5674 first_job_id
= attr
->values
[0].integer
;
5679 * See if we only want to see jobs for a specific user...
5682 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
5683 IPP_TAG_BOOLEAN
)) != NULL
&&
5684 attr
->values
[0].boolean
)
5685 strlcpy(username
, get_username(con
), sizeof(username
));
5689 ra
= create_requested_array(con
->request
);
5692 * OK, build a list of jobs for this printer...
5695 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
5696 count
< limit
&& job
;
5697 job
= (cupsd_job_t
*)cupsArrayNext(list
))
5700 * Filter out jobs that don't match...
5703 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
5705 if ((dest
&& strcmp(job
->dest
, dest
)) &&
5706 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
5708 if ((job
->dtype
& dmask
) != dtype
&&
5709 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
5711 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
5714 if (job
->id
< first_job_id
)
5722 if (username
[0] && strcasecmp(username
, job
->username
))
5726 ippAddSeparator(con
->response
);
5730 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
5732 copy_job_attrs(con
, job
, ra
);
5735 cupsArrayDelete(ra
);
5737 con
->response
->request
.status
.status_code
= IPP_OK
;
5742 * 'get_notifications()' - Get events for a subscription.
5746 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
5748 int i
, j
; /* Looping vars */
5749 http_status_t status
; /* Policy status */
5750 cupsd_subscription_t
*sub
; /* Subscription */
5751 ipp_attribute_t
*ids
, /* notify-subscription-ids */
5752 *sequences
; /* notify-sequence-numbers */
5753 int min_seq
; /* Minimum sequence number */
5754 int interval
; /* Poll interval */
5757 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_notifications(con=%p[%d])",
5761 * Get subscription attributes...
5764 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
5766 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
5771 send_ipp_status(con
, IPP_BAD_REQUEST
,
5772 _("Missing notify-subscription-ids attribute!"));
5777 * Are the subscription IDs valid?
5780 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
5782 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
5785 * Bad subscription ID...
5788 send_ipp_status(con
, IPP_NOT_FOUND
,
5789 _("notify-subscription-id %d no good!"),
5790 ids
->values
[i
].integer
);
5798 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
5800 con
, sub
->owner
)) != HTTP_OK
)
5802 send_http_error(con
, status
, sub
->dest
);
5807 * Check the subscription type and update the interval accordingly.
5810 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
5813 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
5815 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
5821 * Tell the client to poll again in N seconds...
5825 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
5826 "notify-get-interval", interval
);
5828 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
5829 "printer-up-time", time(NULL
));
5832 * Copy the subscription event attributes to the response.
5835 con
->response
->request
.status
.status_code
=
5836 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
5838 for (i
= 0; i
< ids
->num_values
; i
++)
5841 * Get the subscription and sequence number...
5844 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
5846 if (sequences
&& i
< sequences
->num_values
)
5847 min_seq
= sequences
->values
[i
].integer
;
5852 * If we don't have any new events, nothing to do here...
5855 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
5859 * Otherwise copy all of the new events...
5862 if (sub
->first_event_id
> min_seq
)
5865 j
= min_seq
- sub
->first_event_id
;
5867 for (; j
< sub
->num_events
; j
++)
5869 ippAddSeparator(con
->response
);
5871 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
5872 IPP_TAG_EVENT_NOTIFICATION
, 0);
5879 * 'get_ppds()' - Get the list of PPD files on the local system.
5883 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
5885 http_status_t status
; /* Policy status */
5886 ipp_attribute_t
*limit
, /* Limit attribute */
5887 *make
, /* ppd-make attribute */
5888 *requested
; /* requested-attributes attribute */
5889 char command
[1024], /* cups-deviced command */
5890 options
[1024], /* Options to pass to command */
5892 /* String for requested attributes */
5893 make_str
[256]; /* Escaped ppd-make string */
5896 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
5902 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5904 send_http_error(con
, status
, NULL
);
5909 * Run cups-driverd command with the given options...
5912 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5913 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
5914 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5918 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5920 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5923 url_encode_attr(make
, make_str
, sizeof(make_str
));
5927 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
5928 snprintf(options
, sizeof(options
), "list+%d+%d+%s%s%s",
5929 con
->request
->request
.op
.request_id
,
5930 limit
? limit
->values
[0].integer
: 0,
5931 requested_str
, make
? "%20" : "", make_str
);
5933 if (cupsdSendCommand(con
, command
, options
, 0))
5936 * Command started successfully, don't send an IPP response here...
5939 ippDelete(con
->response
);
5940 con
->response
= NULL
;
5945 * Command failed, return "internal error" so the user knows something
5949 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5950 _("cups-driverd failed to execute."));
5956 * 'get_printer_attrs()' - Get printer attributes.
5960 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
5961 ipp_attribute_t
*uri
) /* I - Printer URI */
5963 http_status_t status
; /* Policy status */
5964 cups_ptype_t dtype
; /* Destination type (printer or class) */
5965 cupsd_printer_t
*printer
; /* Printer/class */
5966 cups_array_t
*ra
; /* Requested attributes array */
5969 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
5970 con
->http
.fd
, uri
->values
[0].string
.text
);
5973 * Is the destination valid?
5976 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
5982 send_ipp_status(con
, IPP_NOT_FOUND
,
5983 _("The printer or class was not found."));
5991 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
5993 send_http_error(con
, status
, printer
);
5998 * Send the attributes...
6001 ra
= create_requested_array(con
->request
);
6003 copy_printer_attrs(con
, printer
, ra
);
6005 cupsArrayDelete(ra
);
6007 con
->response
->request
.status
.status_code
= IPP_OK
;
6012 * 'get_printers()' - Get a list of printers or classes.
6016 get_printers(cupsd_client_t
*con
, /* I - Client connection */
6017 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
6019 http_status_t status
; /* Policy status */
6020 ipp_attribute_t
*attr
; /* Current attribute */
6021 int limit
; /* Maximum number of printers to return */
6022 int count
; /* Number of printers that match */
6023 cupsd_printer_t
*printer
; /* Current printer pointer */
6024 int printer_type
, /* printer-type attribute */
6025 printer_mask
; /* printer-type-mask attribute */
6026 char *location
; /* Location string */
6027 const char *username
; /* Current user */
6028 char *first_printer_name
; /* first-printer-name attribute */
6029 cups_array_t
*ra
; /* Requested attributes array */
6032 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
6033 con
->http
.fd
, type
);
6039 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
6041 send_http_error(con
, status
, NULL
);
6046 * Check for printers...
6049 if (!Printers
|| !cupsArrayCount(Printers
))
6051 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
6056 * See if they want to limit the number of printers reported...
6059 if ((attr
= ippFindAttribute(con
->request
, "limit",
6060 IPP_TAG_INTEGER
)) != NULL
)
6061 limit
= attr
->values
[0].integer
;
6065 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
6066 IPP_TAG_NAME
)) != NULL
)
6067 first_printer_name
= attr
->values
[0].string
.text
;
6069 first_printer_name
= NULL
;
6072 * Support filtering...
6075 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
6076 IPP_TAG_ENUM
)) != NULL
)
6077 printer_type
= attr
->values
[0].integer
;
6081 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
6082 IPP_TAG_ENUM
)) != NULL
)
6083 printer_mask
= attr
->values
[0].integer
;
6087 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
6088 IPP_TAG_TEXT
)) != NULL
)
6089 location
= attr
->values
[0].string
.text
;
6093 if (con
->username
[0])
6094 username
= con
->username
;
6095 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
6096 IPP_TAG_NAME
)) != NULL
)
6097 username
= attr
->values
[0].string
.text
;
6101 ra
= create_requested_array(con
->request
);
6104 * OK, build a list of printers for this printer...
6107 if (first_printer_name
)
6109 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
6110 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
6113 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
6116 count
< limit
&& printer
;
6117 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
6119 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
6120 (printer
->type
& printer_mask
) == printer_type
&&
6121 (!location
|| !printer
->location
||
6122 !strcasecmp(printer
->location
, location
)))
6125 * If HideImplicitMembers is enabled, see if this printer or class
6126 * is a member of an implicit class...
6129 if (ImplicitClasses
&& HideImplicitMembers
&&
6130 printer
->in_implicit_class
)
6134 * If a username is specified, see if it is allowed or denied
6138 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
6142 * Add the group separator as needed...
6146 ippAddSeparator(con
->response
);
6151 * Send the attributes...
6154 copy_printer_attrs(con
, printer
, ra
);
6158 cupsArrayDelete(ra
);
6160 con
->response
->request
.status
.status_code
= IPP_OK
;
6165 * 'get_subscription_attrs()' - Get subscription attributes.
6169 get_subscription_attrs(
6170 cupsd_client_t
*con
, /* I - Client connection */
6171 int sub_id
) /* I - Subscription ID */
6173 http_status_t status
; /* Policy status */
6174 cupsd_subscription_t
*sub
; /* Subscription */
6175 cups_array_t
*ra
; /* Requested attributes array */
6178 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6179 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
6180 con
, con
->http
.fd
, sub_id
);
6183 * Is the subscription ID valid?
6186 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
6189 * Bad subscription ID...
6192 send_ipp_status(con
, IPP_NOT_FOUND
,
6193 _("notify-subscription-id %d no good!"), sub_id
);
6201 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
6203 con
, sub
->owner
)) != HTTP_OK
)
6205 send_http_error(con
, status
, sub
->dest
);
6210 * Copy the subscription attributes to the response using the
6211 * requested-attributes attribute that may be provided by the client.
6214 ra
= create_requested_array(con
->request
);
6216 copy_subscription_attrs(con
, sub
, ra
);
6218 cupsArrayDelete(ra
);
6220 con
->response
->request
.status
.status_code
= IPP_OK
;
6225 * 'get_subscriptions()' - Get subscriptions.
6229 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
6230 ipp_attribute_t
*uri
) /* I - Printer/job URI */
6232 http_status_t status
; /* Policy status */
6233 int count
; /* Number of subscriptions */
6234 int limit
; /* Limit */
6235 cupsd_subscription_t
*sub
; /* Subscription */
6236 cups_array_t
*ra
; /* Requested attributes array */
6237 ipp_attribute_t
*attr
; /* Attribute */
6238 cups_ptype_t dtype
; /* Destination type (printer or class) */
6239 char scheme
[HTTP_MAX_URI
],
6240 /* Scheme portion of URI */
6241 username
[HTTP_MAX_URI
],
6242 /* Username portion of URI */
6244 /* Host portion of URI */
6245 resource
[HTTP_MAX_URI
];
6246 /* Resource portion of URI */
6247 int port
; /* Port portion of URI */
6248 cupsd_job_t
*job
; /* Job pointer */
6249 cupsd_printer_t
*printer
; /* Printer */
6252 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6253 "get_subscriptions(con=%p[%d], uri=%s)",
6254 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6257 * Is the destination valid?
6260 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6261 sizeof(scheme
), username
, sizeof(username
), host
,
6262 sizeof(host
), &port
, resource
, sizeof(resource
));
6264 if (!strcmp(resource
, "/") ||
6265 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
6266 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
6267 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
6272 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
6275 job
= cupsdFindJob(atoi(resource
+ 6));
6279 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
6284 else if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
6290 send_ipp_status(con
, IPP_NOT_FOUND
,
6291 _("The printer or class was not found."));
6294 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
6295 IPP_TAG_INTEGER
)) != NULL
)
6297 job
= cupsdFindJob(attr
->values
[0].integer
);
6301 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
6302 attr
->values
[0].integer
);
6313 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
6315 con
, NULL
)) != HTTP_OK
)
6317 send_http_error(con
, status
, printer
);
6322 * Copy the subscription attributes to the response using the
6323 * requested-attributes attribute that may be provided by the client.
6326 ra
= create_requested_array(con
->request
);
6328 if ((attr
= ippFindAttribute(con
->request
, "limit",
6329 IPP_TAG_INTEGER
)) != NULL
)
6330 limit
= attr
->values
[0].integer
;
6335 * See if we only want to see subscriptions for a specific user...
6338 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
6339 IPP_TAG_BOOLEAN
)) != NULL
&&
6340 attr
->values
[0].boolean
)
6341 strlcpy(username
, get_username(con
), sizeof(username
));
6345 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
6347 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
6348 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
6349 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
6351 ippAddSeparator(con
->response
);
6352 copy_subscription_attrs(con
, sub
, ra
);
6355 if (limit
&& count
>= limit
)
6359 cupsArrayDelete(ra
);
6362 con
->response
->request
.status
.status_code
= IPP_OK
;
6364 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
6369 * 'get_username()' - Get the username associated with a request.
6372 static const char * /* O - Username */
6373 get_username(cupsd_client_t
*con
) /* I - Connection */
6375 ipp_attribute_t
*attr
; /* Attribute */
6378 if (con
->username
[0])
6379 return (con
->username
);
6380 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
6381 IPP_TAG_NAME
)) != NULL
)
6382 return (attr
->values
[0].string
.text
);
6384 return ("anonymous");
6389 * 'hold_job()' - Hold a print job.
6393 hold_job(cupsd_client_t
*con
, /* I - Client connection */
6394 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
6396 ipp_attribute_t
*attr
, /* Current job-hold-until */
6397 *newattr
; /* New job-hold-until */
6398 int jobid
; /* Job ID */
6399 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6400 username
[HTTP_MAX_URI
], /* Username portion of URI */
6401 host
[HTTP_MAX_URI
], /* Host portion of URI */
6402 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6403 int port
; /* Port portion of URI */
6404 cupsd_job_t
*job
; /* Job information */
6407 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
6408 uri
->values
[0].string
.text
);
6411 * See if we have a job URI or a printer URI...
6414 if (!strcmp(uri
->name
, "printer-uri"))
6417 * Got a printer URI; see if we also have a job-id attribute...
6420 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6421 IPP_TAG_INTEGER
)) == NULL
)
6423 send_ipp_status(con
, IPP_BAD_REQUEST
,
6424 _("Got a printer-uri attribute but no job-id!"));
6428 jobid
= attr
->values
[0].integer
;
6433 * Got a job URI; parse it to get the job ID...
6436 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6437 sizeof(method
), username
, sizeof(username
), host
,
6438 sizeof(host
), &port
, resource
, sizeof(resource
));
6440 if (strncmp(resource
, "/jobs/", 6))
6446 send_ipp_status(con
, IPP_BAD_REQUEST
,
6447 _("Bad job-uri attribute \"%s\"!"),
6448 uri
->values
[0].string
.text
);
6452 jobid
= atoi(resource
+ 6);
6456 * See if the job exists...
6459 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6462 * Nope - return a "not found" error...
6465 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6470 * See if the job is owned by the requesting user...
6473 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6475 send_http_error(con
, HTTP_UNAUTHORIZED
, NULL
);
6480 * Hold the job and return...
6485 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
6486 "Job held by user.");
6488 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
6489 IPP_TAG_KEYWORD
)) == NULL
)
6490 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
6492 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
6493 IPP_TAG_KEYWORD
)) == NULL
)
6494 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
6499 * Free the old hold value and copy the new one over...
6502 _cupsStrFree(attr
->values
[0].string
.text
);
6506 attr
->value_tag
= newattr
->value_tag
;
6507 attr
->values
[0].string
.text
=
6508 _cupsStrAlloc(newattr
->values
[0].string
.text
);
6512 attr
->value_tag
= IPP_TAG_KEYWORD
;
6513 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
6517 * Hold job until specified time...
6520 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
6522 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
6523 "Job job-hold-until value changed by user.");
6526 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was held by \"%s\".", jobid
,
6529 con
->response
->request
.status
.status_code
= IPP_OK
;
6534 * 'move_job()' - Move a job to a new destination.
6538 move_job(cupsd_client_t
*con
, /* I - Client connection */
6539 ipp_attribute_t
*uri
) /* I - Job URI */
6541 http_status_t status
; /* Policy status */
6542 ipp_attribute_t
*attr
; /* Current attribute */
6543 int jobid
; /* Job ID */
6544 cupsd_job_t
*job
; /* Current job */
6545 const char *src
; /* Source printer/class */
6546 cups_ptype_t stype
, /* Source type (printer or class) */
6547 dtype
; /* Destination type (printer or class) */
6548 char scheme
[HTTP_MAX_URI
], /* Scheme portion of URI */
6549 username
[HTTP_MAX_URI
], /* Username portion of URI */
6550 host
[HTTP_MAX_URI
], /* Host portion of URI */
6551 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6552 int port
; /* Port portion of URI */
6553 cupsd_printer_t
*sprinter
, /* Source printer */
6554 *dprinter
; /* Destination printer */
6557 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
6558 uri
->values
[0].string
.text
);
6561 * Get the new printer or class...
6564 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
6565 IPP_TAG_URI
)) == NULL
)
6568 * Need job-printer-uri...
6571 send_ipp_status(con
, IPP_BAD_REQUEST
,
6572 _("job-printer-uri attribute missing!"));
6576 if (!cupsdValidateDest(attr
->values
[0].string
.text
, &dtype
, &dprinter
))
6582 send_ipp_status(con
, IPP_NOT_FOUND
,
6583 _("The printer or class was not found."));
6591 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
,
6594 send_http_error(con
, status
, dprinter
);
6599 * See if we have a job URI or a printer URI...
6602 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
6603 sizeof(scheme
), username
, sizeof(username
), host
,
6604 sizeof(host
), &port
, resource
, sizeof(resource
));
6606 if (!strcmp(uri
->name
, "printer-uri"))
6609 * Got a printer URI; see if we also have a job-id attribute...
6612 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6613 IPP_TAG_INTEGER
)) == NULL
)
6619 if ((src
= cupsdValidateDest(uri
->values
[0].string
.text
, &stype
,
6620 &sprinter
)) == NULL
)
6626 send_ipp_status(con
, IPP_NOT_FOUND
,
6627 _("The printer or class was not found."));
6636 * Otherwise, just move a single job...
6639 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
6642 * Nope - return a "not found" error...
6645 send_ipp_status(con
, IPP_NOT_FOUND
,
6646 _("Job #%d does not exist!"), attr
->values
[0].integer
);
6652 * Job found, initialize source pointers...
6663 * Got a job URI; parse it to get the job ID...
6666 if (strncmp(resource
, "/jobs/", 6))
6672 send_ipp_status(con
, IPP_BAD_REQUEST
,
6673 _("Bad job-uri attribute \"%s\"!"),
6674 uri
->values
[0].string
.text
);
6679 * See if the job exists...
6682 jobid
= atoi(resource
+ 6);
6684 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6687 * Nope - return a "not found" error...
6690 send_ipp_status(con
, IPP_NOT_FOUND
,
6691 _("Job #%d does not exist!"), jobid
);
6697 * Job found, initialize source pointers...
6706 * Now move the job or jobs...
6712 * See if the job has been completed...
6715 if (job
->state_value
> IPP_JOB_STOPPED
)
6718 * Return a "not-possible" error...
6721 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6722 _("Job #%d is finished and cannot be altered!"),
6728 * See if the job is owned by the requesting user...
6731 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6733 send_http_error(con
, HTTP_UNAUTHORIZED
, NULL
);
6738 * Move the job to a different printer or class...
6741 cupsdMoveJob(job
, dprinter
);
6746 * Got the source printer, now look through the jobs...
6749 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
6751 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
6754 * See if the job is pointing at the source printer or has not been
6758 if (strcasecmp(job
->dest
, src
) ||
6759 job
->state_value
> IPP_JOB_STOPPED
)
6763 * See if the job can be moved by the requesting user...
6766 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6770 * Move the job to a different printer or class...
6773 cupsdMoveJob(job
, dprinter
);
6778 * Start jobs if possible...
6784 * Return with "everything is OK" status...
6787 con
->response
->request
.status
.status_code
= IPP_OK
;
6792 * 'ppd_parse_line()' - Parse a PPD default line.
6795 static int /* O - 0 on success, -1 on failure */
6796 ppd_parse_line(const char *line
, /* I - Line */
6797 char *option
, /* O - Option name */
6798 int olen
, /* I - Size of option name */
6799 char *choice
, /* O - Choice name */
6800 int clen
) /* I - Size of choice name */
6803 * Verify this is a default option line...
6806 if (strncmp(line
, "*Default", 8))
6810 * Read the option name...
6813 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
6823 * Skip everything else up to the colon (:)...
6826 while (*line
&& *line
!= ':')
6835 * Now grab the option choice, skipping leading whitespace...
6838 while (isspace(*line
& 255))
6841 for (clen
--; isalnum(*line
& 255); line
++)
6851 * Return with no errors...
6859 * 'print_job()' - Print a file to a printer or class.
6863 print_job(cupsd_client_t
*con
, /* I - Client connection */
6864 ipp_attribute_t
*uri
) /* I - Printer URI */
6866 ipp_attribute_t
*attr
; /* Current attribute */
6867 ipp_attribute_t
*format
; /* Document-format attribute */
6868 const char *default_format
; /* document-format-default value */
6869 cupsd_job_t
*job
; /* New job */
6870 char filename
[1024]; /* Job filename */
6871 mime_type_t
*filetype
; /* Type of file */
6872 char super
[MIME_MAX_SUPER
], /* Supertype of file */
6873 type
[MIME_MAX_TYPE
], /* Subtype of file */
6874 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
6875 /* Textual name of mime type */
6876 cupsd_printer_t
*printer
; /* Printer data */
6877 struct stat fileinfo
; /* File information */
6878 int kbytes
; /* Size of file */
6879 int compression
; /* Document compression */
6882 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
6883 uri
->values
[0].string
.text
);
6886 * Validate print file attributes, for now just document-format and
6887 * compression (CUPS only supports "none" and "gzip")...
6890 compression
= CUPS_FILE_NONE
;
6892 if ((attr
= ippFindAttribute(con
->request
, "compression",
6893 IPP_TAG_KEYWORD
)) != NULL
)
6895 if (strcmp(attr
->values
[0].string
.text
, "none")
6897 && strcmp(attr
->values
[0].string
.text
, "gzip")
6898 #endif /* HAVE_LIBZ */
6901 send_ipp_status(con
, IPP_ATTRIBUTES
,
6902 _("Unsupported compression \"%s\"!"),
6903 attr
->values
[0].string
.text
);
6904 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6905 "compression", NULL
, attr
->values
[0].string
.text
);
6910 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
6911 compression
= CUPS_FILE_GZIP
;
6912 #endif /* HAVE_LIBZ */
6916 * Do we have a file to print?
6921 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
6926 * Is the destination valid?
6929 if (!cupsdValidateDest(uri
->values
[0].string
.text
, NULL
, &printer
))
6935 send_ipp_status(con
, IPP_NOT_FOUND
,
6936 _("The printer or class was not found."));
6941 * Is it a format we support?
6944 if ((format
= ippFindAttribute(con
->request
, "document-format",
6945 IPP_TAG_MIMETYPE
)) != NULL
)
6948 * Grab format from client...
6951 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
,
6954 send_ipp_status(con
, IPP_BAD_REQUEST
,
6955 _("Could not scan type \"%s\"!"),
6956 format
->values
[0].string
.text
);
6960 else if ((default_format
= cupsGetOption("document-format",
6961 printer
->num_options
,
6962 printer
->options
)) != NULL
)
6965 * Use default document format...
6968 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
6970 send_ipp_status(con
, IPP_BAD_REQUEST
,
6971 _("Could not scan type \"%s\"!"),
6982 strcpy(super
, "application");
6983 strcpy(type
, "octet-stream");
6986 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
6989 * Auto-type the file...
6992 ipp_attribute_t
*doc_name
; /* document-name attribute */
6995 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: auto-typing file...");
6997 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
6998 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
6999 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
7003 filetype
= mimeType(MimeDatabase
, super
, type
);
7006 filetype
= mimeType(MimeDatabase
, super
, type
);
7010 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
7013 * Replace the document-format attribute value with the auto-typed or
7017 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
7022 _cupsStrFree(format
->values
[0].string
.text
);
7024 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
7027 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
7028 "document-format", NULL
, mimetype
);
7032 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
7033 _("Unsupported format \'%s/%s\'!"), super
, type
);
7034 cupsdLogMessage(CUPSD_LOG_INFO
,
7035 "Hint: Do you have the raw file printing rules enabled?");
7038 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
7039 "document-format", NULL
, format
->values
[0].string
.text
);
7044 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: request file type is %s/%s.",
7045 filetype
->super
, filetype
->type
);
7048 * Read any embedded job ticket info from PS files...
7051 if (!strcasecmp(filetype
->super
, "application") &&
7052 !strcasecmp(filetype
->type
, "postscript"))
7053 read_ps_job_ticket(con
);
7056 * Create the job object...
7059 if ((job
= add_job(con
, printer
, filetype
)) == NULL
)
7063 * Update quota data...
7066 if (stat(con
->filename
, &fileinfo
))
7069 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
7071 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
7073 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
7074 IPP_TAG_INTEGER
)) != NULL
)
7075 attr
->values
[0].integer
+= kbytes
;
7078 * Add the job file...
7081 if (add_file(con
, job
, filetype
, compression
))
7084 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
7086 rename(con
->filename
, filename
);
7087 cupsdClearString(&con
->filename
);
7090 * See if we need to add the ending sheet...
7093 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
7095 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
7096 attr
&& attr
->num_values
> 1)
7102 cupsdLogMessage(CUPSD_LOG_INFO
, "Adding end banner page \"%s\" to job %d.",
7103 attr
->values
[1].string
.text
, job
->id
);
7105 kbytes
= copy_banner(con
, job
, attr
->values
[1].string
.text
);
7107 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
7111 * Log and save the job...
7114 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d queued on \"%s\" by \"%s\".", job
->id
,
7115 job
->dest
, job
->username
);
7116 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Job %d hold_until = %d", job
->id
,
7117 (int)job
->hold_until
);
7122 * Start the job if possible...
7130 * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
7132 * This function only gets called when printing a single PostScript
7133 * file using the Print-Job operation. It doesn't work for Create-Job +
7134 * Send-File, since the job attributes need to be set at job creation
7135 * time for banners to work. The embedded PS job ticket stuff is here
7136 * only to allow the Windows printer driver for CUPS to pass in JCL
7137 * options and IPP attributes which otherwise would be lost.
7139 * The format of a PS job ticket is simple:
7141 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
7143 * %cupsJobTicket: attr1=value1
7144 * %cupsJobTicket: attr2=value2
7146 * %cupsJobTicket: attrN=valueN
7148 * Job ticket lines must appear immediately after the first line that
7149 * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
7150 * looking for job ticket info when it finds a line that does not begin
7151 * with "%cupsJobTicket:".
7153 * The maximum length of a job ticket line, including the prefix, is
7154 * 255 characters to conform with the Adobe DSC.
7156 * Read-only attributes are rejected with a notice to the error log in
7157 * case a malicious user tries anything. Since the job ticket is read
7158 * prior to attribute validation in print_job(), job ticket attributes
7159 * will go through the same validation as IPP attributes...
7163 read_ps_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
7165 cups_file_t
*fp
; /* File to read from */
7166 char line
[256]; /* Line data */
7167 int num_options
; /* Number of options */
7168 cups_option_t
*options
; /* Options */
7169 ipp_t
*ticket
; /* New attributes */
7170 ipp_attribute_t
*attr
, /* Current attribute */
7171 *attr2
, /* Job attribute */
7172 *prev2
; /* Previous job attribute */
7176 * First open the print file...
7179 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
7181 cupsdLogMessage(CUPSD_LOG_ERROR
,
7182 "read_ps_job_ticket: Unable to open PostScript print file "
7189 * Skip the first line...
7192 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
7194 cupsdLogMessage(CUPSD_LOG_ERROR
,
7195 "read_ps_job_ticket: Unable to read from PostScript print "
7202 if (strncmp(line
, "%!PS-Adobe-", 11))
7205 * Not a DSC-compliant file, so no job ticket info will be available...
7213 * Read job ticket info from the file...
7219 while (cupsFileGets(fp
, line
, sizeof(line
)))
7222 * Stop at the first non-ticket line...
7225 if (strncmp(line
, "%cupsJobTicket:", 15))
7229 * Add the options to the option array...
7232 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
7236 * Done with the file; see if we have any options...
7241 if (num_options
== 0)
7245 * OK, convert the options to an attribute list, and apply them to
7250 cupsEncodeOptions(ticket
, num_options
, options
);
7253 * See what the user wants to change.
7256 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
7258 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
7261 if (!strcmp(attr
->name
, "job-originating-host-name") ||
7262 !strcmp(attr
->name
, "job-originating-user-name") ||
7263 !strcmp(attr
->name
, "job-media-sheets-completed") ||
7264 !strcmp(attr
->name
, "job-k-octets") ||
7265 !strcmp(attr
->name
, "job-id") ||
7266 !strncmp(attr
->name
, "job-state", 9) ||
7267 !strncmp(attr
->name
, "time-at-", 8))
7268 continue; /* Read-only attrs */
7270 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
7271 IPP_TAG_ZERO
)) != NULL
)
7274 * Some other value; first free the old value...
7277 if (con
->request
->attrs
== attr2
)
7279 con
->request
->attrs
= attr2
->next
;
7284 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
7285 if (prev2
->next
== attr2
)
7287 prev2
->next
= attr2
->next
;
7292 if (con
->request
->last
== attr2
)
7293 con
->request
->last
= prev2
;
7295 _ippFreeAttr(attr2
);
7299 * Add new option by copying it...
7302 copy_attribute(con
->request
, attr
, 0);
7306 * Then free the attribute list and option array...
7310 cupsFreeOptions(num_options
, options
);
7315 * 'reject_jobs()' - Reject print jobs to a printer.
7319 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
7320 ipp_attribute_t
*uri
) /* I - Printer or class URI */
7322 http_status_t status
; /* Policy status */
7323 cups_ptype_t dtype
; /* Destination type (printer or class) */
7324 cupsd_printer_t
*printer
; /* Printer data */
7325 ipp_attribute_t
*attr
; /* printer-state-message text */
7328 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
7329 con
->http
.fd
, uri
->values
[0].string
.text
);
7332 * Is the destination valid?
7335 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
7341 send_ipp_status(con
, IPP_NOT_FOUND
,
7342 _("The printer or class was not found."));
7350 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7352 send_http_error(con
, status
, printer
);
7357 * Reject jobs sent to the printer...
7360 printer
->accepting
= 0;
7362 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
7363 IPP_TAG_TEXT
)) == NULL
)
7364 strcpy(printer
->state_message
, "Rejecting Jobs");
7366 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
7367 sizeof(printer
->state_message
));
7369 cupsdAddPrinterHistory(printer
);
7371 if (dtype
& CUPS_PRINTER_CLASS
)
7373 cupsdSaveAllClasses();
7375 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
7376 printer
->name
, get_username(con
));
7380 cupsdSaveAllPrinters();
7382 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
7383 printer
->name
, get_username(con
));
7387 * Everything was ok, so return OK status...
7390 con
->response
->request
.status
.status_code
= IPP_OK
;
7395 * 'release_job()' - Release a held print job.
7399 release_job(cupsd_client_t
*con
, /* I - Client connection */
7400 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7402 ipp_attribute_t
*attr
; /* Current attribute */
7403 int jobid
; /* Job ID */
7404 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7405 username
[HTTP_MAX_URI
], /* Username portion of URI */
7406 host
[HTTP_MAX_URI
], /* Host portion of URI */
7407 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7408 int port
; /* Port portion of URI */
7409 cupsd_job_t
*job
; /* Job information */
7412 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
7413 con
->http
.fd
, uri
->values
[0].string
.text
);
7416 * See if we have a job URI or a printer URI...
7419 if (!strcmp(uri
->name
, "printer-uri"))
7422 * Got a printer URI; see if we also have a job-id attribute...
7425 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7426 IPP_TAG_INTEGER
)) == NULL
)
7428 send_ipp_status(con
, IPP_BAD_REQUEST
,
7429 _("Got a printer-uri attribute but no job-id!"));
7433 jobid
= attr
->values
[0].integer
;
7438 * Got a job URI; parse it to get the job ID...
7441 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7442 sizeof(method
), username
, sizeof(username
), host
,
7443 sizeof(host
), &port
, resource
, sizeof(resource
));
7445 if (strncmp(resource
, "/jobs/", 6))
7451 send_ipp_status(con
, IPP_BAD_REQUEST
,
7452 _("Bad job-uri attribute \"%s\"!"),
7453 uri
->values
[0].string
.text
);
7457 jobid
= atoi(resource
+ 6);
7461 * See if the job exists...
7464 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7467 * Nope - return a "not found" error...
7470 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7475 * See if job is "held"...
7478 if (job
->state_value
!= IPP_JOB_HELD
)
7481 * Nope - return a "not possible" error...
7484 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
7489 * See if the job is owned by the requesting user...
7492 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7494 send_http_error(con
, HTTP_UNAUTHORIZED
, NULL
);
7499 * Reset the job-hold-until value to "no-hold"...
7502 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7503 IPP_TAG_KEYWORD
)) == NULL
)
7504 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7508 _cupsStrFree(attr
->values
[0].string
.text
);
7510 attr
->value_tag
= IPP_TAG_KEYWORD
;
7511 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
7513 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
7514 "Job job-hold-until value changed by user.");
7518 * Release the job and return...
7521 cupsdReleaseJob(job
);
7523 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
7524 "Job released by user.");
7526 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was released by \"%s\".", jobid
,
7529 con
->response
->request
.status
.status_code
= IPP_OK
;
7534 * 'renew_subscription()' - Renew an existing subscription...
7539 cupsd_client_t
*con
, /* I - Client connection */
7540 int sub_id
) /* I - Subscription ID */
7542 http_status_t status
; /* Policy status */
7543 cupsd_subscription_t
*sub
; /* Subscription */
7544 ipp_attribute_t
*lease
; /* notify-lease-duration */
7547 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7548 "renew_subscription(con=%p[%d], sub_id=%d)",
7549 con
, con
->http
.fd
, sub_id
);
7552 * Is the subscription ID valid?
7555 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7558 * Bad subscription ID...
7561 send_ipp_status(con
, IPP_NOT_FOUND
,
7562 _("notify-subscription-id %d no good!"), sub_id
);
7569 * Job subscriptions cannot be renewed...
7572 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7573 _("Job subscriptions cannot be renewed!"));
7581 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7583 con
, sub
->owner
)) != HTTP_OK
)
7585 send_http_error(con
, status
, sub
->dest
);
7590 * Renew the subscription...
7593 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
7596 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
7598 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
7600 cupsdLogMessage(CUPSD_LOG_INFO
,
7601 "renew_subscription: Limiting notify-lease-duration to "
7604 sub
->lease
= MaxLeaseDuration
;
7607 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
7609 cupsdSaveAllSubscriptions();
7611 con
->response
->request
.status
.status_code
= IPP_OK
;
7616 * 'restart_job()' - Restart an old print job.
7620 restart_job(cupsd_client_t
*con
, /* I - Client connection */
7621 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7623 ipp_attribute_t
*attr
; /* Current attribute */
7624 int jobid
; /* Job ID */
7625 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7626 username
[HTTP_MAX_URI
], /* Username portion of URI */
7627 host
[HTTP_MAX_URI
], /* Host portion of URI */
7628 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7629 int port
; /* Port portion of URI */
7630 cupsd_job_t
*job
; /* Job information */
7633 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
7634 con
->http
.fd
, uri
->values
[0].string
.text
);
7637 * See if we have a job URI or a printer URI...
7640 if (!strcmp(uri
->name
, "printer-uri"))
7643 * Got a printer URI; see if we also have a job-id attribute...
7646 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7647 IPP_TAG_INTEGER
)) == NULL
)
7649 send_ipp_status(con
, IPP_BAD_REQUEST
,
7650 _("Got a printer-uri attribute but no job-id!"));
7654 jobid
= attr
->values
[0].integer
;
7659 * Got a job URI; parse it to get the job ID...
7662 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7663 sizeof(method
), username
, sizeof(username
), host
,
7664 sizeof(host
), &port
, resource
, sizeof(resource
));
7666 if (strncmp(resource
, "/jobs/", 6))
7672 send_ipp_status(con
, IPP_BAD_REQUEST
,
7673 _("Bad job-uri attribute \"%s\"!"),
7674 uri
->values
[0].string
.text
);
7678 jobid
= atoi(resource
+ 6);
7682 * See if the job exists...
7685 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7688 * Nope - return a "not found" error...
7691 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7696 * See if job is in any of the "completed" states...
7699 if (job
->state_value
<= IPP_JOB_PROCESSING
)
7702 * Nope - return a "not possible" error...
7705 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
7711 * See if we have retained the job files...
7716 if (!job
->attrs
|| job
->num_files
== 0)
7719 * Nope - return a "not possible" error...
7722 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7723 _("Job #%d cannot be restarted - no files!"), jobid
);
7728 * See if the job is owned by the requesting user...
7731 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7733 send_http_error(con
, HTTP_UNAUTHORIZED
, NULL
);
7738 * Restart the job and return...
7741 cupsdRestartJob(job
);
7743 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was restarted by \"%s\".", jobid
,
7746 con
->response
->request
.status
.status_code
= IPP_OK
;
7751 * 'save_auth_info()' - Save authentication information for a job.
7756 cupsd_client_t
*con
, /* I - Client connection */
7757 cupsd_job_t
*job
, /* I - Job */
7758 ipp_attribute_t
*auth_info
) /* I - auth-info attribute, if any */
7760 int i
; /* Looping var */
7761 char filename
[1024]; /* Job authentication filename */
7762 cups_file_t
*fp
; /* Job authentication file */
7763 char line
[2048]; /* Line for file */
7767 * This function saves the in-memory authentication information for
7768 * a job so that it can be used to authenticate with a remote host.
7769 * The information is stored in a file that is readable only by the
7770 * root user. The fields are Base-64 encoded, each on a separate line,
7771 * followed by random number (up to 1024) of newlines to limit the
7772 * amount of information that is exposed.
7774 * Because of the potential for exposing of authentication information,
7775 * this functionality is only enabled when running cupsd as root.
7777 * This caching only works for the Basic and BasicDigest authentication
7778 * types. Digest authentication cannot be cached this way, and in
7779 * the future Kerberos authentication may make all of this obsolete.
7781 * Authentication information is saved whenever an authenticated
7782 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
7785 * This information is deleted after a job is completed or canceled,
7786 * so reprints may require subsequent re-authentication.
7793 * Create the authentication file and change permissions...
7796 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
7797 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
7799 cupsdLogMessage(CUPSD_LOG_ERROR
,
7800 "Unable to save authentication info to \"%s\" - %s",
7801 filename
, strerror(errno
));
7805 fchown(cupsFileNumber(fp
), 0, 0);
7806 fchmod(cupsFileNumber(fp
), 0400);
7811 * Write 1 to 4 auth values...
7814 for (i
= 0; i
< auth_info
->num_values
; i
++)
7816 httpEncode64_2(line
, sizeof(line
), auth_info
->values
[i
].string
.text
,
7817 strlen(auth_info
->values
[i
].string
.text
));
7818 cupsFilePrintf(fp
, "%s\n", line
);
7824 * Write the authenticated username...
7827 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
7828 cupsFilePrintf(fp
, "%s\n", line
);
7831 * Write the authenticated password...
7834 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
7835 cupsFilePrintf(fp
, "%s\n", line
);
7839 * Write a random number of newlines to the end of the file...
7842 for (i
= (rand() % 1024); i
>= 0; i
--)
7843 cupsFilePutChar(fp
, '\n');
7846 * Close the file and return...
7851 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
7852 save_krb5_creds(con
, job
);
7853 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
7857 #if defined(HAVE_GSSAPI) && defined(HAVE_KRB5_H)
7859 * 'save_krb5_creds()' - Save Kerberos credentials for the job.
7863 save_krb5_creds(cupsd_client_t
*con
, /* I - Client connection */
7864 cupsd_job_t
*job
) /* I - Job */
7866 krb5_context krb_context
; /* Kerberos context */
7867 krb5_ccache ccache
; /* Credentials cache */
7868 OM_uint32 major_status
, /* Major status code */
7869 minor_status
; /* Minor status code */
7873 * Setup a cached context for the job filters to use...
7876 if (krb5_init_context(&krb_context
))
7878 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to initialize Kerberos context");
7882 # ifdef HAVE_HEIMDAL
7883 if (krb5_cc_gen_new(krb_context
, &krb5_fcc_ops
, &ccache
))
7885 if (krb5_cc_gen_new(krb_context
, &ccache
))
7886 # endif /* HAVE_HEIMDAL */
7888 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create new credentials");
7892 major_status
= gss_krb5_copy_ccache(&minor_status
, con
->gss_delegated_cred
,
7895 if (GSS_ERROR(major_status
))
7897 cupsdLogGSSMessage(CUPSD_LOG_ERROR
, major_status
, minor_status
,
7898 "Unable to import client credentials cache");
7899 krb5_cc_destroy(krb_context
, ccache
);
7903 cupsdSetStringf(&(job
->ccname
), "KRB5CCNAME=FILE:%s",
7904 krb5_cc_get_name(krb_context
, ccache
));
7905 krb5_cc_close(krb_context
, ccache
);
7907 #endif /* HAVE_GSSAPI && HAVE_KRB5_H */
7911 * 'send_document()' - Send a file to a printer or class.
7915 send_document(cupsd_client_t
*con
, /* I - Client connection */
7916 ipp_attribute_t
*uri
) /* I - Printer URI */
7918 ipp_attribute_t
*attr
; /* Current attribute */
7919 ipp_attribute_t
*format
; /* Document-format attribute */
7920 const char *default_format
;/* document-format-default value */
7921 int jobid
; /* Job ID number */
7922 cupsd_job_t
*job
; /* Current job */
7923 char job_uri
[HTTP_MAX_URI
],
7925 method
[HTTP_MAX_URI
],
7926 /* Method portion of URI */
7927 username
[HTTP_MAX_URI
],
7928 /* Username portion of URI */
7930 /* Host portion of URI */
7931 resource
[HTTP_MAX_URI
];
7932 /* Resource portion of URI */
7933 int port
; /* Port portion of URI */
7934 mime_type_t
*filetype
; /* Type of file */
7935 char super
[MIME_MAX_SUPER
],
7936 /* Supertype of file */
7937 type
[MIME_MAX_TYPE
],
7938 /* Subtype of file */
7939 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
7940 /* Textual name of mime type */
7941 char filename
[1024]; /* Job filename */
7942 cupsd_printer_t
*printer
; /* Current printer */
7943 struct stat fileinfo
; /* File information */
7944 int kbytes
; /* Size of file */
7945 int compression
; /* Type of compression */
7948 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
7949 con
->http
.fd
, uri
->values
[0].string
.text
);
7952 * See if we have a job URI or a printer URI...
7955 if (!strcmp(uri
->name
, "printer-uri"))
7958 * Got a printer URI; see if we also have a job-id attribute...
7961 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7962 IPP_TAG_INTEGER
)) == NULL
)
7964 send_ipp_status(con
, IPP_BAD_REQUEST
,
7965 _("Got a printer-uri attribute but no job-id!"));
7969 jobid
= attr
->values
[0].integer
;
7974 * Got a job URI; parse it to get the job ID...
7977 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7978 sizeof(method
), username
, sizeof(username
), host
,
7979 sizeof(host
), &port
, resource
, sizeof(resource
));
7981 if (strncmp(resource
, "/jobs/", 6))
7987 send_ipp_status(con
, IPP_BAD_REQUEST
,
7988 _("Bad job-uri attribute \"%s\"!"),
7989 uri
->values
[0].string
.text
);
7993 jobid
= atoi(resource
+ 6);
7997 * See if the job exists...
8000 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8003 * Nope - return a "not found" error...
8006 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8010 printer
= cupsdFindDest(job
->dest
);
8013 * See if the job is owned by the requesting user...
8016 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8018 send_http_error(con
, HTTP_UNAUTHORIZED
, NULL
);
8023 * OK, see if the client is sending the document compressed - CUPS
8024 * only supports "none" and "gzip".
8027 compression
= CUPS_FILE_NONE
;
8029 if ((attr
= ippFindAttribute(con
->request
, "compression",
8030 IPP_TAG_KEYWORD
)) != NULL
)
8032 if (strcmp(attr
->values
[0].string
.text
, "none")
8034 && strcmp(attr
->values
[0].string
.text
, "gzip")
8035 #endif /* HAVE_LIBZ */
8038 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
8039 attr
->values
[0].string
.text
);
8040 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8041 "compression", NULL
, attr
->values
[0].string
.text
);
8046 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
8047 compression
= CUPS_FILE_GZIP
;
8048 #endif /* HAVE_LIBZ */
8052 * Do we have a file to print?
8057 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8062 * Is it a format we support?
8065 if ((format
= ippFindAttribute(con
->request
, "document-format",
8066 IPP_TAG_MIMETYPE
)) != NULL
)
8069 * Grab format from client...
8072 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
8074 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
8075 format
->values
[0].string
.text
);
8079 else if ((default_format
= cupsGetOption("document-format",
8080 printer
->num_options
,
8081 printer
->options
)) != NULL
)
8084 * Use default document format...
8087 if (sscanf(default_format
, "%15[^/]/%31[^;]", super
, type
) != 2)
8089 send_ipp_status(con
, IPP_BAD_REQUEST
,
8090 _("Could not scan type \"%s\"!"),
8098 * No document format attribute? Auto-type it!
8101 strcpy(super
, "application");
8102 strcpy(type
, "octet-stream");
8105 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8108 * Auto-type the file...
8111 ipp_attribute_t
*doc_name
; /* document-name attribute */
8114 cupsdLogMessage(CUPSD_LOG_DEBUG
, "send_document: auto-typing file...");
8116 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
8117 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
8118 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
8122 filetype
= mimeType(MimeDatabase
, super
, type
);
8125 filetype
= mimeType(MimeDatabase
, super
, type
);
8129 (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))))
8132 * Replace the document-format attribute value with the auto-typed or
8136 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8141 _cupsStrFree(format
->values
[0].string
.text
);
8143 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
8146 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8147 "document-format", NULL
, mimetype
);
8151 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8152 _("Unsupported format \'%s/%s\'!"), super
, type
);
8153 cupsdLogMessage(CUPSD_LOG_INFO
,
8154 "Hint: Do you have the raw file printing rules enabled?");
8157 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8158 "document-format", NULL
, format
->values
[0].string
.text
);
8163 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
8165 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8168 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8169 _("Unsupported format \'%s\'!"), mimetype
);
8171 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8172 "document-format", NULL
, mimetype
);
8177 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8178 "send_document: request file type is %s/%s.",
8179 filetype
->super
, filetype
->type
);
8182 * Add the file to the job...
8187 if (add_file(con
, job
, filetype
, compression
))
8190 if (stat(con
->filename
, &fileinfo
))
8193 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8195 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8197 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8198 IPP_TAG_INTEGER
)) != NULL
)
8199 attr
->values
[0].integer
+= kbytes
;
8201 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8203 rename(con
->filename
, filename
);
8205 cupsdClearString(&con
->filename
);
8207 cupsdLogMessage(CUPSD_LOG_INFO
,
8208 "File of type %s/%s queued in job #%d by \"%s\".",
8209 filetype
->super
, filetype
->type
, job
->id
, job
->username
);
8212 * Start the job if this is the last document...
8215 if ((attr
= ippFindAttribute(con
->request
, "last-document",
8216 IPP_TAG_BOOLEAN
)) != NULL
&&
8217 attr
->values
[0].boolean
)
8220 * See if we need to add the ending sheet...
8224 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
8225 (attr
= ippFindAttribute(job
->attrs
, "job-sheets",
8226 IPP_TAG_ZERO
)) != NULL
&&
8227 attr
->num_values
> 1)
8233 cupsdLogMessage(CUPSD_LOG_INFO
,
8234 "Adding end banner page \"%s\" to job %d.",
8235 attr
->values
[1].string
.text
, job
->id
);
8237 kbytes
= copy_banner(con
, job
, attr
->values
[1].string
.text
);
8239 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8242 if (job
->state_value
== IPP_JOB_STOPPED
)
8244 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
8245 job
->state_value
= IPP_JOB_PENDING
;
8247 else if (job
->state_value
== IPP_JOB_HELD
)
8249 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8250 IPP_TAG_KEYWORD
)) == NULL
)
8251 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8253 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
8255 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
8256 job
->state_value
= IPP_JOB_PENDING
;
8263 * Start the job if possible... Since cupsdCheckJobs() can cancel a
8264 * job if it doesn't print, we need to re-find the job afterwards...
8271 job
= cupsdFindJob(jobid
);
8275 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8276 IPP_TAG_KEYWORD
)) == NULL
)
8277 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8279 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
8281 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
8282 job
->state_value
= IPP_JOB_HELD
;
8283 job
->hold_until
= time(NULL
) + 60;
8289 * Fill in the response info...
8292 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
8295 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
8298 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
8300 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
8301 job
? job
->state_value
: IPP_JOB_CANCELED
);
8302 add_job_state_reasons(con
, job
);
8304 con
->response
->request
.status
.status_code
= IPP_OK
;
8309 * 'send_http_error()' - Send a HTTP error back to the IPP client.
8314 cupsd_client_t
*con
, /* I - Client connection */
8315 http_status_t status
, /* I - HTTP status code */
8316 cupsd_printer_t
*printer
) /* I - Printer, if any */
8318 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s",
8319 ippOpString(con
->request
->request
.op
.operation_id
),
8320 httpStatus(status
));
8322 if (status
== HTTP_UNAUTHORIZED
&&
8323 printer
&& printer
->num_auth_info_required
> 0 &&
8324 !strcmp(printer
->auth_info_required
[0], "negotiate"))
8325 cupsdSendError(con
, status
, AUTH_NEGOTIATE
);
8327 cupsdSendError(con
, status
, AUTH_NONE
);
8329 ippDelete(con
->response
);
8330 con
->response
= NULL
;
8337 * 'send_ipp_status()' - Send a status back to the IPP client.
8341 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
8342 ipp_status_t status
, /* I - IPP status code */
8343 const char *message
, /* I - Status message */
8344 ...) /* I - Additional args as needed */
8346 va_list ap
; /* Pointer to additional args */
8347 char formatted
[1024]; /* Formatted errror message */
8352 va_start(ap
, message
);
8353 vsnprintf(formatted
, sizeof(formatted
),
8354 _cupsLangString(con
->language
, message
), ap
);
8357 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
8358 ippOpString(con
->request
->request
.op
.operation_id
),
8359 ippErrorString(status
), formatted
);
8362 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
8363 ippOpString(con
->request
->request
.op
.operation_id
),
8364 ippErrorString(status
));
8366 con
->response
->request
.status
.status_code
= status
;
8368 if (ippFindAttribute(con
->response
, "attributes-charset",
8369 IPP_TAG_ZERO
) == NULL
)
8370 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
8371 "attributes-charset", NULL
, DefaultCharset
);
8373 if (ippFindAttribute(con
->response
, "attributes-natural-language",
8374 IPP_TAG_ZERO
) == NULL
)
8375 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
8376 "attributes-natural-language", NULL
, DefaultLanguage
);
8379 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
8380 "status-message", NULL
, formatted
);
8385 * 'set_default()' - Set the default destination...
8389 set_default(cupsd_client_t
*con
, /* I - Client connection */
8390 ipp_attribute_t
*uri
) /* I - Printer URI */
8392 http_status_t status
; /* Policy status */
8393 cups_ptype_t dtype
; /* Destination type (printer or class) */
8394 cupsd_printer_t
*printer
; /* Printer */
8397 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
8398 con
->http
.fd
, uri
->values
[0].string
.text
);
8401 * Is the destination valid?
8404 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
8410 send_ipp_status(con
, IPP_NOT_FOUND
,
8411 _("The printer or class was not found."));
8419 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8421 send_http_error(con
, status
, NULL
);
8426 * Set it as the default...
8429 DefaultPrinter
= printer
;
8431 cupsdSaveAllPrinters();
8432 cupsdSaveAllClasses();
8434 cupsdWritePrintcap();
8436 cupsdLogMessage(CUPSD_LOG_INFO
,
8437 "Default destination set to \"%s\" by \"%s\".",
8438 printer
->name
, get_username(con
));
8441 * Everything was ok, so return OK status...
8444 con
->response
->request
.status
.status_code
= IPP_OK
;
8449 * 'set_job_attrs()' - Set job attributes.
8453 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
8454 ipp_attribute_t
*uri
) /* I - Job URI */
8456 ipp_attribute_t
*attr
, /* Current attribute */
8457 *attr2
; /* Job attribute */
8458 int jobid
; /* Job ID */
8459 cupsd_job_t
*job
; /* Current job */
8460 char method
[HTTP_MAX_URI
],
8461 /* Method portion of URI */
8462 username
[HTTP_MAX_URI
],
8463 /* Username portion of URI */
8465 /* Host portion of URI */
8466 resource
[HTTP_MAX_URI
];
8467 /* Resource portion of URI */
8468 int port
; /* Port portion of URI */
8469 int event
; /* Events? */
8472 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
8473 con
->http
.fd
, uri
->values
[0].string
.text
);
8476 * Start with "everything is OK" status...
8479 con
->response
->request
.status
.status_code
= IPP_OK
;
8482 * See if we have a job URI or a printer URI...
8485 if (!strcmp(uri
->name
, "printer-uri"))
8488 * Got a printer URI; see if we also have a job-id attribute...
8491 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8492 IPP_TAG_INTEGER
)) == NULL
)
8494 send_ipp_status(con
, IPP_BAD_REQUEST
,
8495 _("Got a printer-uri attribute but no job-id!"));
8499 jobid
= attr
->values
[0].integer
;
8504 * Got a job URI; parse it to get the job ID...
8507 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8508 sizeof(method
), username
, sizeof(username
), host
,
8509 sizeof(host
), &port
, resource
, sizeof(resource
));
8511 if (strncmp(resource
, "/jobs/", 6))
8517 send_ipp_status(con
, IPP_BAD_REQUEST
,
8518 _("Bad job-uri attribute \"%s\"!"),
8519 uri
->values
[0].string
.text
);
8523 jobid
= atoi(resource
+ 6);
8527 * See if the job exists...
8530 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8533 * Nope - return a "not found" error...
8536 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8541 * See if the job has been completed...
8544 if (job
->state_value
> IPP_JOB_STOPPED
)
8547 * Return a "not-possible" error...
8550 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8551 _("Job #%d is finished and cannot be altered!"), jobid
);
8556 * See if the job is owned by the requesting user...
8559 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8561 send_http_error(con
, HTTP_UNAUTHORIZED
, NULL
);
8566 * See what the user wants to change.
8573 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
8575 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8578 if (!strcmp(attr
->name
, "attributes-charset") ||
8579 !strcmp(attr
->name
, "attributes-natural-language") ||
8580 !strcmp(attr
->name
, "document-compression") ||
8581 !strcmp(attr
->name
, "document-format") ||
8582 !strcmp(attr
->name
, "job-detailed-status-messages") ||
8583 !strcmp(attr
->name
, "job-document-access-errors") ||
8584 !strcmp(attr
->name
, "job-id") ||
8585 !strcmp(attr
->name
, "job-k-octets") ||
8586 !strcmp(attr
->name
, "job-originating-host-name") ||
8587 !strcmp(attr
->name
, "job-originating-user-name") ||
8588 !strcmp(attr
->name
, "job-printer-up-time") ||
8589 !strcmp(attr
->name
, "job-printer-uri") ||
8590 !strcmp(attr
->name
, "job-sheets") ||
8591 !strcmp(attr
->name
, "job-state-message") ||
8592 !strcmp(attr
->name
, "job-state-reasons") ||
8593 !strcmp(attr
->name
, "job-uri") ||
8594 !strcmp(attr
->name
, "number-of-documents") ||
8595 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
8596 !strcmp(attr
->name
, "output-device-assigned") ||
8597 !strncmp(attr
->name
, "date-time-at-", 13) ||
8598 !strncmp(attr
->name
, "job-impressions", 15) ||
8599 !strncmp(attr
->name
, "job-k-octets", 12) ||
8600 !strncmp(attr
->name
, "job-media-sheets", 16) ||
8601 !strncmp(attr
->name
, "time-at-", 8))
8607 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
8608 _("%s cannot be changed."), attr
->name
);
8610 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8611 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8616 if (!strcmp(attr
->name
, "job-priority"))
8619 * Change the job priority...
8622 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8624 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
8626 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8627 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8629 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
8631 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8632 _("Job is completed and cannot be changed."));
8635 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8637 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
8638 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8641 else if (!strcmp(attr
->name
, "job-state"))
8644 * Change the job state...
8647 if (attr
->value_tag
!= IPP_TAG_ENUM
)
8649 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
8651 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8652 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8656 switch (attr
->values
[0].integer
)
8658 case IPP_JOB_PENDING
:
8660 if (job
->state_value
> IPP_JOB_HELD
)
8662 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8663 _("Job state cannot be changed."));
8666 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8668 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
8669 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
8671 event
|= CUPSD_EVENT_JOB_STATE
;
8675 case IPP_JOB_PROCESSING
:
8676 case IPP_JOB_STOPPED
:
8677 if (job
->state_value
!= attr
->values
[0].integer
)
8679 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8680 _("Job state cannot be changed."));
8685 case IPP_JOB_CANCELED
:
8686 case IPP_JOB_ABORTED
:
8687 case IPP_JOB_COMPLETED
:
8688 if (job
->state_value
> IPP_JOB_PROCESSING
)
8690 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8691 _("Job state cannot be changed."));
8694 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8695 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
8700 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
8702 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
8703 IPP_TAG_ZERO
)) != NULL
)
8706 * Some other value; first free the old value...
8709 if (job
->attrs
->prev
)
8710 job
->attrs
->prev
->next
= attr2
->next
;
8712 job
->attrs
->attrs
= attr2
->next
;
8714 if (job
->attrs
->last
== attr2
)
8715 job
->attrs
->last
= job
->attrs
->prev
;
8717 _ippFreeAttr(attr2
);
8720 * Then copy the attribute...
8723 copy_attribute(job
->attrs
, attr
, 0);
8726 * See if the job-name or job-hold-until is being changed.
8729 if (!strcmp(attr
->name
, "job-hold-until"))
8731 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
8733 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
8734 cupsdReleaseJob(job
);
8738 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
8741 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
8744 * Delete the attribute...
8747 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
8748 IPP_TAG_ZERO
)) != NULL
)
8750 if (job
->attrs
->prev
)
8751 job
->attrs
->prev
->next
= attr2
->next
;
8753 job
->attrs
->attrs
= attr2
->next
;
8755 if (attr2
== job
->attrs
->last
)
8756 job
->attrs
->last
= job
->attrs
->prev
;
8758 _ippFreeAttr(attr2
);
8760 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8766 * Add new option by copying it...
8769 copy_attribute(job
->attrs
, attr
, 0);
8771 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8782 * Send events as needed...
8785 if (event
& CUPSD_EVENT_JOB_STATE
)
8786 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
8787 job
->state_value
== IPP_JOB_HELD
?
8788 "Job held by user." : "Job restarted by user.");
8790 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
8791 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
8792 "Job options changed by user.");
8795 * Start jobs if possible...
8803 * 'set_printer_defaults()' - Set printer default options from a request.
8807 set_printer_defaults(
8808 cupsd_client_t
*con
, /* I - Client connection */
8809 cupsd_printer_t
*printer
) /* I - Printer */
8811 int i
; /* Looping var */
8812 ipp_attribute_t
*attr
; /* Current attribute */
8813 int namelen
; /* Length of attribute name */
8814 char name
[256], /* New attribute name */
8815 value
[256]; /* String version of integer attrs */
8818 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
8821 * Skip non-printer attributes...
8824 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
8827 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
8829 if (!strcmp(attr
->name
, "job-sheets-default"))
8832 * Only allow keywords and names...
8835 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
8839 * Only allow job-sheets-default to be set when running without a
8840 * system high classification level...
8846 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
8848 if (attr
->num_values
> 1)
8849 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
8851 cupsdSetString(&printer
->job_sheets
[1], "none");
8853 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
8855 cupsdFreePrinterUsers(printer
);
8857 printer
->deny_users
= 0;
8859 if (attr
->value_tag
== IPP_TAG_NAME
&&
8860 (attr
->num_values
> 1 ||
8861 strcmp(attr
->values
[0].string
.text
, "all")))
8863 for (i
= 0; i
< attr
->num_values
; i
++)
8864 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
8867 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
8869 cupsdFreePrinterUsers(printer
);
8871 printer
->deny_users
= 1;
8873 if (attr
->value_tag
== IPP_TAG_NAME
&&
8874 (attr
->num_values
> 1 ||
8875 strcmp(attr
->values
[0].string
.text
, "none")))
8877 for (i
= 0; i
< attr
->num_values
; i
++)
8878 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
8881 else if (!strcmp(attr
->name
, "job-quota-period"))
8883 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8886 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
8887 attr
->values
[0].integer
);
8888 cupsdFreeQuotas(printer
);
8890 printer
->quota_period
= attr
->values
[0].integer
;
8892 else if (!strcmp(attr
->name
, "job-k-limit"))
8894 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8897 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
8898 attr
->values
[0].integer
);
8899 cupsdFreeQuotas(printer
);
8901 printer
->k_limit
= attr
->values
[0].integer
;
8903 else if (!strcmp(attr
->name
, "job-page-limit"))
8905 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8908 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
8909 attr
->values
[0].integer
);
8910 cupsdFreeQuotas(printer
);
8912 printer
->page_limit
= attr
->values
[0].integer
;
8914 else if (!strcmp(attr
->name
, "printer-op-policy"))
8916 cupsd_policy_t
*p
; /* Policy */
8919 if (attr
->value_tag
!= IPP_TAG_NAME
)
8922 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
8924 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8925 "Setting printer-op-policy to \"%s\"...",
8926 attr
->values
[0].string
.text
);
8927 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
8928 printer
->op_policy_ptr
= p
;
8932 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8933 _("Unknown printer-op-policy \"%s\"."),
8934 attr
->values
[0].string
.text
);
8938 else if (!strcmp(attr
->name
, "printer-error-policy"))
8940 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
8943 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
8944 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
8945 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
8947 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8948 _("Unknown printer-error-policy \"%s\"."),
8949 attr
->values
[0].string
.text
);
8953 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8954 "Setting printer-error-policy to \"%s\"...",
8955 attr
->values
[0].string
.text
);
8956 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
8960 * Skip any other non-default attributes...
8963 namelen
= strlen(attr
->name
);
8964 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
8965 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
8969 * OK, anything else must be a user-defined default...
8972 strlcpy(name
, attr
->name
, sizeof(name
));
8973 name
[namelen
- 8] = '\0'; /* Strip "-default" */
8975 switch (attr
->value_tag
)
8977 case IPP_TAG_DELETEATTR
:
8978 printer
->num_options
= cupsRemoveOption(name
,
8979 printer
->num_options
,
8980 &(printer
->options
));
8981 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8982 "Deleting %s", attr
->name
);
8986 case IPP_TAG_KEYWORD
:
8988 printer
->num_options
= cupsAddOption(name
,
8989 attr
->values
[0].string
.text
,
8990 printer
->num_options
,
8991 &(printer
->options
));
8992 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8993 "Setting %s to \"%s\"...", attr
->name
,
8994 attr
->values
[0].string
.text
);
8997 case IPP_TAG_BOOLEAN
:
8998 printer
->num_options
= cupsAddOption(name
,
8999 attr
->values
[0].boolean
?
9001 printer
->num_options
,
9002 &(printer
->options
));
9003 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9004 "Setting %s to %s...", attr
->name
,
9005 attr
->values
[0].boolean
? "true" : "false");
9008 case IPP_TAG_INTEGER
:
9010 sprintf(value
, "%d", attr
->values
[0].integer
);
9011 printer
->num_options
= cupsAddOption(name
, value
,
9012 printer
->num_options
,
9013 &(printer
->options
));
9014 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9015 "Setting %s to %s...", attr
->name
, value
);
9018 case IPP_TAG_RANGE
:
9019 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
9020 attr
->values
[0].range
.upper
);
9021 printer
->num_options
= cupsAddOption(name
, value
,
9022 printer
->num_options
,
9023 &(printer
->options
));
9024 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9025 "Setting %s to %s...", attr
->name
, value
);
9028 case IPP_TAG_RESOLUTION
:
9029 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
9030 attr
->values
[0].resolution
.yres
,
9031 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
9033 printer
->num_options
= cupsAddOption(name
, value
,
9034 printer
->num_options
,
9035 &(printer
->options
));
9036 cupsdLogMessage(CUPSD_LOG_DEBUG
,
9037 "Setting %s to %s...", attr
->name
, value
);
9041 /* Do nothing for other values */
9049 * 'start_printer()' - Start a printer.
9053 start_printer(cupsd_client_t
*con
, /* I - Client connection */
9054 ipp_attribute_t
*uri
) /* I - Printer URI */
9056 http_status_t status
; /* Policy status */
9057 cups_ptype_t dtype
; /* Destination type (printer or class) */
9058 cupsd_printer_t
*printer
; /* Printer data */
9061 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
9062 con
->http
.fd
, uri
->values
[0].string
.text
);
9065 * Is the destination valid?
9068 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9074 send_ipp_status(con
, IPP_NOT_FOUND
,
9075 _("The printer or class was not found."));
9083 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9085 send_http_error(con
, status
, printer
);
9090 * Start the printer...
9093 printer
->state_message
[0] = '\0';
9095 cupsdStartPrinter(printer
, 1);
9097 if (dtype
& CUPS_PRINTER_CLASS
)
9098 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".",
9099 printer
->name
, get_username(con
));
9101 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".",
9102 printer
->name
, get_username(con
));
9107 * Everything was ok, so return OK status...
9110 con
->response
->request
.status
.status_code
= IPP_OK
;
9115 * 'stop_printer()' - Stop a printer.
9119 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
9120 ipp_attribute_t
*uri
) /* I - Printer URI */
9122 http_status_t status
; /* Policy status */
9123 cups_ptype_t dtype
; /* Destination type (printer or class) */
9124 cupsd_printer_t
*printer
; /* Printer data */
9125 ipp_attribute_t
*attr
; /* printer-state-message attribute */
9128 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
9129 con
->http
.fd
, uri
->values
[0].string
.text
);
9132 * Is the destination valid?
9135 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9141 send_ipp_status(con
, IPP_NOT_FOUND
,
9142 _("The printer or class was not found."));
9150 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9152 send_http_error(con
, status
, printer
);
9157 * Stop the printer...
9160 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
9161 IPP_TAG_TEXT
)) == NULL
)
9162 strcpy(printer
->state_message
, "Paused");
9165 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
9166 sizeof(printer
->state_message
));
9169 cupsdStopPrinter(printer
, 1);
9171 if (dtype
& CUPS_PRINTER_CLASS
)
9172 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".",
9173 printer
->name
, get_username(con
));
9175 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".",
9176 printer
->name
, get_username(con
));
9179 * Everything was ok, so return OK status...
9182 con
->response
->request
.status
.status_code
= IPP_OK
;
9187 * 'url_encode_attr()' - URL-encode a string attribute.
9191 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
9192 char *buffer
,/* I - String buffer */
9193 int bufsize
)/* I - Size of buffer */
9195 int i
; /* Looping var */
9196 char *bufptr
, /* Pointer into buffer */
9197 *bufend
, /* End of buffer */
9198 *valptr
; /* Pointer into value */
9201 strlcpy(buffer
, attr
->name
, bufsize
);
9202 bufptr
= buffer
+ strlen(buffer
);
9203 bufend
= buffer
+ bufsize
- 1;
9205 for (i
= 0; i
< attr
->num_values
; i
++)
9207 if (bufptr
>= bufend
)
9215 if (bufptr
>= bufend
)
9220 for (valptr
= attr
->values
[i
].string
.text
;
9221 *valptr
&& bufptr
< bufend
;
9225 if (bufptr
>= (bufend
- 2))
9232 else if (*valptr
== '\'' || *valptr
== '\\')
9235 *bufptr
++ = *valptr
;
9238 *bufptr
++ = *valptr
;
9240 if (bufptr
>= bufend
)
9251 * 'user_allowed()' - See if a user is allowed to print to a queue.
9254 static int /* O - 0 if not allowed, 1 if allowed */
9255 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
9256 const char *username
) /* I - Username */
9258 int i
; /* Looping var */
9259 struct passwd
*pw
; /* User password data */
9262 if (p
->num_users
== 0)
9265 if (!strcmp(username
, "root"))
9268 pw
= getpwnam(username
);
9271 for (i
= 0; i
< p
->num_users
; i
++)
9273 if (p
->users
[i
][0] == '@')
9276 * Check group membership...
9279 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
9282 else if (!strcasecmp(username
, p
->users
[i
]))
9286 return ((i
< p
->num_users
) != p
->deny_users
);
9291 * 'validate_job()' - Validate printer options and destination.
9295 validate_job(cupsd_client_t
*con
, /* I - Client connection */
9296 ipp_attribute_t
*uri
) /* I - Printer URI */
9298 http_status_t status
; /* Policy status */
9299 ipp_attribute_t
*attr
; /* Current attribute */
9300 ipp_attribute_t
*format
; /* Document-format attribute */
9301 cups_ptype_t dtype
; /* Destination type (printer or class) */
9302 char super
[MIME_MAX_SUPER
],
9303 /* Supertype of file */
9304 type
[MIME_MAX_TYPE
];
9305 /* Subtype of file */
9306 cupsd_printer_t
*printer
; /* Printer */
9309 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
9310 con
->http
.fd
, uri
->values
[0].string
.text
);
9313 * OK, see if the client is sending the document compressed - CUPS
9314 * doesn't support compression yet...
9317 if ((attr
= ippFindAttribute(con
->request
, "compression",
9318 IPP_TAG_KEYWORD
)) != NULL
&&
9319 !strcmp(attr
->values
[0].string
.text
, "none"))
9321 send_ipp_status(con
, IPP_ATTRIBUTES
,
9322 _("Unsupported compression attribute %s!"),
9323 attr
->values
[0].string
.text
);
9324 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9325 "compression", NULL
, attr
->values
[0].string
.text
);
9330 * Is it a format we support?
9333 if ((format
= ippFindAttribute(con
->request
, "document-format",
9334 IPP_TAG_MIMETYPE
)) != NULL
)
9336 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
9338 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9339 format
->values
[0].string
.text
);
9343 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
9344 !mimeType(MimeDatabase
, super
, type
))
9346 cupsdLogMessage(CUPSD_LOG_INFO
,
9347 "Hint: Do you have the raw file printing rules enabled?");
9348 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9349 _("Unsupported format \"%s\"!"),
9350 format
->values
[0].string
.text
);
9351 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9352 "document-format", NULL
, format
->values
[0].string
.text
);
9358 * Is the destination valid?
9361 if (!cupsdValidateDest(uri
->values
[0].string
.text
, &dtype
, &printer
))
9367 send_ipp_status(con
, IPP_NOT_FOUND
,
9368 _("The printer or class was not found."));
9376 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9378 send_http_error(con
, status
, printer
);
9383 * Everything was ok, so return OK status...
9386 con
->response
->request
.status
.status_code
= IPP_OK
;
9391 * 'validate_name()' - Make sure the printer name only contains valid chars.
9394 static int /* O - 0 if name is no good, 1 if name is good */
9395 validate_name(const char *name
) /* I - Name to check */
9397 const char *ptr
; /* Pointer into name */
9401 * Scan the whole name...
9404 for (ptr
= name
; *ptr
; ptr
++)
9405 if ((*ptr
> 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
9409 * All the characters are good; validate the length, too...
9412 return ((ptr
- name
) < 128);
9417 * 'validate_user()' - Validate the user for the request.
9420 static int /* O - 1 if permitted, 0 otherwise */
9421 validate_user(cupsd_job_t
*job
, /* I - Job */
9422 cupsd_client_t
*con
, /* I - Client connection */
9423 const char *owner
, /* I - Owner of job/resource */
9424 char *username
, /* O - Authenticated username */
9425 int userlen
) /* I - Length of username */
9427 cupsd_printer_t
*printer
; /* Printer for job */
9430 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9431 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
9433 job
? job
->id
: 0, con
->http
.fd
, owner
? owner
: "(null)",
9440 if (!con
|| !owner
|| !username
|| userlen
<= 0)
9444 * Get the best authenticated username that is available.
9447 strlcpy(username
, get_username(con
), userlen
);
9450 * Check the username against the owner...
9453 printer
= cupsdFindDest(job
->dest
);
9455 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
9456 con
, owner
) == HTTP_OK
);
9461 * End of "$Id: ipp.c 6383 2007-03-21 20:01:20Z mike $".