2 * "$Id: ipp.c 5051 2006-02-02 16:13:16Z mike $"
4 * IPP routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdProcessIPPRequest() - Process an incoming IPP request...
27 * accept_jobs() - Accept print jobs to a printer.
28 * add_class() - Add a class to the system.
29 * add_file() - Add a file to a job.
30 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
31 * upon the job and printer state...
32 * add_job_subscriptions() - Add any subcriptions for a job.
33 * add_printer() - Add a printer to the system.
34 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
35 * based upon the printer state...
36 * add_queued_job_count() - Add the "queued-job-count" attribute for
37 * authenticate_job() - Set job authentication info.
38 * cancel_all_jobs() - Cancel all print jobs.
39 * cancel_job() - Cancel a print job.
40 * cancel_subscription() - Cancel a subscription.
41 * check_quotas() - Check quotas for a printer and user.
42 * copy_attribute() - Copy a single attribute.
43 * copy_attrs() - Copy attributes from one request to another.
44 * copy_banner() - Copy a banner file to the requests directory
45 * for the specified job.
46 * copy_file() - Copy a PPD file or interface script...
47 * copy_model() - Copy a PPD model file, substituting default
49 * copy_job_attrs() - Copy job attributes.
50 * copy_printer_attrs() - Copy printer attributes.
51 * copy_subscription_attrs() - Copy subscription attributes.
52 * create_job() - Print a file to a printer or class.
53 * create_requested_array() - Create an array for the requested-attributes.
54 * create_subscription() - Create a notification subscription.
55 * delete_printer() - Remove a printer or class from the system.
56 * get_default() - Get the default destination.
57 * get_devices() - Get the list of available devices on the
59 * get_job_attrs() - Get job attributes.
60 * get_jobs() - Get a list of jobs for the specified printer.
61 * get_notifications() - Get events for a subscription.
62 * get_ppds() - Get the list of PPD files on the local
64 * get_printer_attrs() - Get printer attributes.
65 * get_printers() - Get a list of printers.
66 * get_subscription_attrs() - Get subscription attributes.
67 * get_subscriptions() - Get subscriptions.
68 * get_username() - Get the username associated with a request.
69 * hold_job() - Hold a print job.
70 * move_job() - Move a job to a new destination.
71 * ppd_add_default() - Add a PPD default choice.
72 * ppd_parse_line() - Parse a PPD default line.
73 * print_job() - Print a file to a printer or class.
74 * read_ps_line() - Read a line from a PS file...
75 * read_ps_job_ticket() - Reads a job ticket embedded in a PS file.
76 * reject_jobs() - Reject print jobs to a printer.
77 * release_job() - Release a held print job.
78 * restart_job() - Restart an old print job.
79 * save_auth_info() - Save authentication information for a job.
80 * send_document() - Send a file to a printer or class.
81 * send_http_error() - Send a HTTP error back to the IPP client.
82 * send_ipp_status() - Send a status back to the IPP client.
83 * set_default() - Set the default destination...
84 * set_job_attrs() - Set job attributes.
85 * start_printer() - Start a printer.
86 * stop_printer() - Stop a printer.
87 * user_allowed() - See if a user is allowed to print to a queue.
88 * validate_job() - Validate printer options and destination.
89 * validate_name() - Make sure the printer name only contains
91 * validate_user() - Validate the user for the request.
95 * Include necessary headers...
102 #endif /* HAVE_LIBPAPER */
106 * PPD default choice structure...
111 char option
[PPD_MAX_NAME
]; /* Main keyword (option name) */
112 char choice
[PPD_MAX_NAME
]; /* Option keyword (choice name) */
120 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
121 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
122 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
, mime_type_t
*filetype
,
124 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
125 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
126 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
127 static void add_printer_state_reasons(cupsd_client_t
*con
, cupsd_printer_t
*p
);
128 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
129 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
130 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
131 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
132 static void cancel_subscription(cupsd_client_t
*con
, int id
);
133 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
134 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
136 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
137 ipp_tag_t group
, int quickcopy
);
138 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
, const char *name
);
139 static int copy_file(const char *from
, const char *to
);
140 static int copy_model(cupsd_client_t
*con
, const char *from
, const char *to
);
141 static void copy_job_attrs(cupsd_client_t
*con
,
144 static void copy_printer_attrs(cupsd_client_t
*con
,
145 cupsd_printer_t
*printer
,
147 static void copy_subscription_attrs(cupsd_client_t
*con
,
148 cupsd_subscription_t
*sub
,
150 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
151 static cups_array_t
*create_requested_array(ipp_t
*request
);
152 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
153 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
154 static void get_default(cupsd_client_t
*con
);
155 static void get_devices(cupsd_client_t
*con
);
156 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
157 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
158 static void get_notifications(cupsd_client_t
*con
, int id
);
159 static void get_ppds(cupsd_client_t
*con
);
160 static void get_printers(cupsd_client_t
*con
, int type
);
161 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
162 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
163 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
164 static const char *get_username(cupsd_client_t
*con
);
165 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
166 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
167 static int ppd_add_default(const char *option
, const char *choice
,
168 int num_defaults
, ppd_default_t
**defaults
);
169 static int ppd_parse_line(const char *line
, char *option
, int olen
,
170 char *choice
, int clen
);
171 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
172 static void read_ps_job_ticket(cupsd_client_t
*con
);
173 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
174 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
175 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
176 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
177 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
);
178 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
179 static void send_http_error(cupsd_client_t
*con
, http_status_t status
);
180 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
181 const char *message
, ...)
183 __attribute__ ((__format__ (__printf__
, 3, 4)))
184 # endif /* __GNUC__ */
186 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
187 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
189 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
190 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
191 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
192 static int validate_name(const char *name
);
193 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
194 const char *owner
, char *username
,
199 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request...
202 int /* O - 1 on success, 0 on failure */
203 cupsdProcessIPPRequest(
204 cupsd_client_t
*con
) /* I - Client connection */
206 ipp_tag_t group
; /* Current group tag */
207 ipp_attribute_t
*attr
; /* Current attribute */
208 ipp_attribute_t
*charset
; /* Character set attribute */
209 ipp_attribute_t
*language
; /* Language attribute */
210 ipp_attribute_t
*uri
; /* Printer URI attribute */
211 ipp_attribute_t
*username
; /* requesting-user-name attr */
212 int sub_id
; /* Subscription ID */
215 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
216 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
217 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
220 * First build an empty response message for this request...
223 con
->response
= ippNew();
225 con
->response
->request
.status
.version
[0] = con
->request
->request
.op
.version
[0];
226 con
->response
->request
.status
.version
[1] = con
->request
->request
.op
.version
[1];
227 con
->response
->request
.status
.request_id
= con
->request
->request
.op
.request_id
;
230 * Then validate the request header and required attributes...
233 if (con
->request
->request
.any
.version
[0] != 1)
236 * Return an error, since we only support IPP 1.x.
239 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
240 "%04X %s Bad request version number %d.%d",
241 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
242 con
->request
->request
.any
.version
[0],
243 con
->request
->request
.any
.version
[1]);
245 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
246 _("Bad request version number %d.%d!"),
247 con
->request
->request
.any
.version
[0],
248 con
->request
->request
.any
.version
[1]);
250 else if (!con
->request
->attrs
)
252 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
253 "%04X %s No attributes in request",
254 IPP_BAD_REQUEST
, con
->http
.hostname
);
256 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
261 * Make sure that the attributes are provided in the correct order and
262 * don't repeat groups...
265 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
268 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
271 * Out of order; return an error...
274 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
275 "%04X %s Attribute groups are out of order",
276 IPP_BAD_REQUEST
, con
->http
.hostname
);
278 send_ipp_status(con
, IPP_BAD_REQUEST
,
279 _("Attribute groups are out of order (%x < %x)!"),
280 attr
->group_tag
, group
);
284 group
= attr
->group_tag
;
289 * Then make sure that the first three attributes are:
292 * attributes-natural-language
293 * printer-uri/job-uri
296 attr
= con
->request
->attrs
;
297 if (attr
&& !strcmp(attr
->name
, "attributes-charset") &&
298 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
306 if (attr
&& !strcmp(attr
->name
, "attributes-natural-language") &&
307 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
312 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
313 IPP_TAG_URI
)) != NULL
)
315 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
316 IPP_TAG_URI
)) != NULL
)
322 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
323 "attributes-charset", NULL
, charset
->values
[0].string
.text
);
325 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
326 "attributes-charset", NULL
, DefaultCharset
);
329 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
330 "attributes-natural-language", NULL
,
331 language
->values
[0].string
.text
);
333 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
334 "attributes-natural-language", NULL
, DefaultLanguage
);
336 if (!charset
|| !language
||
338 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
339 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
340 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
341 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
342 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
345 * Return an error, since attributes-charset,
346 * attributes-natural-language, and printer-uri/job-uri are required
347 * for all operations.
352 cupsdLogMessage(CUPSD_LOG_ERROR
,
353 "Missing attributes-charset attribute!");
355 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
356 "%04X %s Missing attributes-charset attribute",
357 IPP_BAD_REQUEST
, con
->http
.hostname
);
362 cupsdLogMessage(CUPSD_LOG_ERROR
,
363 "Missing attributes-natural-language attribute!");
365 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
366 "%04X %s Missing attributes-natural-language attribute",
367 IPP_BAD_REQUEST
, con
->http
.hostname
);
372 cupsdLogMessage(CUPSD_LOG_ERROR
,
373 "Missing printer-uri or job-uri attribute!");
375 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
376 "%04X %s Missing printer-uri or job-uri attribute",
377 IPP_BAD_REQUEST
, con
->http
.hostname
);
380 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
382 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
383 cupsdLogMessage(CUPSD_LOG_DEBUG
,
384 "attr \"%s\": group_tag = %x, value_tag = %x",
385 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
388 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
390 send_ipp_status(con
, IPP_BAD_REQUEST
,
391 _("Missing required attributes!"));
396 * OK, all the checks pass so far; make sure requesting-user-name is
397 * not "root" from a remote host...
400 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
401 IPP_TAG_NAME
)) != NULL
)
404 * Check for root user...
407 if (!strcmp(username
->values
[0].string
.text
, "root") &&
408 strcasecmp(con
->http
.hostname
, "localhost") &&
409 strcmp(con
->username
, "root"))
412 * Remote unauthenticated user masquerading as local root...
415 _cups_sp_free(username
->values
[0].string
.text
);
416 username
->values
[0].string
.text
= _cups_sp_alloc(RemoteRoot
);
420 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
421 IPP_TAG_INTEGER
)) != NULL
)
422 sub_id
= attr
->values
[0].integer
;
427 * Then try processing the operation...
431 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
432 "cupsdProcessIPPRequest: URI=\"%s\"",
433 uri
->values
[0].string
.text
);
435 switch (con
->request
->request
.op
.operation_id
)
441 case IPP_VALIDATE_JOB
:
442 validate_job(con
, uri
);
445 case IPP_CREATE_JOB
:
446 create_job(con
, uri
);
449 case IPP_SEND_DOCUMENT
:
450 send_document(con
, uri
);
453 case IPP_CANCEL_JOB
:
454 cancel_job(con
, uri
);
457 case IPP_GET_JOB_ATTRIBUTES
:
458 get_job_attrs(con
, uri
);
465 case IPP_GET_PRINTER_ATTRIBUTES
:
466 get_printer_attrs(con
, uri
);
473 case IPP_RELEASE_JOB
:
474 release_job(con
, uri
);
477 case IPP_RESTART_JOB
:
478 restart_job(con
, uri
);
481 case IPP_PAUSE_PRINTER
:
482 stop_printer(con
, uri
);
485 case IPP_RESUME_PRINTER
:
486 start_printer(con
, uri
);
489 case IPP_PURGE_JOBS
:
490 cancel_all_jobs(con
, uri
);
493 case IPP_SET_JOB_ATTRIBUTES
:
494 set_job_attrs(con
, uri
);
497 case CUPS_GET_DEFAULT
:
501 case CUPS_GET_PRINTERS
:
502 get_printers(con
, 0);
505 case CUPS_GET_CLASSES
:
506 get_printers(con
, CUPS_PRINTER_CLASS
);
509 case CUPS_ADD_PRINTER
:
510 add_printer(con
, uri
);
513 case CUPS_DELETE_PRINTER
:
514 delete_printer(con
, uri
);
517 case CUPS_ADD_CLASS
:
521 case CUPS_DELETE_CLASS
:
522 delete_printer(con
, uri
);
525 case CUPS_ACCEPT_JOBS
:
526 case IPP_ENABLE_PRINTER
:
527 accept_jobs(con
, uri
);
530 case CUPS_REJECT_JOBS
:
531 case IPP_DISABLE_PRINTER
:
532 reject_jobs(con
, uri
);
535 case CUPS_SET_DEFAULT
:
536 set_default(con
, uri
);
539 case CUPS_GET_DEVICES
:
551 case CUPS_AUTHENTICATE_JOB
:
552 authenticate_job(con
, uri
);
555 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
556 case IPP_CREATE_JOB_SUBSCRIPTION
:
557 create_subscription(con
, uri
);
560 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
561 get_subscription_attrs(con
, sub_id
);
564 case IPP_GET_SUBSCRIPTIONS
:
565 get_subscriptions(con
, uri
);
568 case IPP_RENEW_SUBSCRIPTION
:
569 renew_subscription(con
, sub_id
);
572 case IPP_CANCEL_SUBSCRIPTION
:
573 cancel_subscription(con
, sub_id
);
576 case IPP_GET_NOTIFICATIONS
:
577 get_notifications(con
, sub_id
);
581 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
582 "%04X %s Operation %04X (%s) not supported",
583 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
584 con
->request
->request
.op
.operation_id
,
585 ippOpString(con
->request
->request
.op
.operation_id
));
587 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
588 _("%s not supported!"),
589 ippOpString(con
->request
->request
.op
.operation_id
));
599 * Sending data from the scheduler...
602 cupsdLogMessage(CUPSD_LOG_DEBUG
,
603 "cupsdProcessIPPRequest: %d status_code=%x (%s)",
604 con
->http
.fd
, con
->response
->request
.status
.status_code
,
605 ippErrorString(con
->response
->request
.status
.status_code
));
607 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp"))
609 if (con
->http
.version
== HTTP_1_1
)
611 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
613 httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n");
617 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
618 con
->http
.data_remaining
= ippLength(con
->response
);
620 if (con
->http
.data_remaining
< INT_MAX
)
621 con
->http
._data_remaining
= con
->http
.data_remaining
;
623 con
->http
._data_remaining
= INT_MAX
;
625 httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
626 CUPS_LLCAST con
->http
.data_remaining
);
629 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
630 "cupsdProcessIPPRequest: Adding fd %d to OutputSet...",
633 FD_SET(con
->http
.fd
, OutputSet
);
636 * Tell the caller the response header was sent successfully...
644 * Tell the caller the response header could not be sent...
653 * Sending data from a subprocess like cups-deviced; tell the caller
654 * everything is A-OK so far...
663 * 'accept_jobs()' - Accept print jobs to a printer.
667 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
668 ipp_attribute_t
*uri
) /* I - Printer or class URI */
670 http_status_t status
; /* Policy status */
671 cups_ptype_t dtype
; /* Destination type (printer or class) */
672 char method
[HTTP_MAX_URI
], /* Method portion of URI */
673 username
[HTTP_MAX_URI
], /* Username portion of URI */
674 host
[HTTP_MAX_URI
], /* Host portion of URI */
675 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
676 int port
; /* Port portion of URI */
677 const char *name
; /* Printer name */
678 cupsd_printer_t
*printer
; /* Printer data */
681 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
682 con
->http
.fd
, uri
->values
[0].string
.text
);
685 * Is the destination valid?
688 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
689 sizeof(method
), username
, sizeof(username
), host
,
690 sizeof(host
), &port
, resource
, sizeof(resource
));
692 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
698 send_ipp_status(con
, IPP_NOT_FOUND
,
699 _("The printer or class was not found."));
707 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
709 send_http_error(con
, status
);
714 * Accept jobs sent to the printer...
717 printer
->accepting
= 1;
718 printer
->state_message
[0] = '\0';
720 cupsdAddPrinterHistory(printer
);
722 if (dtype
& CUPS_PRINTER_CLASS
)
723 cupsdSaveAllClasses();
725 cupsdSaveAllPrinters();
727 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" now accepting jobs (\"%s\").", name
,
731 * Everything was ok, so return OK status...
734 con
->response
->request
.status
.status_code
= IPP_OK
;
739 * 'add_class()' - Add a class to the system.
743 add_class(cupsd_client_t
*con
, /* I - Client connection */
744 ipp_attribute_t
*uri
) /* I - URI of class */
746 http_status_t status
; /* Policy status */
747 int i
; /* Looping var */
748 char method
[HTTP_MAX_URI
], /* Method portion of URI */
749 username
[HTTP_MAX_URI
], /* Username portion of URI */
750 host
[HTTP_MAX_URI
], /* Host portion of URI */
751 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
752 int port
; /* Port portion of URI */
753 cupsd_printer_t
*pclass
, /* Class */
754 *member
; /* Member printer/class */
755 cups_ptype_t dtype
; /* Destination type */
756 const char *dest
; /* Printer or class name */
757 ipp_attribute_t
*attr
; /* Printer attribute */
758 int modify
; /* Non-zero if we just modified */
759 int need_restart_job
; /* Need to restart job? */
762 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
763 con
->http
.fd
, uri
->values
[0].string
.text
);
766 * Do we have a valid URI?
769 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
770 sizeof(method
), username
, sizeof(username
), host
,
771 sizeof(host
), &port
, resource
, sizeof(resource
));
774 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
777 * No, return an error...
780 send_ipp_status(con
, IPP_BAD_REQUEST
,
781 _("The printer-uri must be of the form "
782 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
787 * Do we have a valid printer name?
790 if (!validate_name(resource
+ 9))
793 * No, return an error...
796 send_ipp_status(con
, IPP_BAD_REQUEST
,
797 _("The printer-uri \"%s\" contains invalid characters."),
798 uri
->values
[0].string
.text
);
806 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
808 send_http_error(con
, status
);
813 * See if the class already exists; if not, create a new class...
816 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
819 * Class doesn't exist; see if we have a printer of the same name...
822 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
823 !(pclass
->type
& CUPS_PRINTER_REMOTE
))
826 * Yes, return an error...
829 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
830 _("A printer named \"%s\" already exists!"),
836 * No, add the pclass...
839 pclass
= cupsdAddClass(resource
+ 9);
842 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
845 * Rename the implicit class to "AnyClass" or remove it...
848 if (ImplicitAnyClasses
)
850 cupsArrayRemove(Printers
, pclass
);
851 cupsdSetStringf(&pclass
->name
, "Any%s", resource
+ 9);
852 cupsArrayAdd(Printers
, pclass
);
855 cupsdDeletePrinter(pclass
, 1);
858 * Add the class as a new local class...
861 pclass
= cupsdAddClass(resource
+ 9);
864 else if (pclass
->type
& CUPS_PRINTER_REMOTE
)
867 * Rename the remote class to "Class"...
870 cupsdDeletePrinterFilters(pclass
);
871 cupsArrayRemove(Printers
, pclass
);
872 cupsdSetStringf(&pclass
->name
, "%s@%s", resource
+ 9, pclass
->hostname
);
873 cupsdSetPrinterAttrs(pclass
);
874 cupsArrayAdd(Printers
, pclass
);
877 * Add the class as a new local class...
880 pclass
= cupsdAddClass(resource
+ 9);
887 * Look for attributes and copy them over as needed...
890 need_restart_job
= 0;
892 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
893 IPP_TAG_TEXT
)) != NULL
)
894 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
896 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
897 IPP_TAG_TEXT
)) != NULL
)
898 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
900 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
901 IPP_TAG_BOOLEAN
)) != NULL
)
903 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-is-accepting-jobs to %d (was %d.)",
904 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
906 pclass
->accepting
= attr
->values
[0].boolean
;
907 cupsdAddPrinterHistory(pclass
);
910 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
911 IPP_TAG_BOOLEAN
)) != NULL
)
913 if (pclass
->shared
&& !attr
->values
[0].boolean
)
914 cupsdSendBrowseDelete(pclass
);
916 cupsdLogMessage(CUPSD_LOG_INFO
,
917 "Setting %s printer-is-shared to %d (was %d.)",
918 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
920 pclass
->shared
= attr
->values
[0].boolean
;
923 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
924 IPP_TAG_ENUM
)) != NULL
)
926 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
927 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
929 send_ipp_status(con
, IPP_BAD_REQUEST
,
930 _("Attempt to set %s printer-state to bad value %d!"),
931 pclass
->name
, attr
->values
[0].integer
);
935 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)", pclass
->name
,
936 attr
->values
[0].integer
, pclass
->state
);
938 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
939 cupsdStopPrinter(pclass
, 0);
942 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
943 need_restart_job
= 1;
946 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
947 IPP_TAG_TEXT
)) != NULL
)
949 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
950 sizeof(pclass
->state_message
));
951 cupsdAddPrinterHistory(pclass
);
953 if ((attr
= ippFindAttribute(con
->request
, "job-sheets-default",
954 IPP_TAG_ZERO
)) != NULL
&&
957 cupsdSetString(&pclass
->job_sheets
[0], attr
->values
[0].string
.text
);
958 if (attr
->num_values
> 1)
959 cupsdSetString(&pclass
->job_sheets
[1], attr
->values
[1].string
.text
);
961 cupsdSetString(&pclass
->job_sheets
[1], "none");
963 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name-allowed",
964 IPP_TAG_ZERO
)) != NULL
)
966 cupsdFreePrinterUsers(pclass
);
968 pclass
->deny_users
= 0;
969 if (attr
->value_tag
== IPP_TAG_NAME
&&
970 (attr
->num_values
> 1 ||
971 strcmp(attr
->values
[0].string
.text
, "all")))
972 for (i
= 0; i
< attr
->num_values
; i
++)
973 cupsdAddPrinterUser(pclass
, attr
->values
[i
].string
.text
);
975 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name-denied",
976 IPP_TAG_ZERO
)) != NULL
)
978 cupsdFreePrinterUsers(pclass
);
980 pclass
->deny_users
= 1;
981 if (attr
->value_tag
== IPP_TAG_NAME
&&
982 (attr
->num_values
> 1 ||
983 strcmp(attr
->values
[0].string
.text
, "none")))
984 for (i
= 0; i
< attr
->num_values
; i
++)
985 cupsdAddPrinterUser(pclass
, attr
->values
[i
].string
.text
);
987 if ((attr
= ippFindAttribute(con
->request
, "job-quota-period",
988 IPP_TAG_INTEGER
)) != NULL
)
990 cupsdLogMessage(CUPSD_LOG_DEBUG
,
991 "add_class: Setting job-quota-period to %d...",
992 attr
->values
[0].integer
);
993 cupsdFreeQuotas(pclass
);
994 pclass
->quota_period
= attr
->values
[0].integer
;
996 if ((attr
= ippFindAttribute(con
->request
, "job-k-limit",
997 IPP_TAG_INTEGER
)) != NULL
)
999 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1000 "add_class: Setting job-k-limit to %d...",
1001 attr
->values
[0].integer
);
1002 cupsdFreeQuotas(pclass
);
1003 pclass
->k_limit
= attr
->values
[0].integer
;
1005 if ((attr
= ippFindAttribute(con
->request
, "job-page-limit",
1006 IPP_TAG_INTEGER
)) != NULL
)
1008 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1009 "add_class: Setting job-page-limit to %d...",
1010 attr
->values
[0].integer
);
1011 cupsdFreeQuotas(pclass
);
1012 pclass
->page_limit
= attr
->values
[0].integer
;
1014 if ((attr
= ippFindAttribute(con
->request
, "printer-op-policy",
1015 IPP_TAG_NAME
)) != NULL
)
1017 cupsd_policy_t
*p
; /* Policy */
1020 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
1022 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1023 "add_class: Setting printer-op-policy to \"%s\"...",
1024 attr
->values
[0].string
.text
);
1025 cupsdSetString(&pclass
->op_policy
, attr
->values
[0].string
.text
);
1026 pclass
->op_policy_ptr
= p
;
1030 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1031 _("add_class: Unknown printer-op-policy \"%s\"."),
1032 attr
->values
[0].string
.text
);
1036 if ((attr
= ippFindAttribute(con
->request
, "printer-error-policy",
1037 IPP_TAG_NAME
)) != NULL
)
1039 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
1040 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
1041 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
1043 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1044 _("add_class: Unknown printer-error-policy \"%s\"."),
1045 attr
->values
[0].string
.text
);
1049 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1050 "add_class: Setting printer-error-policy to \"%s\"...",
1051 attr
->values
[0].string
.text
);
1052 cupsdSetString(&pclass
->error_policy
, attr
->values
[0].string
.text
);
1054 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
1055 IPP_TAG_URI
)) != NULL
)
1058 * Clear the printer array as needed...
1061 need_restart_job
= 1;
1063 if (pclass
->num_printers
> 0)
1065 free(pclass
->printers
);
1066 pclass
->num_printers
= 0;
1070 * Add each printer or class that is listed...
1073 for (i
= 0; i
< attr
->num_values
; i
++)
1076 * Search for the printer or class URI...
1079 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[i
].string
.text
, method
,
1080 sizeof(method
), username
, sizeof(username
), host
,
1081 sizeof(host
), &port
, resource
, sizeof(resource
));
1083 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &member
)) == NULL
)
1089 send_ipp_status(con
, IPP_NOT_FOUND
,
1090 _("The printer or class was not found."));
1095 * Add it to the class...
1098 cupsdAddPrinterToClass(pclass
, member
);
1103 * Update the printer class attributes and return...
1106 cupsdSetPrinterAttrs(pclass
);
1107 cupsdSaveAllClasses();
1109 if (need_restart_job
&& pclass
->job
)
1114 * Stop the current job and then restart it below...
1117 job
= (cupsd_job_t
*)pclass
->job
;
1119 cupsdStopJob(job
, 1);
1120 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1123 if (need_restart_job
)
1126 cupsdWritePrintcap();
1130 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1131 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1134 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1135 pclass
->name
, get_username(con
));
1139 cupsdAddPrinterHistory(pclass
);
1141 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1142 "New class \"%s\" added by \"%s\".", pclass
->name
,
1145 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1146 pclass
->name
, get_username(con
));
1149 con
->response
->request
.status
.status_code
= IPP_OK
;
1154 * 'add_file()' - Add a file to a job.
1157 static int /* O - 0 on success, -1 on error */
1158 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1159 cupsd_job_t
*job
, /* I - Job to add to */
1160 mime_type_t
*filetype
, /* I - Type of file */
1161 int compression
) /* I - Compression */
1163 mime_type_t
**filetypes
; /* New filetypes array... */
1164 int *compressions
; /* New compressions array... */
1167 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1168 "add_file(con=%p[%d], job=%d, filetype=%s/%s, compression=%d)",
1169 con
, con
->http
.fd
, job
->id
, filetype
->super
, filetype
->type
,
1173 * Add the file to the job...
1176 if (job
->num_files
== 0)
1178 compressions
= (int *)malloc(sizeof(int));
1179 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1183 compressions
= (int *)realloc(job
->compressions
,
1184 (job
->num_files
+ 1) * sizeof(int));
1185 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1186 (job
->num_files
+ 1) *
1187 sizeof(mime_type_t
*));
1190 if (!compressions
|| !filetypes
)
1192 cupsdCancelJob(job
, 1);
1194 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1195 _("Unable to allocate memory for file types!"));
1199 job
->compressions
= compressions
;
1200 job
->compressions
[job
->num_files
] = compression
;
1201 job
->filetypes
= filetypes
;
1202 job
->filetypes
[job
->num_files
] = filetype
;
1211 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1212 * upon the job and printer state...
1216 add_job_state_reasons(
1217 cupsd_client_t
*con
, /* I - Client connection */
1218 cupsd_job_t
*job
) /* I - Job info */
1220 cupsd_printer_t
*dest
; /* Destination printer */
1223 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1224 con
, con
->http
.fd
, job
? job
->id
: 0);
1226 switch (job
? job
->state
->values
[0].integer
: IPP_JOB_CANCELLED
)
1228 case IPP_JOB_PENDING
:
1229 if (job
->dtype
& CUPS_PRINTER_CLASS
)
1230 dest
= cupsdFindClass(job
->dest
);
1232 dest
= cupsdFindPrinter(job
->dest
);
1234 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1235 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1236 "job-state-reasons", NULL
, "printer-stopped");
1238 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1239 "job-state-reasons", NULL
, "none");
1243 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1244 IPP_TAG_KEYWORD
) != NULL
||
1245 ippFindAttribute(job
->attrs
, "job-hold-until",
1246 IPP_TAG_NAME
) != NULL
)
1247 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1248 "job-state-reasons", NULL
, "job-hold-until-specified");
1250 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1251 "job-state-reasons", NULL
, "job-incoming");
1254 case IPP_JOB_PROCESSING
:
1255 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1256 "job-state-reasons", NULL
, "job-printing");
1259 case IPP_JOB_STOPPED
:
1260 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1261 "job-state-reasons", NULL
, "job-stopped");
1264 case IPP_JOB_CANCELLED
:
1265 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1266 "job-state-reasons", NULL
, "job-canceled-by-user");
1269 case IPP_JOB_ABORTED
:
1270 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1271 "job-state-reasons", NULL
, "aborted-by-system");
1274 case IPP_JOB_COMPLETED
:
1275 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1276 "job-state-reasons", NULL
, "job-completed-successfully");
1283 * 'add_job_subscriptions()' - Add any subcriptions for a job.
1287 add_job_subscriptions(
1288 cupsd_client_t
*con
, /* I - Client connection */
1289 cupsd_job_t
*job
) /* I - Newly created job */
1291 int i
; /* Looping var */
1292 ipp_attribute_t
*prev
, /* Previous attribute */
1293 *next
, /* Next attribute */
1294 *attr
; /* Current attribute */
1295 cupsd_subscription_t
*sub
; /* Subscription object */
1296 const char *recipient
, /* notify-recipient-uri */
1297 *pullmethod
; /* notify-pull-method */
1298 ipp_attribute_t
*user_data
; /* notify-user-data */
1299 int interval
; /* notify-time-interval */
1300 unsigned mask
; /* notify-events */
1304 * Find the first subscription group attribute; return if we have
1308 for (attr
= job
->attrs
->attrs
, prev
= NULL
;
1310 prev
= attr
, attr
= attr
->next
)
1311 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1318 * Process the subscription attributes in the request...
1327 mask
= CUPSD_EVENT_NONE
;
1329 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1331 if (!strcmp(attr
->name
, "notify-recipient") &&
1332 attr
->value_tag
== IPP_TAG_URI
)
1333 recipient
= attr
->values
[0].string
.text
;
1334 else if (!strcmp(attr
->name
, "notify-pull-method") &&
1335 attr
->value_tag
== IPP_TAG_KEYWORD
)
1336 pullmethod
= attr
->values
[0].string
.text
;
1337 else if (!strcmp(attr
->name
, "notify-charset") &&
1338 attr
->value_tag
== IPP_TAG_CHARSET
&&
1339 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
1340 strcmp(attr
->values
[0].string
.text
, "utf-8"))
1342 send_ipp_status(con
, IPP_CHARSET
,
1343 _("Character set \"%s\" not supported!"),
1344 attr
->values
[0].string
.text
);
1347 else if (!strcmp(attr
->name
, "notify-natural-language") &&
1348 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
1349 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
1351 send_ipp_status(con
, IPP_CHARSET
,
1352 _("Language \"%s\" not supported!"),
1353 attr
->values
[0].string
.text
);
1356 else if (!strcmp(attr
->name
, "notify-user-data") &&
1357 attr
->value_tag
== IPP_TAG_STRING
)
1359 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
1361 send_ipp_status(con
, IPP_REQUEST_VALUE
,
1362 _("The notify-user-data value is too large "
1363 "(%d > 63 octets)!"),
1364 attr
->values
[0].unknown
.length
);
1370 else if (!strcmp(attr
->name
, "notify-events") &&
1371 attr
->value_tag
== IPP_TAG_KEYWORD
)
1373 for (i
= 0; i
< attr
->num_values
; i
++)
1374 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
1376 else if (!strcmp(attr
->name
, "notify-lease-duration"))
1378 send_ipp_status(con
, IPP_BAD_REQUEST
,
1379 _("The notify-lease-duration attribute cannot be "
1380 "used with job subscriptions."));
1383 else if (!strcmp(attr
->name
, "notify-time-interval") &&
1384 attr
->value_tag
== IPP_TAG_INTEGER
)
1385 interval
= attr
->values
[0].integer
;
1390 if (!recipient
&& !pullmethod
)
1393 if (mask
== CUPSD_EVENT_NONE
)
1394 mask
= CUPSD_EVENT_JOB_COMPLETED
;
1396 sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
, recipient
,
1399 sub
->interval
= interval
;
1401 cupsdSetString(&sub
->owner
, job
->username
);
1405 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
1406 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
1407 sub
->user_data_len
);
1410 ippAddSeparator(con
->response
);
1411 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
1412 "notify-subscription-id", sub
->id
);
1418 cupsdSaveAllSubscriptions();
1421 * Remove all of the subscription attributes from the job request...
1424 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
1428 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
1429 attr
->group_tag
== IPP_TAG_ZERO
)
1432 * Free and remove this attribute...
1435 _ipp_free_attr(attr
);
1440 job
->attrs
->attrs
= next
;
1446 job
->attrs
->last
= prev
;
1447 job
->attrs
->current
= prev
;
1452 * 'add_printer()' - Add a printer to the system.
1456 add_printer(cupsd_client_t
*con
, /* I - Client connection */
1457 ipp_attribute_t
*uri
) /* I - URI of printer */
1459 http_status_t status
; /* Policy status */
1460 int i
; /* Looping var */
1461 char method
[HTTP_MAX_URI
], /* Method portion of URI */
1462 username
[HTTP_MAX_URI
], /* Username portion of URI */
1463 host
[HTTP_MAX_URI
], /* Host portion of URI */
1464 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1465 int port
; /* Port portion of URI */
1466 cupsd_printer_t
*printer
; /* Printer/class */
1467 ipp_attribute_t
*attr
; /* Printer attribute */
1468 cups_file_t
*fp
; /* Script/PPD file */
1469 char line
[1024]; /* Line from file... */
1470 char srcfile
[1024], /* Source Script/PPD file */
1471 dstfile
[1024]; /* Destination Script/PPD file */
1472 int modify
; /* Non-zero if we are modifying */
1473 int need_restart_job
; /* Need to restart job? */
1476 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
1477 con
->http
.fd
, uri
->values
[0].string
.text
);
1480 * Do we have a valid URI?
1483 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
1484 sizeof(method
), username
, sizeof(username
), host
,
1485 sizeof(host
), &port
, resource
, sizeof(resource
));
1487 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
1490 * No, return an error...
1493 send_ipp_status(con
, IPP_BAD_REQUEST
,
1494 _("The printer-uri must be of the form "
1495 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
1500 * Do we have a valid printer name?
1503 if (!validate_name(resource
+ 10))
1506 * No, return an error...
1509 send_ipp_status(con
, IPP_BAD_REQUEST
,
1510 _("The printer-uri \"%s\" contains invalid characters."),
1511 uri
->values
[0].string
.text
);
1519 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
1521 send_http_error(con
, status
);
1526 * See if the printer already exists; if not, create a new printer...
1529 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
1532 * Printer doesn't exist; see if we have a class of the same name...
1535 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
1536 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1539 * Yes, return an error...
1542 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1543 _("A class named \"%s\" already exists!"),
1549 * No, add the printer...
1552 printer
= cupsdAddPrinter(resource
+ 10);
1555 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
1558 * Rename the implicit printer to "AnyPrinter" or delete it...
1561 if (ImplicitAnyClasses
)
1563 cupsArrayRemove(Printers
, printer
);
1564 cupsdSetStringf(&printer
->name
, "Any%s", resource
+ 10);
1565 cupsArrayAdd(Printers
, printer
);
1568 cupsdDeletePrinter(printer
, 1);
1571 * Add the printer as a new local printer...
1574 printer
= cupsdAddPrinter(resource
+ 10);
1577 else if (printer
->type
& CUPS_PRINTER_REMOTE
)
1580 * Rename the remote printer to "Printer@server"...
1583 cupsdDeletePrinterFilters(printer
);
1584 cupsArrayRemove(Printers
, printer
);
1585 cupsdSetStringf(&printer
->name
, "%s@%s", resource
+ 10, printer
->hostname
);
1586 cupsdSetPrinterAttrs(printer
);
1587 cupsArrayAdd(Printers
, printer
);
1590 * Add the printer as a new local printer...
1593 printer
= cupsdAddPrinter(resource
+ 10);
1600 * Look for attributes and copy them over as needed...
1603 need_restart_job
= 0;
1605 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
1606 IPP_TAG_TEXT
)) != NULL
)
1607 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
1609 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
1610 IPP_TAG_TEXT
)) != NULL
)
1611 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
1613 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
1614 IPP_TAG_URI
)) != NULL
)
1617 * Do we have a valid device URI?
1620 need_restart_job
= 1;
1622 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[0].string
.text
, method
,
1623 sizeof(method
), username
, sizeof(username
), host
,
1624 sizeof(host
), &port
, resource
, sizeof(resource
));
1626 if (!strcmp(method
, "file"))
1629 * See if the administrator has enabled file devices...
1632 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
1635 * File devices are disabled and the URL is not file:/dev/null...
1638 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1639 _("File device URIs have been disabled! "
1640 "To enable, see the FileDevice directive in "
1641 "\"%s/cupsd.conf\"."),
1649 * See if the backend exists and is executable...
1652 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, method
);
1653 if (access(srcfile
, X_OK
))
1656 * Could not find device in list!
1659 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
1660 attr
->values
[0].string
.text
);
1665 cupsdLogMessage(CUPSD_LOG_INFO
,
1666 "Setting %s device-uri to \"%s\" (was \"%s\".)",
1668 cupsdSanitizeURI(attr
->values
[0].string
.text
, line
,
1670 cupsdSanitizeURI(printer
->device_uri
, resource
,
1673 cupsdSetString(&printer
->device_uri
, attr
->values
[0].string
.text
);
1676 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
1677 IPP_TAG_KEYWORD
)) != NULL
)
1679 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
1682 need_restart_job
= 1;
1684 supported
= ippFindAttribute(printer
->attrs
, "port-monitor-supported",
1686 for (i
= 0; i
< supported
->num_values
; i
++)
1687 if (!strcmp(supported
->values
[i
].string
.text
,
1688 attr
->values
[0].string
.text
))
1691 if (i
>= supported
->num_values
)
1693 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
1694 attr
->values
[0].string
.text
);
1698 cupsdLogMessage(CUPSD_LOG_INFO
,
1699 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
1700 printer
->name
, attr
->values
[0].string
.text
,
1701 printer
->port_monitor
);
1703 if (strcmp(attr
->values
[0].string
.text
, "none"))
1704 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
1706 cupsdClearString(&printer
->port_monitor
);
1709 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
1710 IPP_TAG_BOOLEAN
)) != NULL
)
1712 cupsdLogMessage(CUPSD_LOG_INFO
,
1713 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
1714 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
1716 printer
->accepting
= attr
->values
[0].boolean
;
1717 cupsdAddPrinterHistory(printer
);
1720 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
1721 IPP_TAG_BOOLEAN
)) != NULL
)
1723 if (printer
->shared
&& !attr
->values
[0].boolean
)
1724 cupsdSendBrowseDelete(printer
);
1726 cupsdLogMessage(CUPSD_LOG_INFO
,
1727 "Setting %s printer-is-shared to %d (was %d.)",
1728 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
1730 printer
->shared
= attr
->values
[0].boolean
;
1733 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
1734 IPP_TAG_ENUM
)) != NULL
)
1736 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
1737 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
1739 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
1740 attr
->values
[0].integer
);
1744 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)", printer
->name
,
1745 attr
->values
[0].integer
, printer
->state
);
1747 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
1748 cupsdStopPrinter(printer
, 0);
1751 need_restart_job
= 1;
1752 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
1755 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
1756 IPP_TAG_TEXT
)) != NULL
)
1758 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
1759 sizeof(printer
->state_message
));
1760 cupsdAddPrinterHistory(printer
);
1762 if ((attr
= ippFindAttribute(con
->request
, "job-sheets-default",
1763 IPP_TAG_ZERO
)) != NULL
&&
1766 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
1767 if (attr
->num_values
> 1)
1768 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
1770 cupsdSetString(&printer
->job_sheets
[1], "none");
1772 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name-allowed",
1773 IPP_TAG_ZERO
)) != NULL
)
1775 cupsdFreePrinterUsers(printer
);
1777 printer
->deny_users
= 0;
1778 if (attr
->value_tag
== IPP_TAG_NAME
&&
1779 (attr
->num_values
> 1 ||
1780 strcmp(attr
->values
[0].string
.text
, "all")))
1781 for (i
= 0; i
< attr
->num_values
; i
++)
1782 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
1784 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name-denied",
1785 IPP_TAG_ZERO
)) != NULL
)
1787 cupsdFreePrinterUsers(printer
);
1789 printer
->deny_users
= 1;
1790 if (attr
->value_tag
== IPP_TAG_NAME
&&
1791 (attr
->num_values
> 1 ||
1792 strcmp(attr
->values
[0].string
.text
, "none")))
1793 for (i
= 0; i
< attr
->num_values
; i
++)
1794 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
1796 if ((attr
= ippFindAttribute(con
->request
, "job-quota-period",
1797 IPP_TAG_INTEGER
)) != NULL
)
1799 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
1800 attr
->values
[0].integer
);
1801 cupsdFreeQuotas(printer
);
1802 printer
->quota_period
= attr
->values
[0].integer
;
1804 if ((attr
= ippFindAttribute(con
->request
, "job-k-limit",
1805 IPP_TAG_INTEGER
)) != NULL
)
1807 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
1808 attr
->values
[0].integer
);
1809 cupsdFreeQuotas(printer
);
1810 printer
->k_limit
= attr
->values
[0].integer
;
1812 if ((attr
= ippFindAttribute(con
->request
, "job-page-limit",
1813 IPP_TAG_INTEGER
)) != NULL
)
1815 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
1816 attr
->values
[0].integer
);
1817 cupsdFreeQuotas(printer
);
1818 printer
->page_limit
= attr
->values
[0].integer
;
1820 if ((attr
= ippFindAttribute(con
->request
, "printer-op-policy",
1821 IPP_TAG_NAME
)) != NULL
)
1823 cupsd_policy_t
*p
; /* Policy */
1826 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
1828 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1829 "Setting printer-op-policy to \"%s\"...",
1830 attr
->values
[0].string
.text
);
1831 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
1832 printer
->op_policy_ptr
= p
;
1836 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1837 _("Unknown printer-op-policy \"%s\"."),
1838 attr
->values
[0].string
.text
);
1842 if ((attr
= ippFindAttribute(con
->request
, "printer-error-policy",
1843 IPP_TAG_NAME
)) != NULL
)
1845 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
1846 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
1847 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
1849 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1850 _("Unknown printer-error-policy \"%s\"."),
1851 attr
->values
[0].string
.text
);
1855 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1856 "Setting printer-error-policy to \"%s\"...",
1857 attr
->values
[0].string
.text
);
1858 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
1862 * See if we have all required attributes...
1865 if (!printer
->device_uri
)
1866 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
1869 * See if we have an interface script or PPD file attached to the request...
1874 need_restart_job
= 1;
1876 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
1878 if ((fp
= cupsFileOpen(srcfile
, "rb")))
1881 * Yes; get the first line from it...
1885 cupsFileGets(fp
, line
, sizeof(line
));
1889 * Then see what kind of file it is...
1892 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
1895 if (!strncmp(line
, "*PPD-Adobe", 10))
1898 * The new file is a PPD file, so remove any old interface script
1899 * that might be lying around...
1907 * This must be an interface script, so move the file over to the
1908 * interfaces directory and make it executable...
1911 if (copy_file(srcfile
, dstfile
))
1913 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1914 _("Unable to copy interface script - %s!"),
1920 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1921 "Copied interface script successfully!");
1922 chmod(dstfile
, 0755);
1926 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
1929 if (!strncmp(line
, "*PPD-Adobe", 10))
1932 * The new file is a PPD file, so move the file over to the
1933 * ppd directory and make it readable by all...
1936 if (copy_file(srcfile
, dstfile
))
1938 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1939 _("Unable to copy PPD file - %s!"),
1945 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1946 "Copied PPD file successfully!");
1947 chmod(dstfile
, 0644);
1953 * This must be an interface script, so remove any old PPD file that
1954 * may be lying around...
1961 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
1962 IPP_TAG_NAME
)) != NULL
)
1964 need_restart_job
= 1;
1966 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
1969 * Raw driver, remove any existing PPD or interface script files.
1972 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
1976 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
1986 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
1990 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
1993 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
1995 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2000 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2001 "Copied PPD file successfully!");
2002 chmod(dstfile
, 0644);
2008 * Update the printer attributes and return...
2011 cupsdSetPrinterAttrs(printer
);
2012 cupsdSaveAllPrinters();
2014 if (need_restart_job
&& printer
->job
)
2019 * Stop the current job and then restart it below...
2022 job
= (cupsd_job_t
*)printer
->job
;
2024 cupsdStopJob(job
, 1);
2025 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2028 if (need_restart_job
)
2031 cupsdWritePrintcap();
2035 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2036 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2039 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2040 printer
->name
, get_username(con
));
2044 cupsdAddPrinterHistory(printer
);
2046 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2047 "New printer \"%s\" added by \"%s\".", printer
->name
,
2050 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2051 printer
->name
, get_username(con
));
2054 con
->response
->request
.status
.status_code
= IPP_OK
;
2059 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2060 * based upon the printer state...
2064 add_printer_state_reasons(
2065 cupsd_client_t
*con
, /* I - Client connection */
2066 cupsd_printer_t
*p
) /* I - Printer info */
2068 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2069 "add_printer_state_reasons(%p[%d], %p[%s])",
2070 con
, con
->http
.fd
, p
, p
->name
);
2072 if (p
->num_reasons
== 0)
2073 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2074 "printer-state-reasons", NULL
,
2075 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2077 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2078 "printer-state-reasons", p
->num_reasons
, NULL
,
2079 (const char * const *)p
->reasons
);
2084 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2085 * the specified printer or class.
2089 add_queued_job_count(
2090 cupsd_client_t
*con
, /* I - Client connection */
2091 cupsd_printer_t
*p
) /* I - Printer or class */
2093 int count
; /* Number of jobs on destination */
2096 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2097 con
, con
->http
.fd
, p
, p
->name
);
2099 count
= cupsdGetPrinterJobCount(p
->name
);
2101 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2102 "queued-job-count", count
);
2107 * 'authenticate_job()' - Set job authentication info.
2111 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2112 ipp_attribute_t
*uri
) /* I - Job URI */
2114 ipp_attribute_t
*attr
; /* Job-id attribute */
2115 int jobid
; /* Job ID */
2116 cupsd_job_t
*job
; /* Current job */
2117 char method
[HTTP_MAX_URI
],
2118 /* Method portion of URI */
2119 username
[HTTP_MAX_URI
],
2120 /* Username portion of URI */
2122 /* Host portion of URI */
2123 resource
[HTTP_MAX_URI
];
2124 /* Resource portion of URI */
2125 int port
; /* Port portion of URI */
2128 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2129 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
2132 * Start with "everything is OK" status...
2135 con
->response
->request
.status
.status_code
= IPP_OK
;
2138 * See if we have a job URI or a printer URI...
2141 if (!strcmp(uri
->name
, "printer-uri"))
2144 * Got a printer URI; see if we also have a job-id attribute...
2147 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2148 IPP_TAG_INTEGER
)) == NULL
)
2150 send_ipp_status(con
, IPP_BAD_REQUEST
,
2151 _("Got a printer-uri attribute but no job-id!"));
2155 jobid
= attr
->values
[0].integer
;
2160 * Got a job URI; parse it to get the job ID...
2163 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2164 sizeof(method
), username
, sizeof(username
), host
,
2165 sizeof(host
), &port
, resource
, sizeof(resource
));
2167 if (strncmp(resource
, "/jobs/", 6))
2173 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
2174 uri
->values
[0].string
.text
);
2178 jobid
= atoi(resource
+ 6);
2182 * See if the job exists...
2185 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2188 * Nope - return a "not found" error...
2191 send_ipp_status(con
, IPP_NOT_FOUND
,
2192 _("Job #%d does not exist!"), jobid
);
2197 * See if the job has been completed...
2200 if (job
->state
->values
[0].integer
!= IPP_JOB_HELD
)
2203 * Return a "not-possible" error...
2206 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2207 _("Job #%d is not held for authentication!"),
2213 * See if we have already authenticated...
2216 if (!con
->username
[0])
2218 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
2219 _("No authentication information provided!"));
2224 * See if the job is owned by the requesting user...
2227 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
2229 send_ipp_status(con
, IPP_FORBIDDEN
,
2230 _("You are not authorized to authenticate "
2231 "job #%d owned by \"%s\"!"),
2232 jobid
, job
->username
);
2237 * Save the authentication information for this job...
2240 save_auth_info(con
, job
);
2243 * Reset the job-hold-until value to "no-hold"...
2246 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
2247 IPP_TAG_KEYWORD
)) == NULL
)
2248 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
2252 attr
->value_tag
= IPP_TAG_KEYWORD
;
2253 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
2257 * Release the job and return...
2260 cupsdReleaseJob(job
);
2262 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was authenticated by \"%s\".", jobid
,
2268 * 'cancel_all_jobs()' - Cancel all print jobs.
2272 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
2273 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
2275 http_status_t status
; /* Policy status */
2276 const char *dest
; /* Destination */
2277 cups_ptype_t dtype
; /* Destination type */
2278 char method
[HTTP_MAX_URI
], /* Method portion of URI */
2279 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2280 host
[HTTP_MAX_URI
], /* Host portion of URI */
2281 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2282 int port
; /* Port portion of URI */
2283 ipp_attribute_t
*attr
; /* Attribute in request */
2284 const char *username
; /* Username */
2285 int purge
; /* Purge? */
2286 cupsd_printer_t
*printer
; /* Printer */
2289 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
2290 con
->http
.fd
, uri
->values
[0].string
.text
);
2293 * See if we have a printer URI...
2296 if (strcmp(uri
->name
, "printer-uri"))
2298 send_ipp_status(con
, IPP_BAD_REQUEST
,
2299 _("The printer-uri attribute is required!"));
2304 * Get the username (if any) for the jobs we want to cancel (only if
2305 * "my-jobs" is specified...
2308 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
2309 IPP_TAG_BOOLEAN
)) != NULL
&&
2310 attr
->values
[0].boolean
)
2312 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
2313 IPP_TAG_NAME
)) != NULL
)
2314 username
= attr
->values
[0].string
.text
;
2317 send_ipp_status(con
, IPP_BAD_REQUEST
,
2318 _("Missing requesting-user-name attribute!"));
2326 * Look for the "purge-jobs" attribute...
2329 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
2330 IPP_TAG_BOOLEAN
)) != NULL
)
2331 purge
= attr
->values
[0].boolean
;
2336 * And if the destination is valid...
2339 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2340 sizeof(method
), userpass
, sizeof(userpass
), host
,
2341 sizeof(host
), &port
, resource
, sizeof(resource
));
2343 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
2349 if (!strncmp(resource
, "/printers/", 10) ||
2350 !strncmp(resource
, "/classes/", 9))
2352 send_ipp_status(con
, IPP_NOT_FOUND
,
2353 _("The printer or class was not found."));
2356 else if (strcmp(resource
, "/printers/"))
2358 send_ipp_status(con
, IPP_NOT_FOUND
,
2359 _("The printer-uri \"%s\" is not valid."),
2360 uri
->values
[0].string
.text
);
2368 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2370 send_http_error(con
, status
);
2375 * Cancel all jobs on all printers...
2378 cupsdCancelJobs(NULL
, username
, purge
);
2380 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
2381 purge
? "purged" : "cancelled", get_username(con
));
2389 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
2391 send_http_error(con
, status
);
2396 * Cancel all of the jobs on the named printer...
2399 cupsdCancelJobs(dest
, username
, purge
);
2401 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
2402 dest
, purge
? "purged" : "cancelled", get_username(con
));
2405 con
->response
->request
.status
.status_code
= IPP_OK
;
2410 * 'cancel_job()' - Cancel a print job.
2414 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
2415 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
2417 ipp_attribute_t
*attr
; /* Current attribute */
2418 int jobid
; /* Job ID */
2419 char method
[HTTP_MAX_URI
], /* Method portion of URI */
2420 username
[HTTP_MAX_URI
], /* Username portion of URI */
2421 host
[HTTP_MAX_URI
], /* Host portion of URI */
2422 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2423 int port
; /* Port portion of URI */
2424 cupsd_job_t
*job
; /* Job information */
2425 const char *dest
; /* Destination */
2426 cups_ptype_t dtype
; /* Destination type (printer or class) */
2427 cupsd_printer_t
*printer
; /* Printer data */
2430 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
2431 con
->http
.fd
, uri
->values
[0].string
.text
);
2434 * See if we have a job URI or a printer URI...
2437 if (!strcmp(uri
->name
, "printer-uri"))
2440 * Got a printer URI; see if we also have a job-id attribute...
2443 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2444 IPP_TAG_INTEGER
)) == NULL
)
2446 send_ipp_status(con
, IPP_BAD_REQUEST
,
2447 _("Got a printer-uri attribute but no job-id!"));
2451 if ((jobid
= attr
->values
[0].integer
) == 0)
2454 * Find the current job on the specified printer...
2457 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2458 sizeof(method
), username
, sizeof(username
), host
,
2459 sizeof(host
), &port
, resource
, sizeof(resource
));
2461 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
2467 send_ipp_status(con
, IPP_NOT_FOUND
,
2468 _("The printer or class was not found."));
2473 * See if the printer is currently printing a job...
2477 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
2481 * No, see if there are any pending jobs...
2484 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2486 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2487 if (job
->state
->values
[0].integer
<= IPP_JOB_PROCESSING
&&
2488 !strcasecmp(job
->dest
, dest
))
2495 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
2505 * Got a job URI; parse it to get the job ID...
2508 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2509 sizeof(method
), username
, sizeof(username
), host
,
2510 sizeof(host
), &port
, resource
, sizeof(resource
));
2512 if (strncmp(resource
, "/jobs/", 6))
2518 send_ipp_status(con
, IPP_BAD_REQUEST
,
2519 _("Bad job-uri attribute \"%s\"!"),
2520 uri
->values
[0].string
.text
);
2524 jobid
= atoi(resource
+ 6);
2528 * See if the job exists...
2531 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2534 * Nope - return a "not found" error...
2537 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
2542 * See if the job is owned by the requesting user...
2545 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
2547 send_ipp_status(con
, IPP_FORBIDDEN
,
2548 _("You are not authorized to delete job #%d "
2549 "owned by \"%s\"!"),
2550 jobid
, job
->username
);
2555 * See if the job is already completed, cancelled, or aborted; if so,
2556 * we can't cancel...
2559 if (job
->state
->values
[0].integer
>= IPP_JOB_CANCELLED
)
2561 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2562 _("Job #%d is already %s - can\'t cancel."), jobid
,
2563 job
->state
->values
[0].integer
== IPP_JOB_CANCELLED
? "cancelled" :
2564 job
->state
->values
[0].integer
== IPP_JOB_ABORTED
? "aborted" :
2570 * Cancel the job and return...
2573 cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED
, job
->printer
, job
,
2574 "Job cancelled by \"%s\".", username
);
2576 cupsdCancelJob(job
, 0);
2579 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was cancelled by \"%s\".", jobid
,
2582 con
->response
->request
.status
.status_code
= IPP_OK
;
2587 * 'cancel_subscription()' - Cancel a subscription.
2591 cancel_subscription(
2592 cupsd_client_t
*con
, /* I - Client connection */
2593 int sub_id
) /* I - Subscription ID */
2599 * 'check_quotas()' - Check quotas for a printer and user.
2602 static int /* O - 1 if OK, 0 if not */
2603 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
2604 cupsd_printer_t
*p
) /* I - Printer or class */
2606 int i
; /* Looping var */
2607 char username
[33]; /* Username */
2608 cupsd_quota_t
*q
; /* Quota data */
2609 struct passwd
*pw
; /* User password data */
2612 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
2613 con
, con
->http
.fd
, p
, p
->name
);
2623 * Figure out who is printing...
2626 strlcpy(username
, get_username(con
), sizeof(username
));
2629 * Check global active job limits for printers and users...
2632 if (MaxJobsPerPrinter
)
2635 * Check if there are too many pending jobs on this printer...
2638 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
2640 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
2649 * Check if there are too many pending jobs for this user...
2652 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
2654 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
2661 * Check against users...
2664 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
2669 pw
= getpwnam(username
);
2672 for (i
= 0; i
< p
->num_users
; i
++)
2673 if (p
->users
[i
][0] == '@')
2676 * Check group membership...
2679 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
2682 else if (!strcasecmp(username
, p
->users
[i
]))
2685 if ((i
< p
->num_users
) == p
->deny_users
)
2687 cupsdLogMessage(CUPSD_LOG_INFO
,
2688 "Denying user \"%s\" access to printer \"%s\"...",
2698 if (p
->k_limit
|| p
->page_limit
)
2700 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
2702 cupsdLogMessage(CUPSD_LOG_ERROR
,
2703 "Unable to allocate quota data for user \"%s\"!",
2708 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
2709 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
2711 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
2718 * If we have gotten this far, we're done!
2726 * 'copy_attribute()' - Copy a single attribute.
2729 static ipp_attribute_t
* /* O - New attribute */
2731 ipp_t
*to
, /* O - Destination request/response */
2732 ipp_attribute_t
*attr
, /* I - Attribute to copy */
2733 int quickcopy
) /* I - Do a quick copy? */
2735 int i
; /* Looping var */
2736 ipp_attribute_t
*toattr
; /* Destination attribute */
2739 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2740 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
2741 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
2744 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
2747 toattr
= ippAddSeparator(to
);
2750 case IPP_TAG_INTEGER
:
2752 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
2753 attr
->name
, attr
->num_values
, NULL
);
2755 for (i
= 0; i
< attr
->num_values
; i
++)
2756 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
2759 case IPP_TAG_BOOLEAN
:
2760 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
2761 attr
->num_values
, NULL
);
2763 for (i
= 0; i
< attr
->num_values
; i
++)
2764 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
2767 case IPP_TAG_STRING
:
2770 case IPP_TAG_KEYWORD
:
2772 case IPP_TAG_URISCHEME
:
2773 case IPP_TAG_CHARSET
:
2774 case IPP_TAG_LANGUAGE
:
2775 case IPP_TAG_MIMETYPE
:
2776 toattr
= ippAddStrings(to
, attr
->group_tag
,
2777 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
2778 attr
->name
, attr
->num_values
, NULL
, NULL
);
2782 for (i
= 0; i
< attr
->num_values
; i
++)
2783 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
2787 for (i
= 0; i
< attr
->num_values
; i
++)
2788 toattr
->values
[i
].string
.text
= _cups_sp_alloc(attr
->values
[i
].string
.text
);
2793 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
2794 attr
->values
[0].date
);
2797 case IPP_TAG_RESOLUTION
:
2798 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
2799 attr
->num_values
, IPP_RES_PER_INCH
,
2802 for (i
= 0; i
< attr
->num_values
; i
++)
2804 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
2805 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
2806 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
2810 case IPP_TAG_RANGE
:
2811 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
2812 attr
->num_values
, NULL
, NULL
);
2814 for (i
= 0; i
< attr
->num_values
; i
++)
2816 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
2817 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
2821 case IPP_TAG_TEXTLANG
:
2822 case IPP_TAG_NAMELANG
:
2823 toattr
= ippAddStrings(to
, attr
->group_tag
,
2824 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
2825 attr
->name
, attr
->num_values
, NULL
, NULL
);
2829 for (i
= 0; i
< attr
->num_values
; i
++)
2831 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
2832 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
2837 for (i
= 0; i
< attr
->num_values
; i
++)
2840 toattr
->values
[i
].string
.charset
=
2841 _cups_sp_alloc(attr
->values
[i
].string
.charset
);
2843 toattr
->values
[i
].string
.charset
=
2844 toattr
->values
[0].string
.charset
;
2846 toattr
->values
[i
].string
.text
= _cups_sp_alloc(attr
->values
[i
].string
.text
);
2851 case IPP_TAG_BEGIN_COLLECTION
:
2852 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
2853 attr
->num_values
, NULL
);
2855 for (i
= 0; i
< attr
->num_values
; i
++)
2857 toattr
->values
[i
].collection
= ippNew();
2858 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
2859 NULL
, IPP_TAG_ZERO
, 0);
2864 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
2865 attr
->name
, attr
->num_values
, NULL
);
2867 for (i
= 0; i
< attr
->num_values
; i
++)
2869 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
2871 if (toattr
->values
[i
].unknown
.length
> 0)
2873 if ((toattr
->values
[i
].unknown
.data
=
2874 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
2875 toattr
->values
[i
].unknown
.length
= 0;
2877 memcpy(toattr
->values
[i
].unknown
.data
,
2878 attr
->values
[i
].unknown
.data
,
2879 toattr
->values
[i
].unknown
.length
);
2882 break; /* anti-compiler-warning-code */
2890 * 'copy_attrs()' - Copy attributes from one request to another.
2894 copy_attrs(ipp_t
*to
, /* I - Destination request */
2895 ipp_t
*from
, /* I - Source request */
2896 cups_array_t
*ra
, /* I - Requested attributes */
2897 ipp_tag_t group
, /* I - Group to copy */
2898 int quickcopy
) /* I - Do a quick copy? */
2900 ipp_attribute_t
*fromattr
; /* Source attribute */
2903 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2904 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
2905 to
, from
, ra
, group
, quickcopy
);
2910 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
2913 * Filter attributes as needed...
2916 if (group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
2917 fromattr
->group_tag
!= IPP_TAG_ZERO
&& !fromattr
->name
)
2920 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
2921 copy_attribute(to
, fromattr
, quickcopy
);
2927 * 'copy_banner()' - Copy a banner file to the requests directory for the
2931 static int /* O - Size of banner file in kbytes */
2932 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
2933 cupsd_job_t
*job
, /* I - Job information */
2934 const char *name
) /* I - Name of banner */
2936 int i
; /* Looping var */
2937 int kbytes
; /* Size of banner file in kbytes */
2938 char filename
[1024]; /* Job filename */
2939 cupsd_banner_t
*banner
; /* Pointer to banner */
2940 cups_file_t
*in
; /* Input file */
2941 cups_file_t
*out
; /* Output file */
2942 int ch
; /* Character from file */
2943 char attrname
[255], /* Name of attribute */
2944 *s
; /* Pointer into name */
2945 ipp_attribute_t
*attr
; /* Attribute */
2948 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_banner(%p[%d], %p[%d], %s)",
2949 con
, con
->http
.fd
, job
, job
->id
, name
? name
: "(null)");
2952 * Find the banner; return if not found or "none"...
2955 if (!name
|| !strcmp(name
, "none") ||
2956 (banner
= cupsdFindBanner(name
)) == NULL
)
2960 * Open the banner and job files...
2963 if (add_file(con
, job
, banner
->filetype
, 0))
2966 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
2968 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
2970 cupsdLogMessage(CUPSD_LOG_ERROR
,
2971 "copy_banner: Unable to create banner job file %s - %s",
2972 filename
, strerror(errno
));
2977 fchmod(cupsFileNumber(out
), 0640);
2978 fchown(cupsFileNumber(out
), RunUser
, Group
);
2981 * Try the localized banner file under the subdirectory...
2984 strlcpy(attrname
, con
->request
->attrs
->next
->values
[0].string
.text
,
2986 if (strlen(attrname
) > 2 && attrname
[2] == '-')
2989 * Convert ll-cc to ll_CC...
2993 attrname
[3] = toupper(attrname
[3] & 255);
2994 attrname
[4] = toupper(attrname
[4] & 255);
2997 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
3000 if (access(filename
, 0) && strlen(attrname
) > 2)
3003 * Wasn't able to find "ll_CC" locale file; try the non-national
3004 * localization banner directory.
3009 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
3013 if (access(filename
, 0))
3016 * Use the non-localized banner file.
3019 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
3022 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
3026 cupsdLogMessage(CUPSD_LOG_ERROR
,
3027 "copy_banner: Unable to open banner template file %s - %s",
3028 filename
, strerror(errno
));
3034 * Parse the file to the end...
3037 while ((ch
= cupsFileGetChar(in
)) != EOF
)
3041 * Get an attribute name...
3044 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
3045 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
3047 else if (s
< (attrname
+ sizeof(attrname
) - 1))
3057 * Ignore { followed by stuff that is not an attribute name...
3060 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
3065 * See if it is defined...
3068 if (attrname
[0] == '?')
3073 if (!strcmp(s
, "printer-name"))
3075 cupsFilePuts(out
, job
->dest
);
3078 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
3081 * See if we have a leading question mark...
3084 if (attrname
[0] != '?')
3087 * Nope, write to file as-is; probably a PostScript procedure...
3090 cupsFilePrintf(out
, "{%s}", attrname
);
3097 * Output value(s)...
3100 for (i
= 0; i
< attr
->num_values
; i
++)
3103 cupsFilePutChar(out
, ',');
3105 switch (attr
->value_tag
)
3107 case IPP_TAG_INTEGER
:
3109 if (!strncmp(s
, "time-at-", 8))
3110 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
3112 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
3115 case IPP_TAG_BOOLEAN
:
3116 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
3119 case IPP_TAG_NOVALUE
:
3120 cupsFilePuts(out
, "novalue");
3123 case IPP_TAG_RANGE
:
3124 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
3125 attr
->values
[i
].range
.upper
);
3128 case IPP_TAG_RESOLUTION
:
3129 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
3130 attr
->values
[i
].resolution
.yres
,
3131 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
3136 case IPP_TAG_STRING
:
3139 case IPP_TAG_KEYWORD
:
3140 case IPP_TAG_CHARSET
:
3141 case IPP_TAG_LANGUAGE
:
3142 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
3145 * Need to quote strings for PS banners...
3150 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
3152 if (*p
== '(' || *p
== ')' || *p
== '\\')
3154 cupsFilePutChar(out
, '\\');
3155 cupsFilePutChar(out
, *p
);
3157 else if (*p
< 32 || *p
> 126)
3158 cupsFilePrintf(out
, "\\%03o", *p
& 255);
3160 cupsFilePutChar(out
, *p
);
3164 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
3168 break; /* anti-compiler-warning-code */
3172 else if (ch
== '\\') /* Quoted char */
3174 ch
= cupsFileGetChar(in
);
3176 if (ch
!= '{') /* Only do special handling for \{ */
3177 cupsFilePutChar(out
, '\\');
3179 cupsFilePutChar(out
, ch
);
3182 cupsFilePutChar(out
, ch
);
3186 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
3188 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
3189 IPP_TAG_INTEGER
)) != NULL
)
3190 attr
->values
[0].integer
+= kbytes
;
3199 * 'copy_file()' - Copy a PPD file or interface script...
3202 static int /* O - 0 = success, -1 = error */
3203 copy_file(const char *from
, /* I - Source file */
3204 const char *to
) /* I - Destination file */
3206 cups_file_t
*src
, /* Source file */
3207 *dst
; /* Destination file */
3208 int bytes
; /* Bytes to read/write */
3209 char buffer
[2048]; /* Copy buffer */
3212 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
3215 * Open the source and destination file for a copy...
3218 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
3221 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
3228 * Copy the source file to the destination...
3231 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
3232 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
3240 * Close both files and return...
3245 return (cupsFileClose(dst
));
3250 * 'copy_model()' - Copy a PPD model file, substituting default values
3254 static int /* O - 0 = success, -1 = error */
3255 copy_model(cupsd_client_t
*con
, /* I - Client connection */
3256 const char *from
, /* I - Source file */
3257 const char *to
) /* I - Destination file */
3259 fd_set
*input
; /* select() input set */
3260 struct timeval timeout
; /* select() timeout */
3261 int maxfd
; /* Maximum file descriptor for select() */
3262 char tempfile
[1024]; /* Temporary PPD file */
3263 int tempfd
; /* Temporary PPD file descriptor */
3264 int temppid
; /* Process ID of cups-driverd */
3265 int temppipe
[2]; /* Temporary pipes */
3266 char *argv
[4], /* Command-line arguments */
3267 *envp
[MAX_ENV
]; /* Environment */
3268 cups_file_t
*src
, /* Source file */
3269 *dst
; /* Destination file */
3270 int bytes
, /* Bytes from pipe */
3271 total
; /* Total bytes from pipe */
3272 char buffer
[2048], /* Copy buffer */
3273 *ptr
; /* Pointer into buffer */
3274 int i
; /* Looping var */
3275 char option
[PPD_MAX_NAME
], /* Option name */
3276 choice
[PPD_MAX_NAME
]; /* Choice name */
3277 int num_defaults
; /* Number of default options */
3278 ppd_default_t
*defaults
; /* Default options */
3279 char cups_protocol
[PPD_MAX_LINE
];
3280 /* cupsProtocol attribute */
3281 int have_letter
, /* Have Letter size */
3282 have_a4
; /* Have A4 size */
3283 #ifdef HAVE_LIBPAPER
3284 char *paper_result
; /* Paper size name from libpaper */
3285 char system_paper
[64]; /* Paper size name buffer */
3286 #endif /* HAVE_LIBPAPER */
3289 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3290 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
3294 * Run cups-driverd to get the PPD file...
3297 argv
[0] = "cups-driverd";
3299 argv
[2] = (char *)from
;
3302 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
3304 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
3305 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
3306 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
3310 cupsdOpenPipe(temppipe
);
3312 if ((input
= calloc(1, SetSize
)) == NULL
)
3317 cupsdLogMessage(CUPSD_LOG_ERROR
,
3318 "copy_model: Unable to allocate %d bytes for select()...",
3323 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3324 "copy_model: Running \"cups-driverd cat %s\"...", from
);
3326 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
3338 * Wait up to 30 seconds for the PPD file to be copied...
3343 if (temppipe
[0] > CGIPipes
[0])
3344 maxfd
= temppipe
[0] + 1;
3346 maxfd
= CGIPipes
[0] + 1;
3351 * See if we have data ready...
3356 FD_SET(temppipe
[0], input
);
3357 FD_SET(CGIPipes
[0], input
);
3359 timeout
.tv_sec
= 30;
3360 timeout
.tv_usec
= 0;
3362 if ((i
= select(maxfd
, input
, NULL
, NULL
, &timeout
)) < 0)
3372 * We have timed out...
3378 if (FD_ISSET(temppipe
[0], input
))
3381 * Read the PPD file from the pipe, and write it to the PPD file.
3384 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
3386 if (write(tempfd
, buffer
, bytes
) < bytes
)
3395 if (FD_ISSET(CGIPipes
[0], input
))
3407 * No data from cups-deviced...
3410 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
3416 * Read the source file and see what page sizes are supported...
3419 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
3428 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
3429 if (!strncmp(buffer
, "*PageSize ", 10))
3432 * Strip UI text and command data from the end of the line...
3435 if ((ptr
= strchr(buffer
+ 10, '/')) != NULL
)
3437 if ((ptr
= strchr(buffer
+ 10, ':')) != NULL
)
3440 for (ptr
= buffer
+ 10; isspace(*ptr
); ptr
++);
3443 * Look for Letter and A4 page sizes...
3446 if (!strcmp(ptr
, "Letter"))
3449 if (!strcmp(ptr
, "A4"))
3453 cupsFileRewind(src
);
3456 * Open the destination (if possible) and set the default options...
3461 cups_protocol
[0] = '\0';
3463 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
3466 * Read all of the default lines from the old PPD...
3469 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
3470 if (!strncmp(buffer
, "*Default", 8))
3473 * Add the default option...
3476 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
3477 choice
, sizeof(choice
)))
3478 num_defaults
= ppd_add_default(option
, choice
, num_defaults
,
3481 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
3482 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
3486 #ifdef HAVE_LIBPAPER
3487 else if ((paper_result
= systempapername()) != NULL
)
3490 * Set the default media sizes from the systemwide default...
3493 strlcpy(system_paper
, paper_result
, sizeof(system_paper
));
3494 system_paper
[0] = toupper(system_paper
[0] & 255);
3496 if ((!strcmp(system_paper
, "Letter") && have_letter
) ||
3497 (!strcmp(system_paper
, "A4") && have_a4
))
3499 num_defaults
= ppd_add_default("PageSize", system_paper
,
3500 num_defaults
, &defaults
);
3501 num_defaults
= ppd_add_default("PageRegion", system_paper
,
3502 num_defaults
, &defaults
);
3503 num_defaults
= ppd_add_default("PaperDimension", system_paper
,
3504 num_defaults
, &defaults
);
3505 num_defaults
= ppd_add_default("ImageableArea", system_paper
,
3506 num_defaults
, &defaults
);
3509 #endif /* HAVE_LIBPAPER */
3513 * Add the default media sizes...
3515 * Note: These values are generally not valid for large-format devices
3516 * like plotters, however it is probably safe to say that those
3517 * users will configure the media size after initially adding
3518 * the device anyways...
3521 if (!DefaultLanguage
||
3522 !strcasecmp(DefaultLanguage
, "C") ||
3523 !strcasecmp(DefaultLanguage
, "POSIX") ||
3524 !strcasecmp(DefaultLanguage
, "en") ||
3525 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
3526 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
3527 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
3530 * These are the only locales that will default to "letter" size...
3535 num_defaults
= ppd_add_default("PageSize", "Letter", num_defaults
,
3537 num_defaults
= ppd_add_default("PageRegion", "Letter", num_defaults
,
3539 num_defaults
= ppd_add_default("PaperDimension", "Letter", num_defaults
,
3541 num_defaults
= ppd_add_default("ImageableArea", "Letter", num_defaults
,
3548 * The rest default to "a4" size...
3551 num_defaults
= ppd_add_default("PageSize", "A4", num_defaults
,
3553 num_defaults
= ppd_add_default("PageRegion", "A4", num_defaults
,
3555 num_defaults
= ppd_add_default("PaperDimension", "A4", num_defaults
,
3557 num_defaults
= ppd_add_default("ImageableArea", "A4", num_defaults
,
3563 * Open the destination file for a copy...
3566 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
3568 if (num_defaults
> 0)
3577 * Copy the source file to the destination...
3580 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
3582 if (!strncmp(buffer
, "*Default", 8))
3585 * Check for an previous default option choice...
3588 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
3589 choice
, sizeof(choice
)))
3591 for (i
= 0; i
< num_defaults
; i
++)
3592 if (!strcmp(option
, defaults
[i
].option
))
3595 * Substitute the previous choice...
3598 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
,
3599 defaults
[i
].choice
);
3605 cupsFilePrintf(dst
, "%s\n", buffer
);
3608 if (cups_protocol
[0])
3609 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
3611 if (num_defaults
> 0)
3615 * Close both files and return...
3622 return (cupsFileClose(dst
));
3627 * 'copy_job_attrs()' - Copy job attributes.
3631 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
3632 cupsd_job_t
*job
, /* I - Job */
3633 cups_array_t
*ra
) /* I - Requested attributes array */
3635 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
3639 * Send the requested attributes for each job...
3642 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
3643 con
->servername
, con
->serverport
, "/jobs/%d",
3646 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
3647 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
3648 "job-more-info", NULL
, job_uri
);
3650 if (job
->state
->values
[0].integer
> IPP_JOB_PROCESSING
&&
3651 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
3653 char filename
[1024]; /* Job data file */
3656 snprintf(filename
, sizeof(filename
), "%s/d%05d-001", RequestRoot
,
3658 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
3659 !access(filename
, 0));
3662 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
3663 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
3664 "job-printer-up-time", time(NULL
));
3666 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
3667 add_job_state_reasons(con
, job
);
3669 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
3670 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
3671 "job-uri", NULL
, job_uri
);
3673 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
3678 * 'copy_printer_attrs()' - Copy printer attributes.
3683 cupsd_client_t
*con
, /* I - Client connection */
3684 cupsd_printer_t
*printer
, /* I - Printer */
3685 cups_array_t
*ra
) /* I - Requested attributes array */
3687 char printer_uri
[HTTP_MAX_URI
];
3689 time_t curtime
; /* Current time */
3690 int i
; /* Looping var */
3691 ipp_attribute_t
*history
; /* History collection */
3695 * Copy the printer attributes to the response using requested-attributes
3696 * and document-format attributes that may be provided by the client.
3699 curtime
= time(NULL
);
3702 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
3703 printer
->recoverable
)
3704 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3705 "com.apple.print.recoverable-message", NULL
,
3706 printer
->recoverable
);
3707 #endif /* __APPLE__ */
3709 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
3710 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
3711 ippTimeToDate(curtime
));
3713 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
3714 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
3715 "printer-error-policy", NULL
, printer
->error_policy
);
3717 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
3718 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
3719 printer
->accepting
);
3721 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
3722 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
3725 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
3726 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
3727 "printer-op-policy", NULL
, printer
->op_policy
);
3729 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
3730 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
3733 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
3734 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3735 "printer-state-change-time", printer
->state_time
);
3737 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
3738 cupsArrayFind(ra
, "printer-state-history"))
3741 * Printer history is only sent if specifically requested, so that
3742 * older CUPS/IPP clients won't barf on the collection attributes.
3745 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
3746 "printer-state-history",
3747 printer
->num_history
, NULL
);
3749 for (i
= 0; i
< printer
->num_history
; i
++)
3750 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
3751 NULL
, IPP_TAG_ZERO
, 0);
3754 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
3755 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3756 "printer-state-message", NULL
, printer
->state_message
);
3758 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
3759 add_printer_state_reasons(con
, printer
);
3761 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
3763 int type
; /* printer-type value */
3767 * Add the CUPS-specific printer-type attribute...
3770 type
= printer
->type
;
3772 if (printer
== DefaultPrinter
)
3773 type
|= CUPS_PRINTER_DEFAULT
;
3775 if (!printer
->accepting
)
3776 type
|= CUPS_PRINTER_REJECTING
;
3778 if (!printer
->shared
)
3779 type
|= CUPS_PRINTER_NOT_SHARED
;
3781 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
3785 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
3786 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3787 "printer-up-time", curtime
);
3789 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
3790 !ippFindAttribute(printer
->attrs
, "printer-uri-supported",
3793 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
3794 "ipp", NULL
, con
->servername
, con
->serverport
,
3795 "/printers/%s", printer
->name
);
3796 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3797 "printer-uri-supported", NULL
, printer_uri
);
3798 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
3802 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
3803 add_queued_job_count(con
, printer
);
3805 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
3806 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
3811 * 'copy_subscription_attrs()' - Copy subscription attributes.
3815 copy_subscription_attrs(
3816 cupsd_client_t
*con
, /* I - Client connection */
3817 cupsd_subscription_t
*sub
, /* I - Subscription */
3818 cups_array_t
*ra
) /* I - Requested attributes array */
3820 ipp_attribute_t
*attr
; /* Current attribute */
3821 char printer_uri
[HTTP_MAX_URI
];
3823 int count
; /* Number of events */
3824 unsigned mask
; /* Current event mask */
3825 const char *name
; /* Current event name */
3829 * Copy the subscription attributes to the response using the
3830 * requested-attributes attribute that may be provided by the client.
3833 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
3835 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
3838 * Simple event list...
3841 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
3842 IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
3843 "notify-events", NULL
, name
);
3848 * Complex event list...
3851 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
3852 if (sub
->mask
& mask
)
3855 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
3856 IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
3857 "notify-events", count
, NULL
, NULL
);
3859 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
3860 if (sub
->mask
& mask
)
3862 attr
->values
[count
].string
.text
=
3863 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
3870 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
3871 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
3872 "notify-job-id", sub
->job
->id
);
3874 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
3875 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
3876 "notify-lease-duration", sub
->lease
);
3878 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
3880 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
3881 "ipp", NULL
, con
->servername
, con
->serverport
,
3882 "/printers/%s", sub
->dest
->name
);
3883 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
3884 "notify-printer-uri", NULL
, printer_uri
);
3887 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
3888 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
3889 "notify-recipient-uri", NULL
, sub
->recipient
);
3890 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
3891 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
3892 "notify-pull-method", NULL
, "ippget");
3894 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
3895 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
3896 "notify-subscriber-user-name", NULL
, sub
->owner
);
3898 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
3899 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
3900 "notify-subscription-id", sub
->id
);
3902 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
3903 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
3904 "notify-time-interval", sub
->interval
);
3906 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
3907 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
3908 sub
->user_data
, sub
->user_data_len
);
3913 * 'create_job()' - Print a file to a printer or class.
3917 create_job(cupsd_client_t
*con
, /* I - Client connection */
3918 ipp_attribute_t
*uri
) /* I - Printer URI */
3920 http_status_t status
; /* Policy status */
3921 ipp_attribute_t
*attr
; /* Current attribute */
3922 const char *dest
; /* Destination */
3923 cups_ptype_t dtype
; /* Destination type (printer or class) */
3924 int priority
; /* Job priority */
3925 char *title
; /* Job name/title */
3926 cupsd_job_t
*job
; /* Current job */
3927 char job_uri
[HTTP_MAX_URI
], /* Job URI */
3928 method
[HTTP_MAX_URI
], /* Method portion of URI */
3929 username
[HTTP_MAX_URI
], /* Username portion of URI */
3930 host
[HTTP_MAX_URI
], /* Host portion of URI */
3931 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
3932 int port
; /* Port portion of URI */
3933 cupsd_printer_t
*printer
; /* Printer data */
3934 int kbytes
; /* Size of print file */
3935 int i
; /* Looping var */
3936 int lowerpagerange
; /* Page range bound */
3939 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
3940 con
->http
.fd
, uri
->values
[0].string
.text
);
3943 * Is the destination valid?
3946 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
3947 sizeof(method
), username
, sizeof(username
), host
,
3948 sizeof(host
), &port
, resource
, sizeof(resource
));
3950 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
3956 send_ipp_status(con
, IPP_NOT_FOUND
,
3957 _("The printer or class was not found."));
3962 * Check remote printing to non-shared printer...
3965 if (!printer
->shared
&&
3966 strcasecmp(con
->http
.hostname
, "localhost") &&
3967 strcasecmp(con
->http
.hostname
, ServerName
))
3969 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
3970 _("The printer or class is not shared!"));
3978 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
3980 send_http_error(con
, status
);
3983 else if ((printer
->type
& CUPS_PRINTER_AUTHENTICATED
) && !con
->username
[0])
3985 send_http_error(con
, HTTP_UNAUTHORIZED
);
3990 * See if the printer is accepting jobs...
3993 if (!printer
->accepting
)
3995 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
3996 _("Destination \"%s\" is not accepting jobs."),
4002 * Validate job template attributes; for now just copies and page-ranges...
4005 if ((attr
= ippFindAttribute(con
->request
, "copies",
4006 IPP_TAG_INTEGER
)) != NULL
)
4008 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
4010 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
4011 attr
->values
[0].integer
);
4012 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
4013 "copies", attr
->values
[0].integer
);
4018 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
4019 IPP_TAG_RANGE
)) != NULL
)
4021 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
4023 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
4024 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
4026 send_ipp_status(con
, IPP_BAD_REQUEST
,
4027 _("Bad page-ranges values %d-%d."),
4028 attr
->values
[i
].range
.lower
,
4029 attr
->values
[i
].range
.upper
);
4033 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
4038 * Make sure we aren't over our limit...
4041 if (cupsArrayCount(Jobs
) >= MaxJobs
&& MaxJobs
)
4044 if (cupsArrayCount(Jobs
) >= MaxJobs
&& MaxJobs
)
4046 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4047 _("Too many active jobs."));
4051 if (!check_quotas(con
, printer
))
4053 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
4058 * Create the job and set things up...
4061 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
4062 IPP_TAG_INTEGER
)) != NULL
)
4063 priority
= attr
->values
[0].integer
;
4065 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
4068 if ((attr
= ippFindAttribute(con
->request
, "job-name",
4069 IPP_TAG_NAME
)) != NULL
)
4070 title
= attr
->values
[0].string
.text
;
4072 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
4073 title
= "Untitled");
4075 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
4077 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
4078 _("Unable to add job for destination \"%s\"!"), dest
);
4083 job
->attrs
= con
->request
;
4084 con
->request
= NULL
;
4086 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
4088 if (con
->username
[0])
4090 cupsdSetString(&job
->username
, con
->username
);
4093 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
4095 save_auth_info(con
, job
);
4099 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4100 "create_job: requesting-user-name = \"%s\"",
4101 attr
->values
[0].string
.text
);
4103 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
4106 cupsdSetString(&job
->username
, "anonymous");
4109 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
4110 "job-originating-user-name", NULL
, job
->username
);
4113 attr
->group_tag
= IPP_TAG_JOB
;
4114 cupsdSetString(&attr
->name
, "job-originating-user-name");
4117 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
4118 IPP_TAG_ZERO
)) != NULL
)
4121 * Request contains a job-originating-host-name attribute; validate it...
4124 if (attr
->value_tag
!= IPP_TAG_NAME
||
4125 attr
->num_values
!= 1 ||
4126 strcmp(con
->http
.hostname
, "localhost"))
4129 * Can't override the value if we aren't connected via localhost.
4130 * Also, we can only have 1 value and it must be a name value.
4133 switch (attr
->value_tag
)
4135 case IPP_TAG_STRING
:
4136 case IPP_TAG_TEXTLANG
:
4137 case IPP_TAG_NAMELANG
:
4140 case IPP_TAG_KEYWORD
:
4142 case IPP_TAG_URISCHEME
:
4143 case IPP_TAG_CHARSET
:
4144 case IPP_TAG_LANGUAGE
:
4145 case IPP_TAG_MIMETYPE
:
4147 * Free old strings...
4150 for (i
= 0; i
< attr
->num_values
; i
++)
4152 _cups_sp_free(attr
->values
[i
].string
.text
);
4153 attr
->values
[i
].string
.text
= NULL
;
4154 if (attr
->values
[i
].string
.charset
)
4156 _cups_sp_free(attr
->values
[i
].string
.charset
);
4157 attr
->values
[i
].string
.charset
= NULL
;
4166 * Use the default connection hostname instead...
4169 attr
->value_tag
= IPP_TAG_NAME
;
4170 attr
->num_values
= 1;
4171 attr
->values
[0].string
.text
= _cups_sp_alloc(con
->http
.hostname
);
4174 attr
->group_tag
= IPP_TAG_JOB
;
4179 * No job-originating-host-name attribute, so use the hostname from
4183 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
4184 "job-originating-host-name", NULL
, con
->http
.hostname
);
4187 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
4189 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4190 "time-at-processing", 0);
4191 attr
->value_tag
= IPP_TAG_NOVALUE
;
4192 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4193 "time-at-completed", 0);
4194 attr
->value_tag
= IPP_TAG_NOVALUE
;
4197 * Add remaining job attributes...
4200 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4201 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
4202 "job-state", IPP_JOB_STOPPED
);
4203 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4204 "job-media-sheets-completed", 0);
4205 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
4207 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
4210 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
4211 IPP_TAG_INTEGER
)) != NULL
)
4212 attr
->values
[0].integer
= 0;
4214 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4217 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
4218 IPP_TAG_KEYWORD
)) == NULL
)
4219 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
4221 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
4222 "job-hold-until", NULL
, "no-hold");
4223 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
4224 !(printer
->type
& CUPS_PRINTER_REMOTE
))
4227 * Hold job until specified time...
4230 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
4233 job
->hold_until
= time(NULL
) + 60;
4235 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
4237 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
4241 * Add job sheets options...
4244 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
4245 IPP_TAG_ZERO
)) == NULL
)
4247 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4248 "Adding default job-sheets values \"%s,%s\"...",
4249 printer
->job_sheets
[0], printer
->job_sheets
[1]);
4251 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
4253 attr
->values
[0].string
.text
= _cups_sp_alloc(printer
->job_sheets
[0]);
4254 attr
->values
[1].string
.text
= _cups_sp_alloc(printer
->job_sheets
[1]);
4257 job
->job_sheets
= attr
;
4260 * Enforce classification level if set...
4265 cupsdLogMessage(CUPSD_LOG_INFO
,
4266 "Classification=\"%s\", ClassifyOverride=%d",
4267 Classification
? Classification
: "(null)",
4270 if (ClassifyOverride
)
4272 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
4273 (attr
->num_values
== 1 ||
4274 !strcmp(attr
->values
[1].string
.text
, "none")))
4277 * Force the leading banner to have the classification on it...
4280 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
4282 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
4283 "job-sheets=\"%s,none\", "
4284 "job-originating-user-name=\"%s\"",
4285 job
->id
, Classification
, job
->username
);
4287 else if (attr
->num_values
== 2 &&
4288 strcmp(attr
->values
[0].string
.text
,
4289 attr
->values
[1].string
.text
) &&
4290 strcmp(attr
->values
[0].string
.text
, "none") &&
4291 strcmp(attr
->values
[1].string
.text
, "none"))
4294 * Can't put two different security markings on the same document!
4297 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
4299 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
4300 "job-sheets=\"%s,%s\", "
4301 "job-originating-user-name=\"%s\"",
4302 job
->id
, attr
->values
[0].string
.text
,
4303 attr
->values
[1].string
.text
, job
->username
);
4305 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
4306 strcmp(attr
->values
[0].string
.text
, "none") &&
4307 (attr
->num_values
== 1 ||
4308 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
4309 strcmp(attr
->values
[1].string
.text
, "none"))))
4311 if (attr
->num_values
== 1)
4312 cupsdLogMessage(CUPSD_LOG_NOTICE
,
4313 "[Job %d] CLASSIFICATION OVERRIDDEN "
4314 "job-sheets=\"%s\", "
4315 "job-originating-user-name=\"%s\"",
4316 job
->id
, attr
->values
[0].string
.text
, job
->username
);
4318 cupsdLogMessage(CUPSD_LOG_NOTICE
,
4319 "[Job %d] CLASSIFICATION OVERRIDDEN "
4320 "job-sheets=\"%s,%s\",fffff "
4321 "job-originating-user-name=\"%s\"",
4322 job
->id
, attr
->values
[0].string
.text
,
4323 attr
->values
[1].string
.text
, job
->username
);
4326 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
4327 (attr
->num_values
== 1 ||
4328 strcmp(attr
->values
[1].string
.text
, Classification
)))
4331 * Force the banner to have the classification on it...
4334 if (attr
->num_values
> 1 &&
4335 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
4337 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
4338 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
4342 if (attr
->num_values
== 1 ||
4343 strcmp(attr
->values
[0].string
.text
, "none"))
4344 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
4346 if (attr
->num_values
> 1 &&
4347 strcmp(attr
->values
[1].string
.text
, "none"))
4348 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
4351 if (attr
->num_values
> 1)
4352 cupsdLogMessage(CUPSD_LOG_NOTICE
,
4353 "[Job %d] CLASSIFICATION FORCED "
4354 "job-sheets=\"%s,%s\", "
4355 "job-originating-user-name=\"%s\"",
4356 job
->id
, attr
->values
[0].string
.text
,
4357 attr
->values
[1].string
.text
, job
->username
);
4359 cupsdLogMessage(CUPSD_LOG_NOTICE
,
4360 "[Job %d] CLASSIFICATION FORCED "
4361 "job-sheets=\"%s\", "
4362 "job-originating-user-name=\"%s\"",
4363 job
->id
, Classification
, job
->username
);
4368 * See if we need to add the starting sheet...
4371 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
4373 cupsdLogMessage(CUPSD_LOG_INFO
,
4374 "Adding start banner page \"%s\" to job %d.",
4375 attr
->values
[0].string
.text
, job
->id
);
4377 kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
);
4379 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
4382 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
4383 IPP_TAG_ZERO
)) != NULL
)
4387 * Fill in the response info...
4390 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
4391 LocalPort
, job
->id
);
4393 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
, job_uri
);
4395 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
4397 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
4398 job
->state
->values
[0].integer
);
4400 con
->response
->request
.status
.status_code
= IPP_OK
;
4403 * Add any job subscriptions...
4406 add_job_subscriptions(con
, job
);
4409 * Set all but the first two attributes to the job attributes group...
4412 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
4413 attr
->group_tag
= IPP_TAG_JOB
;
4416 * Save and log the job...
4421 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d created on \"%s\" by \"%s\".",
4422 job
->id
, job
->dest
, job
->username
);
4424 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
4429 * 'create_requested_array()' - Create an array for the requested-attributes.
4432 static cups_array_t
* /* O - Array of attributes or NULL */
4433 create_requested_array(ipp_t
*request
) /* I - IPP request */
4435 int i
; /* Looping var */
4436 ipp_attribute_t
*requested
; /* requested-attributes attribute */
4437 cups_array_t
*ra
; /* Requested attributes array */
4438 char *value
; /* Current value */
4442 * Get the requested-attributes attribute, and return NULL if we don't
4446 if ((requested
= ippFindAttribute(request
, "requested-attributes",
4447 IPP_TAG_KEYWORD
)) == NULL
)
4451 * If the attribute contains a single "all" keyword, return NULL...
4454 if (requested
->num_values
== 1 &&
4455 !strcmp(requested
->values
[0].string
.text
, "all"))
4459 * Create an array using "strcmp" as the comparison function...
4462 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4464 for (i
= 0; i
< requested
->num_values
; i
++)
4466 value
= requested
->values
[i
].string
.text
;
4468 if (!strcmp(value
, "job-template"))
4470 cupsArrayAdd(ra
, "copies");
4471 cupsArrayAdd(ra
, "copies-default");
4472 cupsArrayAdd(ra
, "copies-supported");
4473 cupsArrayAdd(ra
, "finishings");
4474 cupsArrayAdd(ra
, "finishings-default");
4475 cupsArrayAdd(ra
, "finishings-supported");
4476 cupsArrayAdd(ra
, "job-hold-until");
4477 cupsArrayAdd(ra
, "job-hold-until-default");
4478 cupsArrayAdd(ra
, "job-hold-until-supported");
4479 cupsArrayAdd(ra
, "job-priority");
4480 cupsArrayAdd(ra
, "job-priority-default");
4481 cupsArrayAdd(ra
, "job-priority-supported");
4482 cupsArrayAdd(ra
, "job-sheets");
4483 cupsArrayAdd(ra
, "job-sheets-default");
4484 cupsArrayAdd(ra
, "job-sheets-supported");
4485 cupsArrayAdd(ra
, "media");
4486 cupsArrayAdd(ra
, "media-default");
4487 cupsArrayAdd(ra
, "media-supported");
4488 cupsArrayAdd(ra
, "multiple-document-handling");
4489 cupsArrayAdd(ra
, "multiple-document-handling-default");
4490 cupsArrayAdd(ra
, "multiple-document-handling-supported");
4491 cupsArrayAdd(ra
, "number-up");
4492 cupsArrayAdd(ra
, "number-up-default");
4493 cupsArrayAdd(ra
, "number-up-supported");
4494 cupsArrayAdd(ra
, "orientation-requested");
4495 cupsArrayAdd(ra
, "orientation-requested-default");
4496 cupsArrayAdd(ra
, "orientation-requested-supported");
4497 cupsArrayAdd(ra
, "page-ranges");
4498 cupsArrayAdd(ra
, "page-ranges-supported");
4499 cupsArrayAdd(ra
, "printer-resolution");
4500 cupsArrayAdd(ra
, "printer-resolution-default");
4501 cupsArrayAdd(ra
, "printer-resolution-supported");
4502 cupsArrayAdd(ra
, "print-quality");
4503 cupsArrayAdd(ra
, "print-quality-default");
4504 cupsArrayAdd(ra
, "print-quality-supported");
4505 cupsArrayAdd(ra
, "sides");
4506 cupsArrayAdd(ra
, "sides-default");
4507 cupsArrayAdd(ra
, "sides-supported");
4509 else if (!strcmp(value
, "job-description"))
4511 cupsArrayAdd(ra
, "date-time-at-completed");
4512 cupsArrayAdd(ra
, "date-time-at-creation");
4513 cupsArrayAdd(ra
, "date-time-at-processing");
4514 cupsArrayAdd(ra
, "job-detailed-status-message");
4515 cupsArrayAdd(ra
, "job-document-access-errors");
4516 cupsArrayAdd(ra
, "job-id");
4517 cupsArrayAdd(ra
, "job-impressions");
4518 cupsArrayAdd(ra
, "job-impressions-completed");
4519 cupsArrayAdd(ra
, "job-k-octets");
4520 cupsArrayAdd(ra
, "job-k-octets-processed");
4521 cupsArrayAdd(ra
, "job-media-sheets");
4522 cupsArrayAdd(ra
, "job-media-sheets-completed");
4523 cupsArrayAdd(ra
, "job-message-from-operator");
4524 cupsArrayAdd(ra
, "job-more-info");
4525 cupsArrayAdd(ra
, "job-name");
4526 cupsArrayAdd(ra
, "job-originating-user-name");
4527 cupsArrayAdd(ra
, "job-printer-up-time");
4528 cupsArrayAdd(ra
, "job-printer-uri");
4529 cupsArrayAdd(ra
, "job-state");
4530 cupsArrayAdd(ra
, "job-state-message");
4531 cupsArrayAdd(ra
, "job-state-reasons");
4532 cupsArrayAdd(ra
, "job-uri");
4533 cupsArrayAdd(ra
, "number-of-documents");
4534 cupsArrayAdd(ra
, "number-of-intervening-jobs");
4535 cupsArrayAdd(ra
, "output-device-assigned");
4536 cupsArrayAdd(ra
, "time-at-completed");
4537 cupsArrayAdd(ra
, "time-at-creation");
4538 cupsArrayAdd(ra
, "time-at-processing");
4540 else if (!strcmp(value
, "printer-description"))
4542 cupsArrayAdd(ra
, "charset-configured");
4543 cupsArrayAdd(ra
, "charset-supported");
4544 cupsArrayAdd(ra
, "color-supported");
4545 cupsArrayAdd(ra
, "compression-supported");
4546 cupsArrayAdd(ra
, "document-format-default");
4547 cupsArrayAdd(ra
, "document-format-supported");
4548 cupsArrayAdd(ra
, "generated-natural-language-supported");
4549 cupsArrayAdd(ra
, "ipp-versions-supported");
4550 cupsArrayAdd(ra
, "job-impressions-supported");
4551 cupsArrayAdd(ra
, "job-k-octets-supported");
4552 cupsArrayAdd(ra
, "job-media-sheets-supported");
4553 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
4554 cupsArrayAdd(ra
, "multiple-operation-time-out");
4555 cupsArrayAdd(ra
, "natural-language-configured");
4556 cupsArrayAdd(ra
, "notify-attributes-supported");
4557 cupsArrayAdd(ra
, "notify-lease-duration-default");
4558 cupsArrayAdd(ra
, "notify-lease-duration-supported");
4559 cupsArrayAdd(ra
, "notify-max-events-supported");
4560 cupsArrayAdd(ra
, "notify-notify-events-default");
4561 cupsArrayAdd(ra
, "notify-notify-events-supported");
4562 cupsArrayAdd(ra
, "notify-pull-method-supported");
4563 cupsArrayAdd(ra
, "notify-schemes-supported");
4564 cupsArrayAdd(ra
, "operations-supported");
4565 cupsArrayAdd(ra
, "pages-per-minute");
4566 cupsArrayAdd(ra
, "pages-per-minute-color");
4567 cupsArrayAdd(ra
, "pdl-override-supported");
4568 cupsArrayAdd(ra
, "printer-current-time");
4569 cupsArrayAdd(ra
, "printer-driver-installer");
4570 cupsArrayAdd(ra
, "printer-info");
4571 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
4572 cupsArrayAdd(ra
, "printer-location");
4573 cupsArrayAdd(ra
, "printer-make-and-model");
4574 cupsArrayAdd(ra
, "printer-message-from-operator");
4575 cupsArrayAdd(ra
, "printer-more-info");
4576 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
4577 cupsArrayAdd(ra
, "printer-name");
4578 cupsArrayAdd(ra
, "printer-state");
4579 cupsArrayAdd(ra
, "printer-state-message");
4580 cupsArrayAdd(ra
, "printer-state-reasons");
4581 cupsArrayAdd(ra
, "printer-up-time");
4582 cupsArrayAdd(ra
, "printer-uri-supported");
4583 cupsArrayAdd(ra
, "queued-job-count");
4584 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
4585 cupsArrayAdd(ra
, "uri-authentication-supported");
4586 cupsArrayAdd(ra
, "uri-security-supported");
4588 else if (!strcmp(value
, "subscription-template"))
4590 cupsArrayAdd(ra
, "notify-attributes");
4591 cupsArrayAdd(ra
, "notify-charset");
4592 cupsArrayAdd(ra
, "notify-events");
4593 cupsArrayAdd(ra
, "notify-lease-duration");
4594 cupsArrayAdd(ra
, "notify-natural-language");
4595 cupsArrayAdd(ra
, "notify-pull-method");
4596 cupsArrayAdd(ra
, "notify-recipient-uri");
4597 cupsArrayAdd(ra
, "notify-time-interval");
4598 cupsArrayAdd(ra
, "notify-user-data");
4601 cupsArrayAdd(ra
, value
);
4609 * 'create_subscription()' - Create a notification subscription.
4613 create_subscription(
4614 cupsd_client_t
*con
, /* I - Client connection */
4615 ipp_attribute_t
*uri
) /* I - Printer URI */
4617 http_status_t status
; /* Policy status */
4618 int i
; /* Looping var */
4619 ipp_attribute_t
*attr
; /* Current attribute */
4620 const char *dest
; /* Destination */
4621 cups_ptype_t dtype
; /* Destination type (printer or class) */
4622 char method
[HTTP_MAX_URI
],
4623 /* Method portion of URI */
4624 userpass
[HTTP_MAX_URI
],
4625 /* Username portion of URI */
4627 /* Host portion of URI */
4628 resource
[HTTP_MAX_URI
];
4629 /* Resource portion of URI */
4630 int port
; /* Port portion of URI */
4631 cupsd_printer_t
*printer
; /* Printer/class */
4632 cupsd_job_t
*job
; /* Job */
4633 int jobid
; /* Job ID */
4634 cupsd_subscription_t
*sub
; /* Subscription object */
4635 const char *username
, /* requesting-user-name or authenticated username */
4636 *recipient
, /* notify-recipient-uri */
4637 *pullmethod
; /* notify-pull-method */
4638 ipp_attribute_t
*user_data
; /* notify-user-data */
4639 int interval
, /* notify-time-interval */
4640 lease
; /* notify-lease-duration */
4641 unsigned mask
; /* notify-events */
4645 * Is the destination valid?
4648 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4649 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
4650 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4652 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
4653 sizeof(method
), userpass
, sizeof(userpass
), host
,
4654 sizeof(host
), &port
, resource
, sizeof(resource
));
4656 if (!strcmp(resource
, "/"))
4659 dtype
= (cups_ptype_t
)0;
4662 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
4665 dtype
= (cups_ptype_t
)0;
4668 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
4671 dtype
= CUPS_PRINTER_CLASS
;
4674 else if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
4680 send_ipp_status(con
, IPP_NOT_FOUND
,
4681 _("The printer or class was not found."));
4691 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
4693 send_http_error(con
, status
);
4697 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4699 send_http_error(con
, status
);
4704 * Get the user that is requesting the subscription...
4707 username
= get_username(con
);
4710 * Find the first subscription group attribute; return if we have
4714 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
4715 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
4720 send_ipp_status(con
, IPP_BAD_REQUEST
,
4721 _("No subscription attributes in request!"));
4726 * Process the subscription attributes in the request...
4729 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
4737 lease
= DefaultLeaseDuration
;
4739 mask
= CUPSD_EVENT_NONE
;
4741 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
4743 if (!strcmp(attr
->name
, "notify-recipient") &&
4744 attr
->value_tag
== IPP_TAG_URI
)
4745 recipient
= attr
->values
[0].string
.text
;
4746 else if (!strcmp(attr
->name
, "notify-pull-method") &&
4747 attr
->value_tag
== IPP_TAG_KEYWORD
)
4748 pullmethod
= attr
->values
[0].string
.text
;
4749 else if (!strcmp(attr
->name
, "notify-charset") &&
4750 attr
->value_tag
== IPP_TAG_CHARSET
&&
4751 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
4752 strcmp(attr
->values
[0].string
.text
, "utf-8"))
4754 send_ipp_status(con
, IPP_CHARSET
,
4755 _("Character set \"%s\" not supported!"),
4756 attr
->values
[0].string
.text
);
4759 else if (!strcmp(attr
->name
, "notify-natural-language") &&
4760 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
4761 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
4763 send_ipp_status(con
, IPP_CHARSET
,
4764 _("Language \"%s\" not supported!"),
4765 attr
->values
[0].string
.text
);
4768 else if (!strcmp(attr
->name
, "notify-user-data") &&
4769 attr
->value_tag
== IPP_TAG_STRING
)
4771 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
4773 send_ipp_status(con
, IPP_REQUEST_VALUE
,
4774 _("The notify-user-data value is too large "
4775 "(%d > 63 octets)!"),
4776 attr
->values
[0].unknown
.length
);
4782 else if (!strcmp(attr
->name
, "notify-events") &&
4783 attr
->value_tag
== IPP_TAG_KEYWORD
)
4785 for (i
= 0; i
< attr
->num_values
; i
++)
4786 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
4788 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
4789 attr
->value_tag
== IPP_TAG_INTEGER
)
4790 lease
= attr
->values
[0].integer
;
4791 else if (!strcmp(attr
->name
, "notify-time-interval") &&
4792 attr
->value_tag
== IPP_TAG_INTEGER
)
4793 interval
= attr
->values
[0].integer
;
4794 else if (!strcmp(attr
->name
, "notify-job-id") &&
4795 attr
->value_tag
== IPP_TAG_INTEGER
)
4796 jobid
= attr
->values
[0].integer
;
4801 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
4802 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
4804 if (!recipient
&& !pullmethod
)
4807 if (mask
== CUPSD_EVENT_NONE
)
4810 mask
= CUPSD_EVENT_JOB_COMPLETED
;
4812 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
4815 send_ipp_status(con
, IPP_BAD_REQUEST
,
4816 _("notify-events not specified!"));
4821 if (MaxLeaseDuration
&& lease
> MaxLeaseDuration
)
4823 cupsdLogMessage(CUPSD_LOG_INFO
,
4824 "create_subscription: Limiting notify-lease-duration to "
4827 lease
= MaxLeaseDuration
;
4832 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4834 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
4841 sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0);
4844 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
4847 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4848 "Added subscription %d for printer \"%s\"",
4849 sub
->id
, printer
->name
);
4851 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
4854 sub
->interval
= interval
;
4856 sub
->expire
= time(NULL
) + lease
;
4858 cupsdSetString(&sub
->owner
, username
);
4862 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
4863 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
4864 sub
->user_data_len
);
4867 ippAddSeparator(con
->response
);
4868 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4869 "notify-subscription-id", sub
->id
);
4871 con
->response
->request
.status
.status_code
= IPP_OK
;
4877 cupsdSaveAllSubscriptions();
4883 * 'delete_printer()' - Remove a printer or class from the system.
4887 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
4888 ipp_attribute_t
*uri
) /* I - URI of printer or class */
4890 http_status_t status
; /* Policy status */
4891 const char *dest
; /* Destination */
4892 cups_ptype_t dtype
; /* Destination type (printer or class) */
4893 char method
[HTTP_MAX_URI
], /* Method portion of URI */
4894 username
[HTTP_MAX_URI
], /* Username portion of URI */
4895 host
[HTTP_MAX_URI
], /* Host portion of URI */
4896 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
4897 int port
; /* Port portion of URI */
4898 cupsd_printer_t
*printer
; /* Printer/class */
4899 char filename
[1024]; /* Script/PPD filename */
4902 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
4903 con
->http
.fd
, uri
->values
[0].string
.text
);
4906 * Do we have a valid URI?
4909 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
4910 sizeof(method
), username
, sizeof(username
), host
,
4911 sizeof(host
), &port
, resource
, sizeof(resource
));
4913 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
4919 send_ipp_status(con
, IPP_NOT_FOUND
,
4920 _("The printer or class was not found."));
4928 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4930 send_http_error(con
, status
);
4935 * Remove old jobs...
4938 cupsdCancelJobs(dest
, NULL
, 1);
4941 * Remove old subscriptions and send a "deleted printer" event...
4944 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
4945 "%s \"%s\" deleted by \"%s\".",
4946 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
4947 dest
, get_username(con
));
4949 cupsdExpireSubscriptions(printer
, NULL
);
4952 * Remove any old PPD or script files...
4955 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
, dest
);
4958 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
);
4961 if (dtype
& CUPS_PRINTER_CLASS
)
4963 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".", dest
,
4966 cupsdDeletePrinter(printer
, 0);
4967 cupsdSaveAllClasses();
4971 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".", dest
,
4974 cupsdDeletePrinter(printer
, 0);
4975 cupsdSaveAllPrinters();
4978 cupsdWritePrintcap();
4981 * Return with no errors...
4984 con
->response
->request
.status
.status_code
= IPP_OK
;
4989 * 'get_default()' - Get the default destination.
4993 get_default(cupsd_client_t
*con
) /* I - Client connection */
4995 http_status_t status
; /* Policy status */
4996 cups_array_t
*ra
; /* Requested attributes array */
4999 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5005 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5007 send_http_error(con
, status
);
5013 ra
= create_requested_array(con
->request
);
5015 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5017 cupsArrayDelete(ra
);
5019 con
->response
->request
.status
.status_code
= IPP_OK
;
5022 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
5027 * 'get_devices()' - Get the list of available devices on the local system.
5031 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5033 http_status_t status
; /* Policy status */
5034 int i
; /* Looping var */
5035 ipp_attribute_t
*limit
, /* Limit attribute */
5036 *requested
; /* requested-attributes attribute */
5037 char command
[1024], /* cups-deviced command */
5038 options
[1024], /* Options to pass to command */
5039 attrs
[1024], /* String for requested attributes */
5040 *aptr
; /* Pointer into string */
5041 int alen
; /* Length of attribute value */
5044 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
5050 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5052 send_http_error(con
, status
);
5057 * Run cups-deviced command with the given options...
5060 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5061 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5066 for (i
= 0, aptr
= attrs
; i
< requested
->num_values
; i
++)
5069 * Check that we have enough room...
5072 alen
= strlen(requested
->values
[i
].string
.text
);
5073 if (alen
> (sizeof(attrs
) - (aptr
- attrs
) - 2))
5077 * Put commas between values...
5084 * Add the value to the end of the string...
5087 strcpy(aptr
, requested
->values
[i
].string
.text
);
5092 * If we have more attribute names than will fit, default to "all"...
5095 if (i
< requested
->num_values
)
5096 strcpy(attrs
, "all");
5099 strcpy(attrs
, "all");
5101 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5102 snprintf(options
, sizeof(options
),
5103 "cups-deviced %d+%d+%d+requested-attributes=%s",
5104 con
->request
->request
.op
.request_id
,
5105 limit
? limit
->values
[0].integer
: 0, User
,
5108 if (cupsdSendCommand(con
, command
, options
, 1))
5111 * Command started successfully, don't send an IPP response here...
5114 ippDelete(con
->response
);
5115 con
->response
= NULL
;
5120 * Command failed, return "internal error" so the user knows something
5124 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5125 _("cups-deviced failed to execute."));
5131 * 'get_job_attrs()' - Get job attributes.
5135 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5136 ipp_attribute_t
*uri
) /* I - Job URI */
5138 http_status_t status
; /* Policy status */
5139 ipp_attribute_t
*attr
; /* Current attribute */
5140 int jobid
; /* Job ID */
5141 cupsd_job_t
*job
; /* Current job */
5142 char method
[HTTP_MAX_URI
], /* Method portion of URI */
5143 username
[HTTP_MAX_URI
], /* Username portion of URI */
5144 host
[HTTP_MAX_URI
], /* Host portion of URI */
5145 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5146 int port
; /* Port portion of URI */
5147 cups_array_t
*ra
; /* Requested attributes array */
5150 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
5151 con
->http
.fd
, uri
->values
[0].string
.text
);
5154 * See if we have a job URI or a printer URI...
5157 if (!strcmp(uri
->name
, "printer-uri"))
5160 * Got a printer URI; see if we also have a job-id attribute...
5163 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5164 IPP_TAG_INTEGER
)) == NULL
)
5166 send_ipp_status(con
, IPP_BAD_REQUEST
,
5167 _("Got a printer-uri attribute but no job-id!"));
5171 jobid
= attr
->values
[0].integer
;
5176 * Got a job URI; parse it to get the job ID...
5179 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5180 sizeof(method
), username
, sizeof(username
), host
,
5181 sizeof(host
), &port
, resource
, sizeof(resource
));
5183 if (strncmp(resource
, "/jobs/", 6))
5189 send_ipp_status(con
, IPP_BAD_REQUEST
,
5190 _("Bad job-uri attribute \"%s\"!"),
5191 uri
->values
[0].string
.text
);
5195 jobid
= atoi(resource
+ 6);
5199 * See if the job exists...
5202 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5205 * Nope - return a "not found" error...
5208 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
5216 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5218 send_http_error(con
, status
);
5223 * Copy attributes...
5226 ra
= create_requested_array(con
->request
);
5227 copy_job_attrs(con
, job
, ra
);
5228 cupsArrayDelete(ra
);
5230 con
->response
->request
.status
.status_code
= IPP_OK
;
5235 * 'get_jobs()' - Get a list of jobs for the specified printer.
5239 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
5240 ipp_attribute_t
*uri
) /* I - Printer URI */
5242 http_status_t status
; /* Policy status */
5243 ipp_attribute_t
*attr
; /* Current attribute */
5244 const char *dest
; /* Destination */
5245 cups_ptype_t dtype
; /* Destination type (printer or class) */
5246 cups_ptype_t dmask
; /* Destination type mask */
5247 char method
[HTTP_MAX_URI
], /* Method portion of URI */
5248 username
[HTTP_MAX_URI
], /* Username portion of URI */
5249 host
[HTTP_MAX_URI
], /* Host portion of URI */
5250 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5251 int port
; /* Port portion of URI */
5252 int completed
; /* Completed jobs? */
5253 int first_job_id
; /* First job ID */
5254 int limit
; /* Maximum number of jobs to return */
5255 int count
; /* Number of jobs that match */
5256 cupsd_job_t
*job
; /* Current job pointer */
5257 cupsd_printer_t
*printer
; /* Printer */
5258 cups_array_t
*list
; /* Which job list... */
5259 cups_array_t
*ra
; /* Requested attributes array */
5262 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
5263 uri
->values
[0].string
.text
);
5266 * Is the destination valid?
5269 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5270 sizeof(method
), username
, sizeof(username
), host
,
5271 sizeof(host
), &port
, resource
, sizeof(resource
));
5273 if (!strcmp(resource
, "/") ||
5274 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
5277 dtype
= (cups_ptype_t
)0;
5278 dmask
= (cups_ptype_t
)0;
5281 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5284 dtype
= (cups_ptype_t
)0;
5285 dmask
= CUPS_PRINTER_CLASS
;
5288 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5291 dtype
= CUPS_PRINTER_CLASS
;
5292 dmask
= CUPS_PRINTER_CLASS
;
5295 else if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
5301 send_ipp_status(con
, IPP_NOT_FOUND
,
5302 _("The printer or class was not found."));
5306 dmask
= CUPS_PRINTER_CLASS
;
5314 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
5316 send_http_error(con
, status
);
5320 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5322 send_http_error(con
, status
);
5327 * See if the "which-jobs" attribute have been specified...
5330 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
5331 IPP_TAG_KEYWORD
)) != NULL
&&
5332 !strcmp(attr
->values
[0].string
.text
, "completed"))
5337 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
5349 * See if they want to limit the number of jobs reported...
5352 if ((attr
= ippFindAttribute(con
->request
, "limit",
5353 IPP_TAG_INTEGER
)) != NULL
)
5354 limit
= attr
->values
[0].integer
;
5358 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
5359 IPP_TAG_INTEGER
)) != NULL
)
5360 first_job_id
= attr
->values
[0].integer
;
5365 * See if we only want to see jobs for a specific user...
5368 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
5369 IPP_TAG_BOOLEAN
)) != NULL
&&
5370 attr
->values
[0].boolean
)
5371 strlcpy(username
, get_username(con
), sizeof(username
));
5375 ra
= create_requested_array(con
->request
);
5378 * OK, build a list of jobs for this printer...
5381 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
5382 count
< limit
&& job
;
5383 job
= (cupsd_job_t
*)cupsArrayNext(list
))
5386 * Filter out jobs that don't match...
5389 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
5391 if ((dest
&& strcmp(job
->dest
, dest
)) &&
5392 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
5394 if ((job
->dtype
& dmask
) != dtype
&&
5395 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
5397 if (username
[0] && strcasecmp(username
, job
->username
))
5400 if (completed
&& job
->state
->values
[0].integer
<= IPP_JOB_STOPPED
)
5403 if (job
->id
< first_job_id
)
5407 ippAddSeparator(con
->response
);
5411 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
5413 copy_job_attrs(con
, job
, ra
);
5416 cupsArrayDelete(ra
);
5418 con
->response
->request
.status
.status_code
= IPP_OK
;
5423 * 'get_notifications()' - Get events for a subscription.
5427 get_notifications(cupsd_client_t
*con
, /* I - Client connection */
5428 int id
) /* I - Subscription ID */
5434 * 'get_ppds()' - Get the list of PPD files on the local system.
5438 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
5440 http_status_t status
; /* Policy status */
5441 int i
; /* Looping var */
5442 ipp_attribute_t
*limit
, /* Limit attribute */
5443 *make
, /* ppd-make attribute */
5444 *requested
; /* requested-attributes attribute */
5445 char command
[1024], /* cups-deviced command */
5446 options
[1024], /* Options to pass to command */
5447 attrs
[1024], /* String for requested attributes */
5448 *aptr
; /* Pointer into string */
5449 int alen
; /* Length of attribute value */
5452 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
5458 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5460 send_http_error(con
, status
);
5465 * Run cups-driverd command with the given options...
5468 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5469 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
5470 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5475 for (i
= 0, aptr
= attrs
; i
< requested
->num_values
; i
++)
5478 * Check that we have enough room...
5481 alen
= strlen(requested
->values
[i
].string
.text
);
5482 if (alen
> (sizeof(attrs
) - (aptr
- attrs
) - 2))
5486 * Put commas between values...
5493 * Add the value to the end of the string...
5496 strcpy(aptr
, requested
->values
[i
].string
.text
);
5501 * If we have more attribute names than will fit, default to "all"...
5504 if (i
< requested
->num_values
)
5505 strcpy(attrs
, "all");
5508 strcpy(attrs
, "all");
5510 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
5511 snprintf(options
, sizeof(options
),
5512 "cups-driverd list+%d+%d+requested-attributes=%s%s%s",
5513 con
->request
->request
.op
.request_id
,
5514 limit
? limit
->values
[0].integer
: 0,
5516 make
? "%20ppd-make=" : "",
5517 make
? make
->values
[0].string
.text
: "");
5519 if (cupsdSendCommand(con
, command
, options
, 0))
5522 * Command started successfully, don't send an IPP response here...
5525 ippDelete(con
->response
);
5526 con
->response
= NULL
;
5531 * Command failed, return "internal error" so the user knows something
5535 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5536 _("cups-driverd failed to execute."));
5542 * 'get_printer_attrs()' - Get printer attributes.
5546 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
5547 ipp_attribute_t
*uri
) /* I - Printer URI */
5549 http_status_t status
; /* Policy status */
5550 const char *dest
; /* Destination */
5551 cups_ptype_t dtype
; /* Destination type (printer or class) */
5552 char method
[HTTP_MAX_URI
],
5553 /* Method portion of URI */
5554 username
[HTTP_MAX_URI
],
5555 /* Username portion of URI */
5557 /* Host portion of URI */
5558 resource
[HTTP_MAX_URI
];
5559 /* Resource portion of URI */
5560 int port
; /* Port portion of URI */
5561 cupsd_printer_t
*printer
; /* Printer/class */
5562 cups_array_t
*ra
; /* Requested attributes array */
5565 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
5566 con
->http
.fd
, uri
->values
[0].string
.text
);
5569 * Is the destination valid?
5572 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5573 sizeof(method
), username
, sizeof(username
), host
,
5574 sizeof(host
), &port
, resource
, sizeof(resource
));
5576 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
5582 send_ipp_status(con
, IPP_NOT_FOUND
,
5583 _("The printer or class was not found."));
5591 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
5593 send_http_error(con
, status
);
5598 * Send the attributes...
5601 ra
= create_requested_array(con
->request
);
5603 copy_printer_attrs(con
, printer
, ra
);
5605 cupsArrayDelete(ra
);
5607 con
->response
->request
.status
.status_code
= IPP_OK
;
5612 * 'get_printers()' - Get a list of printers or classes.
5616 get_printers(cupsd_client_t
*con
, /* I - Client connection */
5617 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
5619 http_status_t status
; /* Policy status */
5620 ipp_attribute_t
*attr
; /* Current attribute */
5621 int limit
; /* Maximum number of printers to return */
5622 int count
; /* Number of printers that match */
5623 cupsd_printer_t
*printer
; /* Current printer pointer */
5624 int printer_type
, /* printer-type attribute */
5625 printer_mask
; /* printer-type-mask attribute */
5626 char *location
; /* Location string */
5627 const char *username
; /* Current user */
5628 char *first_printer_name
; /* first-printer-name attribute */
5629 cups_array_t
*ra
; /* Requested attributes array */
5632 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
5633 con
->http
.fd
, type
);
5639 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5641 send_http_error(con
, status
);
5646 * Check for printers...
5649 if (!Printers
|| !cupsArrayCount(Printers
))
5651 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
5656 * See if they want to limit the number of printers reported...
5659 if ((attr
= ippFindAttribute(con
->request
, "limit",
5660 IPP_TAG_INTEGER
)) != NULL
)
5661 limit
= attr
->values
[0].integer
;
5665 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
5666 IPP_TAG_NAME
)) != NULL
)
5667 first_printer_name
= attr
->values
[0].string
.text
;
5669 first_printer_name
= NULL
;
5672 * Support filtering...
5675 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
5676 IPP_TAG_ENUM
)) != NULL
)
5677 printer_type
= attr
->values
[0].integer
;
5681 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
5682 IPP_TAG_ENUM
)) != NULL
)
5683 printer_mask
= attr
->values
[0].integer
;
5687 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
5688 IPP_TAG_TEXT
)) != NULL
)
5689 location
= attr
->values
[0].string
.text
;
5693 if (con
->username
[0])
5694 username
= con
->username
;
5695 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
5696 IPP_TAG_NAME
)) != NULL
)
5697 username
= attr
->values
[0].string
.text
;
5701 ra
= create_requested_array(con
->request
);
5704 * OK, build a list of printers for this printer...
5707 if (first_printer_name
)
5709 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
5710 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
5713 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
5716 count
< limit
&& printer
;
5717 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
5719 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
5720 (printer
->type
& printer_mask
) == printer_type
&&
5721 (!location
|| !printer
->location
||
5722 !strcasecmp(printer
->location
, location
)))
5725 * If HideImplicitMembers is enabled, see if this printer or class
5726 * is a member of an implicit class...
5729 if (ImplicitClasses
&& HideImplicitMembers
&&
5730 printer
->in_implicit_class
)
5734 * If a username is specified, see if it is allowed or denied
5738 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
5742 * Add the group separator as needed...
5746 ippAddSeparator(con
->response
);
5751 * Send the attributes...
5754 copy_printer_attrs(con
, printer
, ra
);
5758 cupsArrayDelete(ra
);
5760 con
->response
->request
.status
.status_code
= IPP_OK
;
5765 * 'get_subscription_attrs()' - Get subscription attributes.
5769 get_subscription_attrs(
5770 cupsd_client_t
*con
, /* I - Client connection */
5771 int sub_id
) /* I - Subscription ID */
5773 http_status_t status
; /* Policy status */
5774 cupsd_subscription_t
*sub
; /* Subscription */
5775 cups_array_t
*ra
; /* Requested attributes array */
5778 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5779 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
5780 con
, con
->http
.fd
, sub_id
);
5783 * Is the subscription ID valid?
5786 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
5789 * Bad subscription ID...
5792 send_ipp_status(con
, IPP_NOT_FOUND
,
5793 _("notify-subscription-id %d no good!"), sub_id
);
5801 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
5803 con
, sub
->owner
)) != HTTP_OK
)
5805 send_http_error(con
, status
);
5810 * Copy the subscription attributes to the response using the
5811 * requested-attributes attribute that may be provided by the client.
5814 ra
= create_requested_array(con
->request
);
5816 copy_subscription_attrs(con
, sub
, ra
);
5818 cupsArrayDelete(ra
);
5820 con
->response
->request
.status
.status_code
= IPP_OK
;
5825 * 'get_subscriptions()' - Get subscriptions.
5829 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
5830 ipp_attribute_t
*uri
) /* I - Printer/job URI */
5832 http_status_t status
; /* Policy status */
5833 int count
; /* Number of subscriptions */
5834 int limit
; /* Limit */
5835 cupsd_subscription_t
*sub
; /* Subscription */
5836 cups_array_t
*ra
; /* Requested attributes array */
5837 ipp_attribute_t
*attr
; /* Attribute */
5838 cups_ptype_t dtype
; /* Destination type (printer or class) */
5839 char method
[HTTP_MAX_URI
],
5840 /* Method portion of URI */
5841 username
[HTTP_MAX_URI
],
5842 /* Username portion of URI */
5844 /* Host portion of URI */
5845 resource
[HTTP_MAX_URI
];
5846 /* Resource portion of URI */
5847 int port
; /* Port portion of URI */
5848 cupsd_job_t
*job
; /* Job pointer */
5849 cupsd_printer_t
*printer
; /* Printer */
5852 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5853 "get_subscriptions(con=%p[%d], uri=%s)",
5854 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
5857 * Is the destination valid?
5860 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5861 sizeof(method
), username
, sizeof(username
), host
,
5862 sizeof(host
), &port
, resource
, sizeof(resource
));
5864 if (!strcmp(resource
, "/") ||
5865 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
5866 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
5867 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
5872 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
5875 job
= cupsdFindJob(atoi(resource
+ 6));
5879 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
5884 else if (!cupsdValidateDest(host
, resource
, &dtype
, &printer
))
5890 send_ipp_status(con
, IPP_NOT_FOUND
,
5891 _("The printer or class was not found."));
5894 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
5895 IPP_TAG_INTEGER
)) != NULL
)
5897 job
= cupsdFindJob(attr
->values
[0].integer
);
5901 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
5902 attr
->values
[0].integer
);
5913 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
5915 con
, NULL
)) != HTTP_OK
)
5917 send_http_error(con
, status
);
5922 * Copy the subscription attributes to the response using the
5923 * requested-attributes attribute that may be provided by the client.
5926 ra
= create_requested_array(con
->request
);
5928 if ((attr
= ippFindAttribute(con
->request
, "limit",
5929 IPP_TAG_INTEGER
)) != NULL
)
5930 limit
= attr
->values
[0].integer
;
5935 * See if we only want to see subscriptions for a specific user...
5938 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
5939 IPP_TAG_BOOLEAN
)) != NULL
&&
5940 attr
->values
[0].boolean
)
5941 strlcpy(username
, get_username(con
), sizeof(username
));
5945 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
5947 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
5948 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
5949 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
5951 ippAddSeparator(con
->response
);
5952 copy_subscription_attrs(con
, sub
, ra
);
5955 if (limit
&& count
>= limit
)
5959 cupsArrayDelete(ra
);
5962 con
->response
->request
.status
.status_code
= IPP_OK
;
5964 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
5969 * 'get_username()' - Get the username associated with a request.
5972 static const char * /* O - Username */
5973 get_username(cupsd_client_t
*con
) /* I - Connection */
5975 ipp_attribute_t
*attr
; /* Attribute */
5978 if (con
->username
[0])
5979 return (con
->username
);
5980 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
5981 IPP_TAG_NAME
)) != NULL
)
5982 return (attr
->values
[0].string
.text
);
5984 return ("anonymous");
5989 * 'hold_job()' - Hold a print job.
5993 hold_job(cupsd_client_t
*con
, /* I - Client connection */
5994 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
5996 ipp_attribute_t
*attr
, /* Current job-hold-until */
5997 *newattr
; /* New job-hold-until */
5998 int jobid
; /* Job ID */
5999 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6000 username
[HTTP_MAX_URI
], /* Username portion of URI */
6001 host
[HTTP_MAX_URI
], /* Host portion of URI */
6002 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6003 int port
; /* Port portion of URI */
6004 cupsd_job_t
*job
; /* Job information */
6007 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
6008 uri
->values
[0].string
.text
);
6011 * See if we have a job URI or a printer URI...
6014 if (!strcmp(uri
->name
, "printer-uri"))
6017 * Got a printer URI; see if we also have a job-id attribute...
6020 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6021 IPP_TAG_INTEGER
)) == NULL
)
6023 send_ipp_status(con
, IPP_BAD_REQUEST
,
6024 _("Got a printer-uri attribute but no job-id!"));
6028 jobid
= attr
->values
[0].integer
;
6033 * Got a job URI; parse it to get the job ID...
6036 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6037 sizeof(method
), username
, sizeof(username
), host
,
6038 sizeof(host
), &port
, resource
, sizeof(resource
));
6040 if (strncmp(resource
, "/jobs/", 6))
6046 send_ipp_status(con
, IPP_BAD_REQUEST
,
6047 _("Bad job-uri attribute \"%s\"!"),
6048 uri
->values
[0].string
.text
);
6052 jobid
= atoi(resource
+ 6);
6056 * See if the job exists...
6059 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6062 * Nope - return a "not found" error...
6065 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6070 * See if the job is owned by the requesting user...
6073 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6075 send_ipp_status(con
, IPP_FORBIDDEN
,
6076 _("Not authorized to hold job #%d owned by \"%s\"!"),
6077 jobid
, job
->username
);
6082 * Hold the job and return...
6087 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
6088 IPP_TAG_KEYWORD
)) == NULL
)
6089 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
6091 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
6092 IPP_TAG_KEYWORD
)) == NULL
)
6093 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
6098 * Free the old hold value and copy the new one over...
6101 _cups_sp_free(attr
->values
[0].string
.text
);
6105 attr
->value_tag
= newattr
->value_tag
;
6106 attr
->values
[0].string
.text
=
6107 _cups_sp_alloc(newattr
->values
[0].string
.text
);
6111 attr
->value_tag
= IPP_TAG_KEYWORD
;
6112 attr
->values
[0].string
.text
= _cups_sp_alloc("indefinite");
6116 * Hold job until specified time...
6119 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
6122 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was held by \"%s\".", jobid
,
6125 con
->response
->request
.status
.status_code
= IPP_OK
;
6130 * 'move_job()' - Move a job to a new destination.
6134 move_job(cupsd_client_t
*con
, /* I - Client connection */
6135 ipp_attribute_t
*uri
) /* I - Job URI */
6137 http_status_t status
; /* Policy status */
6138 ipp_attribute_t
*attr
; /* Current attribute */
6139 int jobid
; /* Job ID */
6140 cupsd_job_t
*job
; /* Current job */
6141 const char *src
, /* Source printer/class */
6142 *dest
; /* Destination */
6143 cups_ptype_t stype
, /* Source type (printer or class) */
6144 dtype
; /* Destination type (printer or class) */
6145 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6146 username
[HTTP_MAX_URI
], /* Username portion of URI */
6147 host
[HTTP_MAX_URI
], /* Host portion of URI */
6148 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6149 int port
; /* Port portion of URI */
6150 cupsd_printer_t
*sprinter
, /* Source printer */
6151 *dprinter
; /* Destination printer */
6154 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
6155 uri
->values
[0].string
.text
);
6158 * Get the new printer or class...
6161 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
6162 IPP_TAG_URI
)) == NULL
)
6165 * Need job-printer-uri...
6168 send_ipp_status(con
, IPP_BAD_REQUEST
,
6169 _("job-printer-uri attribute missing!"));
6173 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[0].string
.text
, method
,
6174 sizeof(method
), username
, sizeof(username
), host
,
6175 sizeof(host
), &port
, resource
, sizeof(resource
));
6177 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &dprinter
)) == NULL
)
6183 send_ipp_status(con
, IPP_NOT_FOUND
,
6184 _("The printer or class was not found."));
6192 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6194 send_http_error(con
, status
);
6199 * See if we have a job URI or a printer URI...
6202 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6203 sizeof(method
), username
, sizeof(username
), host
,
6204 sizeof(host
), &port
, resource
, sizeof(resource
));
6206 if (!strcmp(uri
->name
, "printer-uri"))
6209 * Got a printer URI; see if we also have a job-id attribute...
6212 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6213 IPP_TAG_INTEGER
)) == NULL
)
6219 if ((src
= cupsdValidateDest(host
, resource
, &stype
, &sprinter
)) == NULL
)
6225 send_ipp_status(con
, IPP_NOT_FOUND
,
6226 _("The printer or class was not found."));
6235 * Otherwise, just move a single job...
6238 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
6241 * Nope - return a "not found" error...
6244 send_ipp_status(con
, IPP_NOT_FOUND
,
6245 _("Job #%d does not exist!"), attr
->values
[0].integer
);
6251 * Job found, initialize source pointers...
6262 * Got a job URI; parse it to get the job ID...
6265 if (strncmp(resource
, "/jobs/", 6))
6271 send_ipp_status(con
, IPP_BAD_REQUEST
,
6272 _("Bad job-uri attribute \"%s\"!"),
6273 uri
->values
[0].string
.text
);
6278 * See if the job exists...
6281 jobid
= atoi(resource
+ 6);
6283 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6286 * Nope - return a "not found" error...
6289 send_ipp_status(con
, IPP_NOT_FOUND
,
6290 _("Job #%d does not exist!"), jobid
);
6296 * Job found, initialize source pointers...
6305 * Now move the job or jobs...
6311 * See if the job has been completed...
6314 if (job
->state
->values
[0].integer
> IPP_JOB_STOPPED
)
6317 * Return a "not-possible" error...
6320 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6321 _("Job #%d is finished and cannot be altered!"),
6327 * See if the job is owned by the requesting user...
6330 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6332 send_ipp_status(con
, IPP_FORBIDDEN
,
6333 _("You are not authorized to move job #%d owned "
6335 job
->id
, job
->username
);
6340 * Move the job to a different printer or class...
6343 cupsdMoveJob(job
, dest
);
6348 * Got the source printer, now look through the jobs...
6351 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
6353 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
6356 * See if the job is pointing at the source printer or has not been
6360 if (strcasecmp(job
->dest
, src
) ||
6361 job
->state
->values
[0].integer
> IPP_JOB_STOPPED
)
6365 * See if the job can be moved by the requesting user...
6368 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6372 * Move the job to a different printer or class...
6375 cupsdMoveJob(job
, dest
);
6380 * Start jobs if possible...
6386 * Return with "everything is OK" status...
6389 con
->response
->request
.status
.status_code
= IPP_OK
;
6394 * 'ppd_add_default()' - Add a PPD default choice.
6397 static int /* O - Number of defaults */
6399 const char *option
, /* I - Option name */
6400 const char *choice
, /* I - Choice name */
6401 int num_defaults
, /* I - Number of defaults */
6402 ppd_default_t
**defaults
) /* IO - Defaults */
6404 int i
; /* Looping var */
6405 ppd_default_t
*temp
; /* Temporary defaults array */
6409 * First check if the option already has a default value; the PPD spec
6410 * says that the first one is used...
6413 for (i
= 0, temp
= *defaults
; i
< num_defaults
; i
++)
6414 if (!strcmp(option
, temp
[i
].option
))
6415 return (num_defaults
);
6418 * Now add the option...
6421 if (num_defaults
== 0)
6422 temp
= malloc(sizeof(ppd_default_t
));
6424 temp
= realloc(*defaults
, (num_defaults
+ 1) * sizeof(ppd_default_t
));
6428 cupsdLogMessage(CUPSD_LOG_ERROR
, "ppd_add_default: Unable to add default value for \"%s\" - %s",
6429 option
, strerror(errno
));
6430 return (num_defaults
);
6434 temp
+= num_defaults
;
6436 strlcpy(temp
->option
, option
, sizeof(temp
->option
));
6437 strlcpy(temp
->choice
, choice
, sizeof(temp
->choice
));
6439 return (num_defaults
+ 1);
6444 * 'ppd_parse_line()' - Parse a PPD default line.
6447 static int /* O - 0 on success, -1 on failure */
6448 ppd_parse_line(const char *line
, /* I - Line */
6449 char *option
, /* O - Option name */
6450 int olen
, /* I - Size of option name */
6451 char *choice
, /* O - Choice name */
6452 int clen
) /* I - Size of choice name */
6455 * Verify this is a default option line...
6458 if (strncmp(line
, "*Default", 8))
6462 * Read the option name...
6465 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
6475 * Skip everything else up to the colon (:)...
6478 while (*line
&& *line
!= ':')
6487 * Now grab the option choice, skipping leading whitespace...
6490 while (isspace(*line
& 255))
6493 for (clen
--; isalnum(*line
& 255); line
++)
6503 * Return with no errors...
6511 * 'print_job()' - Print a file to a printer or class.
6515 print_job(cupsd_client_t
*con
, /* I - Client connection */
6516 ipp_attribute_t
*uri
) /* I - Printer URI */
6518 http_status_t status
; /* Policy status */
6519 ipp_attribute_t
*attr
; /* Current attribute */
6520 ipp_attribute_t
*format
; /* Document-format attribute */
6521 const char *dest
; /* Destination */
6522 cups_ptype_t dtype
; /* Destination type (printer or class) */
6523 int priority
; /* Job priority */
6524 char *title
; /* Job name/title */
6525 cupsd_job_t
*job
; /* Current job */
6526 char job_uri
[HTTP_MAX_URI
], /* Job URI */
6527 method
[HTTP_MAX_URI
], /* Method portion of URI */
6528 username
[HTTP_MAX_URI
], /* Username portion of URI */
6529 host
[HTTP_MAX_URI
], /* Host portion of URI */
6530 resource
[HTTP_MAX_URI
], /* Resource portion of URI */
6531 filename
[1024]; /* Job filename */
6532 int port
; /* Port portion of URI */
6533 mime_type_t
*filetype
; /* Type of file */
6534 char super
[MIME_MAX_SUPER
], /* Supertype of file */
6535 type
[MIME_MAX_TYPE
], /* Subtype of file */
6536 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
6537 /* Textual name of mime type */
6538 cupsd_printer_t
*printer
; /* Printer data */
6539 struct stat fileinfo
; /* File information */
6540 int kbytes
; /* Size of file */
6541 int i
; /* Looping var */
6542 int lowerpagerange
; /* Page range bound */
6543 int compression
; /* Document compression */
6546 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
6547 uri
->values
[0].string
.text
);
6550 * Validate job template attributes; for now just copies and page-ranges...
6553 if ((attr
= ippFindAttribute(con
->request
, "copies",
6554 IPP_TAG_INTEGER
)) != NULL
)
6556 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
6558 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
6559 attr
->values
[0].integer
);
6560 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
6561 "copies", attr
->values
[0].integer
);
6566 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
6567 IPP_TAG_RANGE
)) != NULL
)
6569 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
6571 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
6572 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
6574 send_ipp_status(con
, IPP_BAD_REQUEST
,
6575 _("Bad page-ranges values %d-%d."),
6576 attr
->values
[i
].range
.lower
,
6577 attr
->values
[i
].range
.upper
);
6581 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
6586 * OK, see if the client is sending the document compressed - CUPS
6587 * only supports "none" and "gzip".
6590 compression
= CUPS_FILE_NONE
;
6592 if ((attr
= ippFindAttribute(con
->request
, "compression",
6593 IPP_TAG_KEYWORD
)) != NULL
)
6595 if (strcmp(attr
->values
[0].string
.text
, "none")
6597 && strcmp(attr
->values
[0].string
.text
, "gzip")
6598 #endif /* HAVE_LIBZ */
6601 send_ipp_status(con
, IPP_ATTRIBUTES
,
6602 _("Unsupported compression \"%s\"!"),
6603 attr
->values
[0].string
.text
);
6604 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6605 "compression", NULL
, attr
->values
[0].string
.text
);
6610 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
6611 compression
= CUPS_FILE_GZIP
;
6612 #endif /* HAVE_LIBZ */
6616 * Do we have a file to print?
6621 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
6626 * Is it a format we support?
6629 if ((format
= ippFindAttribute(con
->request
, "document-format",
6630 IPP_TAG_MIMETYPE
)) != NULL
)
6633 * Grab format from client...
6636 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
6638 send_ipp_status(con
, IPP_BAD_REQUEST
,
6639 _("Could not scan type \"%s\"!"),
6640 format
->values
[0].string
.text
);
6647 * No document format attribute? Auto-type it!
6650 strcpy(super
, "application");
6651 strcpy(type
, "octet-stream");
6654 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
6657 * Auto-type the file...
6660 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: auto-typing file...");
6662 filetype
= mimeFileType(MimeDatabase
, con
->filename
, NULL
, &compression
);
6667 * Replace the document-format attribute value with the auto-typed one.
6670 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
6675 _cups_sp_free(format
->values
[0].string
.text
);
6677 format
->values
[0].string
.text
= _cups_sp_alloc(mimetype
);
6680 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
6681 "document-format", NULL
, mimetype
);
6684 filetype
= mimeType(MimeDatabase
, super
, type
);
6687 filetype
= mimeType(MimeDatabase
, super
, type
);
6691 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
6692 _("Unsupported format \'%s/%s\'!"), super
, type
);
6693 cupsdLogMessage(CUPSD_LOG_INFO
,
6694 "Hint: Do you have the raw file printing rules enabled?");
6697 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
6698 "document-format", NULL
, format
->values
[0].string
.text
);
6703 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: request file type is %s/%s.",
6704 filetype
->super
, filetype
->type
);
6707 * Read any embedded job ticket info from PS files...
6710 if (!strcasecmp(filetype
->super
, "application") &&
6711 !strcasecmp(filetype
->type
, "postscript"))
6712 read_ps_job_ticket(con
);
6715 * Is the destination valid?
6718 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6719 sizeof(method
), username
, sizeof(username
), host
,
6720 sizeof(host
), &port
, resource
, sizeof(resource
));
6722 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
6728 send_ipp_status(con
, IPP_NOT_FOUND
,
6729 _("The printer or class was not found."));
6734 * Check remote printing to non-shared printer...
6737 if (!printer
->shared
&&
6738 strcasecmp(con
->http
.hostname
, "localhost") &&
6739 strcasecmp(con
->http
.hostname
, ServerName
))
6741 send_ipp_status(con
, IPP_NOT_AUTHORIZED
, _("Printer not shared!"));
6749 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6751 send_http_error(con
, status
);
6754 else if ((printer
->type
& CUPS_PRINTER_AUTHENTICATED
) && !con
->username
[0])
6756 send_http_error(con
, status
);
6761 * See if the printer is accepting jobs...
6764 if (!printer
->accepting
)
6766 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
6767 _("Destination \"%s\" is not accepting jobs."), dest
);
6772 * Make sure we aren't over our limit...
6775 if (cupsArrayCount(Jobs
) >= MaxJobs
&& MaxJobs
)
6778 if (cupsArrayCount(Jobs
) >= MaxJobs
&& MaxJobs
)
6780 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6781 _("Too many jobs - %d jobs, max jobs is %d."),
6782 cupsArrayCount(Jobs
), MaxJobs
);
6786 if (!check_quotas(con
, printer
))
6788 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
6793 * Create the job and set things up...
6796 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
6797 IPP_TAG_INTEGER
)) != NULL
)
6798 priority
= attr
->values
[0].integer
;
6800 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
6803 if ((attr
= ippFindAttribute(con
->request
, "job-name",
6804 IPP_TAG_NAME
)) != NULL
)
6805 title
= attr
->values
[0].string
.text
;
6807 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
6808 title
= "Untitled");
6810 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
6812 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
6813 _("Unable to add job for destination \"%s\"!"), dest
);
6818 job
->attrs
= con
->request
;
6819 con
->request
= NULL
;
6822 * Copy the rest of the job info...
6825 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
6827 if (con
->username
[0])
6829 cupsdSetString(&job
->username
, con
->username
);
6832 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
6834 save_auth_info(con
, job
);
6838 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: requesting-user-name = \"%s\"",
6839 attr
->values
[0].string
.text
);
6841 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
6844 cupsdSetString(&job
->username
, "anonymous");
6847 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
6848 "job-originating-user-name", NULL
, job
->username
);
6851 attr
->group_tag
= IPP_TAG_JOB
;
6852 cupsdSetString(&attr
->name
, "job-originating-user-name");
6856 * Add remaining job attributes...
6859 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
6860 IPP_TAG_ZERO
)) != NULL
)
6863 * Request contains a job-originating-host-name attribute; validate it...
6866 if (attr
->value_tag
!= IPP_TAG_NAME
||
6867 attr
->num_values
!= 1 ||
6868 strcmp(con
->http
.hostname
, "localhost"))
6871 * Can't override the value if we aren't connected via localhost.
6872 * Also, we can only have 1 value and it must be a name value.
6875 switch (attr
->value_tag
)
6877 case IPP_TAG_STRING
:
6878 case IPP_TAG_TEXTLANG
:
6879 case IPP_TAG_NAMELANG
:
6882 case IPP_TAG_KEYWORD
:
6884 case IPP_TAG_URISCHEME
:
6885 case IPP_TAG_CHARSET
:
6886 case IPP_TAG_LANGUAGE
:
6887 case IPP_TAG_MIMETYPE
:
6889 * Free old strings...
6892 for (i
= 0; i
< attr
->num_values
; i
++)
6894 _cups_sp_free(attr
->values
[i
].string
.text
);
6895 attr
->values
[i
].string
.text
= NULL
;
6896 if (attr
->values
[i
].string
.charset
)
6898 _cups_sp_free(attr
->values
[i
].string
.charset
);
6899 attr
->values
[i
].string
.charset
= NULL
;
6908 * Use the default connection hostname instead...
6911 attr
->value_tag
= IPP_TAG_NAME
;
6912 attr
->num_values
= 1;
6913 attr
->values
[0].string
.text
= _cups_sp_alloc(con
->http
.hostname
);
6916 attr
->group_tag
= IPP_TAG_JOB
;
6921 * No job-originating-host-name attribute, so use the hostname from
6925 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
6926 "job-originating-host-name", NULL
, con
->http
.hostname
);
6929 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
6930 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
6931 "job-state", IPP_JOB_PENDING
);
6932 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
6933 "job-media-sheets-completed", 0);
6934 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
6936 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
6939 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
6940 IPP_TAG_INTEGER
)) == NULL
)
6941 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
6944 if (stat(con
->filename
, &fileinfo
))
6947 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
6949 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
6950 attr
->values
[0].integer
+= kbytes
;
6952 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
6954 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
6955 "time-at-processing", 0);
6956 attr
->value_tag
= IPP_TAG_NOVALUE
;
6957 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
6958 "time-at-completed", 0);
6959 attr
->value_tag
= IPP_TAG_NOVALUE
;
6961 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
6962 IPP_TAG_KEYWORD
)) == NULL
)
6963 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
6965 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
6966 "job-hold-until", NULL
, "no-hold");
6968 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
6969 !(printer
->type
& CUPS_PRINTER_REMOTE
))
6972 * Hold job until specified time...
6975 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
6976 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
6979 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
6983 * Add job sheets options...
6986 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
6987 IPP_TAG_ZERO
)) == NULL
)
6989 cupsdLogMessage(CUPSD_LOG_DEBUG
,
6990 "Adding default job-sheets values \"%s,%s\"...",
6991 printer
->job_sheets
[0], printer
->job_sheets
[1]);
6993 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
6995 attr
->values
[0].string
.text
= _cups_sp_alloc(printer
->job_sheets
[0]);
6996 attr
->values
[1].string
.text
= _cups_sp_alloc(printer
->job_sheets
[1]);
6999 job
->job_sheets
= attr
;
7002 * Enforce classification level if set...
7007 cupsdLogMessage(CUPSD_LOG_INFO
,
7008 "Classification=\"%s\", ClassifyOverride=%d",
7009 Classification
? Classification
: "(null)",
7012 if (ClassifyOverride
)
7014 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
7015 (attr
->num_values
== 1 ||
7016 !strcmp(attr
->values
[1].string
.text
, "none")))
7019 * Force the leading banner to have the classification on it...
7022 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
7024 cupsdLogMessage(CUPSD_LOG_NOTICE
,
7025 "[Job %d] CLASSIFICATION FORCED "
7026 "job-sheets=\"%s,none\", "
7027 "job-originating-user-name=\"%s\"",
7028 job
->id
, Classification
, job
->username
);
7030 else if (attr
->num_values
== 2 &&
7031 strcmp(attr
->values
[0].string
.text
,
7032 attr
->values
[1].string
.text
) &&
7033 strcmp(attr
->values
[0].string
.text
, "none") &&
7034 strcmp(attr
->values
[1].string
.text
, "none"))
7037 * Can't put two different security markings on the same document!
7040 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
7042 cupsdLogMessage(CUPSD_LOG_NOTICE
,
7043 "[Job %d] CLASSIFICATION FORCED "
7044 "job-sheets=\"%s,%s\", "
7045 "job-originating-user-name=\"%s\"",
7046 job
->id
, attr
->values
[0].string
.text
,
7047 attr
->values
[1].string
.text
, job
->username
);
7049 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
7050 strcmp(attr
->values
[0].string
.text
, "none") &&
7051 (attr
->num_values
== 1 ||
7052 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
7053 strcmp(attr
->values
[1].string
.text
, "none"))))
7055 if (attr
->num_values
== 1)
7056 cupsdLogMessage(CUPSD_LOG_NOTICE
,
7057 "[Job %d] CLASSIFICATION OVERRIDDEN "
7058 "job-sheets=\"%s\", "
7059 "job-originating-user-name=\"%s\"",
7060 job
->id
, attr
->values
[0].string
.text
,
7063 cupsdLogMessage(CUPSD_LOG_NOTICE
,
7064 "[Job %d] CLASSIFICATION OVERRIDDEN "
7065 "job-sheets=\"%s,%s\", "
7066 "job-originating-user-name=\"%s\"",
7067 job
->id
, attr
->values
[0].string
.text
,
7068 attr
->values
[1].string
.text
, job
->username
);
7071 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
7072 (attr
->num_values
== 1 ||
7073 strcmp(attr
->values
[1].string
.text
, Classification
)))
7076 * Force the banner to have the classification on it...
7079 if (attr
->num_values
> 1 &&
7080 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
7082 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
7083 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
7087 if (attr
->num_values
== 1 ||
7088 strcmp(attr
->values
[0].string
.text
, "none"))
7089 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
7091 if (attr
->num_values
> 1 &&
7092 strcmp(attr
->values
[1].string
.text
, "none"))
7093 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
7096 if (attr
->num_values
> 1)
7097 cupsdLogMessage(CUPSD_LOG_NOTICE
,
7098 "[Job %d] CLASSIFICATION FORCED "
7099 "job-sheets=\"%s,%s\", "
7100 "job-originating-user-name=\"%s\"",
7101 job
->id
, attr
->values
[0].string
.text
,
7102 attr
->values
[1].string
.text
, job
->username
);
7104 cupsdLogMessage(CUPSD_LOG_NOTICE
,
7105 "[Job %d] CLASSIFICATION FORCED "
7106 "job-sheets=\"%s\", "
7107 "job-originating-user-name=\"%s\"",
7108 job
->id
, Classification
, job
->username
);
7113 * Add the starting sheet...
7116 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
7118 cupsdLogMessage(CUPSD_LOG_INFO
,
7119 "Adding start banner page \"%s\" to job %d.",
7120 attr
->values
[0].string
.text
, job
->id
);
7122 kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
);
7124 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
7127 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
7128 IPP_TAG_ZERO
)) != NULL
)
7132 * Add the job file...
7135 if (add_file(con
, job
, filetype
, compression
))
7138 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
7140 rename(con
->filename
, filename
);
7141 cupsdClearString(&con
->filename
);
7144 * See if we need to add the ending sheet...
7147 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
7148 attr
->num_values
> 1)
7154 cupsdLogMessage(CUPSD_LOG_INFO
, "Adding end banner page \"%s\" to job %d.",
7155 attr
->values
[1].string
.text
, job
->id
);
7157 kbytes
= copy_banner(con
, job
, attr
->values
[1].string
.text
);
7159 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
7163 * Fill in the response info...
7166 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
7167 LocalPort
, job
->id
);
7169 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
7172 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
7174 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
7175 job
->state
->values
[0].integer
);
7176 add_job_state_reasons(con
, job
);
7178 con
->response
->request
.status
.status_code
= IPP_OK
;
7181 * Add any job subscriptions...
7184 add_job_subscriptions(con
, job
);
7187 * Set all but the first two attributes to the job attributes group...
7190 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
7191 attr
->group_tag
= IPP_TAG_JOB
;
7194 * Log and save the job...
7197 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d queued on \"%s\" by \"%s\".", job
->id
,
7198 job
->dest
, job
->username
);
7199 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Job %d hold_until = %d", job
->id
,
7200 (int)job
->hold_until
);
7204 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
7207 * Start the job if possible...
7215 * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
7217 * This function only gets called when printing a single PostScript
7218 * file using the Print-Job operation. It doesn't work for Create-Job +
7219 * Send-File, since the job attributes need to be set at job creation
7220 * time for banners to work. The embedded PS job ticket stuff is here
7221 * only to allow the Windows printer driver for CUPS to pass in JCL
7222 * options and IPP attributes which otherwise would be lost.
7224 * The format of a PS job ticket is simple:
7226 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
7228 * %cupsJobTicket: attr1=value1
7229 * %cupsJobTicket: attr2=value2
7231 * %cupsJobTicket: attrN=valueN
7233 * Job ticket lines must appear immediately after the first line that
7234 * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
7235 * looking for job ticket info when it finds a line that does not begin
7236 * with "%cupsJobTicket:".
7238 * The maximum length of a job ticket line, including the prefix, is
7239 * 255 characters to conform with the Adobe DSC.
7241 * Read-only attributes are rejected with a notice to the error log in
7242 * case a malicious user tries anything. Since the job ticket is read
7243 * prior to attribute validation in print_job(), job ticket attributes
7244 * will go through the same validation as IPP attributes...
7248 read_ps_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
7250 cups_file_t
*fp
; /* File to read from */
7251 char line
[256]; /* Line data */
7252 int num_options
; /* Number of options */
7253 cups_option_t
*options
; /* Options */
7254 ipp_t
*ticket
; /* New attributes */
7255 ipp_attribute_t
*attr
, /* Current attribute */
7256 *attr2
, /* Job attribute */
7257 *prev2
; /* Previous job attribute */
7261 * First open the print file...
7264 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
7266 cupsdLogMessage(CUPSD_LOG_ERROR
,
7267 "read_ps_job_ticket: Unable to open PostScript print file "
7274 * Skip the first line...
7277 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
7279 cupsdLogMessage(CUPSD_LOG_ERROR
,
7280 "read_ps_job_ticket: Unable to read from PostScript print "
7287 if (strncmp(line
, "%!PS-Adobe-", 11))
7290 * Not a DSC-compliant file, so no job ticket info will be available...
7298 * Read job ticket info from the file...
7304 while (cupsFileGets(fp
, line
, sizeof(line
)))
7307 * Stop at the first non-ticket line...
7310 if (strncmp(line
, "%cupsJobTicket:", 15))
7314 * Add the options to the option array...
7317 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
7321 * Done with the file; see if we have any options...
7326 if (num_options
== 0)
7330 * OK, convert the options to an attribute list, and apply them to
7335 cupsEncodeOptions(ticket
, num_options
, options
);
7338 * See what the user wants to change.
7341 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
7343 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
7346 if (!strcmp(attr
->name
, "job-originating-host-name") ||
7347 !strcmp(attr
->name
, "job-originating-user-name") ||
7348 !strcmp(attr
->name
, "job-media-sheets-completed") ||
7349 !strcmp(attr
->name
, "job-k-octets") ||
7350 !strcmp(attr
->name
, "job-id") ||
7351 !strncmp(attr
->name
, "job-state", 9) ||
7352 !strncmp(attr
->name
, "time-at-", 8))
7353 continue; /* Read-only attrs */
7355 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
7356 IPP_TAG_ZERO
)) != NULL
)
7359 * Some other value; first free the old value...
7362 if (con
->request
->attrs
== attr2
)
7364 con
->request
->attrs
= attr2
->next
;
7369 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
7370 if (prev2
->next
== attr2
)
7372 prev2
->next
= attr2
->next
;
7377 if (con
->request
->last
== attr2
)
7378 con
->request
->last
= prev2
;
7380 _ipp_free_attr(attr2
);
7384 * Add new option by copying it...
7387 copy_attribute(con
->request
, attr
, 0);
7391 * Then free the attribute list and option array...
7395 cupsFreeOptions(num_options
, options
);
7400 * 'reject_jobs()' - Reject print jobs to a printer.
7404 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
7405 ipp_attribute_t
*uri
) /* I - Printer or class URI */
7407 http_status_t status
; /* Policy status */
7408 cups_ptype_t dtype
; /* Destination type (printer or class) */
7409 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7410 username
[HTTP_MAX_URI
], /* Username portion of URI */
7411 host
[HTTP_MAX_URI
], /* Host portion of URI */
7412 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7413 int port
; /* Port portion of URI */
7414 const char *name
; /* Printer name */
7415 cupsd_printer_t
*printer
; /* Printer data */
7416 ipp_attribute_t
*attr
; /* printer-state-message text */
7419 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
7420 con
->http
.fd
, uri
->values
[0].string
.text
);
7423 * Is the destination valid?
7426 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7427 sizeof(method
), username
, sizeof(username
), host
,
7428 sizeof(host
), &port
, resource
, sizeof(resource
));
7430 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
7436 send_ipp_status(con
, IPP_NOT_FOUND
,
7437 _("The printer or class was not found."));
7445 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7447 send_http_error(con
, status
);
7452 * Reject jobs sent to the printer...
7455 printer
->accepting
= 0;
7457 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
7458 IPP_TAG_TEXT
)) == NULL
)
7459 strcpy(printer
->state_message
, "Rejecting Jobs");
7461 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
7462 sizeof(printer
->state_message
));
7464 cupsdAddPrinterHistory(printer
);
7466 if (dtype
& CUPS_PRINTER_CLASS
)
7468 cupsdSaveAllClasses();
7470 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
7471 name
, get_username(con
));
7475 cupsdSaveAllPrinters();
7477 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
7478 name
, get_username(con
));
7482 * Everything was ok, so return OK status...
7485 con
->response
->request
.status
.status_code
= IPP_OK
;
7490 * 'release_job()' - Release a held print job.
7494 release_job(cupsd_client_t
*con
, /* I - Client connection */
7495 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7497 ipp_attribute_t
*attr
; /* Current attribute */
7498 int jobid
; /* Job ID */
7499 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7500 username
[HTTP_MAX_URI
], /* Username portion of URI */
7501 host
[HTTP_MAX_URI
], /* Host portion of URI */
7502 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7503 int port
; /* Port portion of URI */
7504 cupsd_job_t
*job
; /* Job information */
7507 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
7508 con
->http
.fd
, uri
->values
[0].string
.text
);
7511 * See if we have a job URI or a printer URI...
7514 if (!strcmp(uri
->name
, "printer-uri"))
7517 * Got a printer URI; see if we also have a job-id attribute...
7520 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7521 IPP_TAG_INTEGER
)) == NULL
)
7523 send_ipp_status(con
, IPP_BAD_REQUEST
,
7524 _("Got a printer-uri attribute but no job-id!"));
7528 jobid
= attr
->values
[0].integer
;
7533 * Got a job URI; parse it to get the job ID...
7536 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7537 sizeof(method
), username
, sizeof(username
), host
,
7538 sizeof(host
), &port
, resource
, sizeof(resource
));
7540 if (strncmp(resource
, "/jobs/", 6))
7546 send_ipp_status(con
, IPP_BAD_REQUEST
,
7547 _("Bad job-uri attribute \"%s\"!"),
7548 uri
->values
[0].string
.text
);
7552 jobid
= atoi(resource
+ 6);
7556 * See if the job exists...
7559 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7562 * Nope - return a "not found" error...
7565 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7570 * See if job is "held"...
7573 if (job
->state
->values
[0].integer
!= IPP_JOB_HELD
)
7576 * Nope - return a "not possible" error...
7579 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
7584 * See if the job is owned by the requesting user...
7587 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7589 send_ipp_status(con
, IPP_FORBIDDEN
,
7590 _("You are not authorized to release job id "
7591 "%d owned by \"%s\"!"),
7592 jobid
, job
->username
);
7597 * Reset the job-hold-until value to "no-hold"...
7600 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7601 IPP_TAG_KEYWORD
)) == NULL
)
7602 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7606 _cups_sp_free(attr
->values
[0].string
.text
);
7608 attr
->value_tag
= IPP_TAG_KEYWORD
;
7609 attr
->values
[0].string
.text
= _cups_sp_alloc("no-hold");
7613 * Release the job and return...
7616 cupsdReleaseJob(job
);
7618 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was released by \"%s\".", jobid
,
7621 con
->response
->request
.status
.status_code
= IPP_OK
;
7626 * 'renew_subscription()' - Renew an existing subscription...
7631 cupsd_client_t
*con
, /* I - Client connection */
7632 int sub_id
) /* I - Subscription ID */
7638 * 'restart_job()' - Restart an old print job.
7642 restart_job(cupsd_client_t
*con
, /* I - Client connection */
7643 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7645 ipp_attribute_t
*attr
; /* Current attribute */
7646 int jobid
; /* Job ID */
7647 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7648 username
[HTTP_MAX_URI
], /* Username portion of URI */
7649 host
[HTTP_MAX_URI
], /* Host portion of URI */
7650 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7651 int port
; /* Port portion of URI */
7652 cupsd_job_t
*job
; /* Job information */
7655 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
7656 con
->http
.fd
, uri
->values
[0].string
.text
);
7659 * See if we have a job URI or a printer URI...
7662 if (!strcmp(uri
->name
, "printer-uri"))
7665 * Got a printer URI; see if we also have a job-id attribute...
7668 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7669 IPP_TAG_INTEGER
)) == NULL
)
7671 send_ipp_status(con
, IPP_BAD_REQUEST
,
7672 _("Got a printer-uri attribute but no job-id!"));
7676 jobid
= attr
->values
[0].integer
;
7681 * Got a job URI; parse it to get the job ID...
7684 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7685 sizeof(method
), username
, sizeof(username
), host
,
7686 sizeof(host
), &port
, resource
, sizeof(resource
));
7688 if (strncmp(resource
, "/jobs/", 6))
7694 send_ipp_status(con
, IPP_BAD_REQUEST
,
7695 _("Bad job-uri attribute \"%s\"!"),
7696 uri
->values
[0].string
.text
);
7700 jobid
= atoi(resource
+ 6);
7704 * See if the job exists...
7707 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7710 * Nope - return a "not found" error...
7713 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7718 * See if job is in any of the "completed" states...
7721 if (job
->state
->values
[0].integer
<= IPP_JOB_PROCESSING
)
7724 * Nope - return a "not possible" error...
7727 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
7733 * See if we have retained the job files...
7736 if (!JobFiles
&& job
->state
->values
[0].integer
> IPP_JOB_STOPPED
)
7739 * Nope - return a "not possible" error...
7742 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7743 _("Job #%d cannot be restarted - no files!"), jobid
);
7748 * See if the job is owned by the requesting user...
7751 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7753 send_ipp_status(con
, IPP_FORBIDDEN
,
7754 _("You are not authorized to restart job id "
7755 "%d owned by \"%s\"!"),
7756 jobid
, job
->username
);
7761 * Restart the job and return...
7764 cupsdRestartJob(job
);
7766 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was restarted by \"%s\".", jobid
,
7769 con
->response
->request
.status
.status_code
= IPP_OK
;
7774 * 'save_auth_info()' - Save authentication information for a job.
7778 save_auth_info(cupsd_client_t
*con
, /* I - Client connection */
7779 cupsd_job_t
*job
) /* I - Job */
7781 int i
; /* Looping var */
7782 char filename
[1024]; /* Job authentication filename */
7783 cups_file_t
*fp
; /* Job authentication file */
7784 char line
[1024]; /* Line for file */
7788 * This function saves the in-memory authentication information for
7789 * a job so that it can be used to authenticate with a remote host.
7790 * The information is stored in a file that is readable only by the
7791 * root user. The username and password are Base-64 encoded, each
7792 * on a separate line, followed by random number (up to 1024) of
7793 * newlines to limit the amount of information that is exposed.
7795 * Because of the potential for exposing of authentication information,
7796 * this functionality is only enabled when running cupsd as root.
7798 * This caching only works for the Basic and BasicDigest authentication
7799 * types. Digest authentication cannot be cached this way, and in
7800 * the future Kerberos authentication may make all of this obsolete.
7802 * Authentication information is saved whenever an authenticated
7803 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
7806 * This information is deleted after a job is completed or canceled,
7807 * so reprints may require subsequent re-authentication.
7814 * Create the authentication file and change permissions...
7817 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
7818 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
7820 cupsdLogMessage(CUPSD_LOG_ERROR
,
7821 "Unable to save authentication info to \"%s\" - %s",
7822 filename
, strerror(errno
));
7826 fchown(cupsFileNumber(fp
), 0, 0);
7827 fchmod(cupsFileNumber(fp
), 0400);
7830 * Write the authenticated username...
7833 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
7834 cupsFilePrintf(fp
, "%s\n", line
);
7837 * Write the authenticated password...
7840 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
7841 cupsFilePrintf(fp
, "%s\n", line
);
7844 * Write a random number of newlines to the end of the file...
7847 for (i
= (rand() % 1024); i
>= 0; i
--)
7848 cupsFilePutChar(fp
, '\n');
7851 * Close the file and return...
7859 * 'send_document()' - Send a file to a printer or class.
7863 send_document(cupsd_client_t
*con
, /* I - Client connection */
7864 ipp_attribute_t
*uri
) /* I - Printer URI */
7866 ipp_attribute_t
*attr
; /* Current attribute */
7867 ipp_attribute_t
*format
; /* Document-format attribute */
7868 int jobid
; /* Job ID number */
7869 cupsd_job_t
*job
; /* Current job */
7870 char job_uri
[HTTP_MAX_URI
],
7872 method
[HTTP_MAX_URI
],
7873 /* Method portion of URI */
7874 username
[HTTP_MAX_URI
],
7875 /* Username portion of URI */
7877 /* Host portion of URI */
7878 resource
[HTTP_MAX_URI
];
7879 /* Resource portion of URI */
7880 int port
; /* Port portion of URI */
7881 mime_type_t
*filetype
; /* Type of file */
7882 char super
[MIME_MAX_SUPER
],
7883 /* Supertype of file */
7884 type
[MIME_MAX_TYPE
],
7885 /* Subtype of file */
7886 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
7887 /* Textual name of mime type */
7888 char filename
[1024]; /* Job filename */
7889 cupsd_printer_t
*printer
; /* Current printer */
7890 struct stat fileinfo
; /* File information */
7891 int kbytes
; /* Size of file */
7892 int compression
; /* Type of compression */
7895 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
7896 con
->http
.fd
, uri
->values
[0].string
.text
);
7899 * See if we have a job URI or a printer URI...
7902 if (!strcmp(uri
->name
, "printer-uri"))
7905 * Got a printer URI; see if we also have a job-id attribute...
7908 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7909 IPP_TAG_INTEGER
)) == NULL
)
7911 send_ipp_status(con
, IPP_BAD_REQUEST
,
7912 _("Got a printer-uri attribute but no job-id!"));
7916 jobid
= attr
->values
[0].integer
;
7921 * Got a job URI; parse it to get the job ID...
7924 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7925 sizeof(method
), username
, sizeof(username
), host
,
7926 sizeof(host
), &port
, resource
, sizeof(resource
));
7928 if (strncmp(resource
, "/jobs/", 6))
7934 send_ipp_status(con
, IPP_BAD_REQUEST
,
7935 _("Bad job-uri attribute \"%s\"!"),
7936 uri
->values
[0].string
.text
);
7940 jobid
= atoi(resource
+ 6);
7944 * See if the job exists...
7947 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7950 * Nope - return a "not found" error...
7953 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7958 * See if the job is owned by the requesting user...
7961 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7963 send_ipp_status(con
, IPP_FORBIDDEN
,
7964 _("You are not authorized to send document "
7965 "for job #%d owned by \"%s\"!"),
7966 jobid
, job
->username
);
7971 * OK, see if the client is sending the document compressed - CUPS
7972 * only supports "none" and "gzip".
7975 compression
= CUPS_FILE_NONE
;
7977 if ((attr
= ippFindAttribute(con
->request
, "compression",
7978 IPP_TAG_KEYWORD
)) != NULL
)
7980 if (strcmp(attr
->values
[0].string
.text
, "none")
7982 && strcmp(attr
->values
[0].string
.text
, "gzip")
7983 #endif /* HAVE_LIBZ */
7986 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
7987 attr
->values
[0].string
.text
);
7988 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7989 "compression", NULL
, attr
->values
[0].string
.text
);
7994 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
7995 compression
= CUPS_FILE_GZIP
;
7996 #endif /* HAVE_LIBZ */
8000 * Do we have a file to print?
8005 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
8010 * Is it a format we support?
8013 if ((format
= ippFindAttribute(con
->request
, "document-format",
8014 IPP_TAG_MIMETYPE
)) != NULL
)
8017 * Grab format from client...
8020 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
8022 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
8023 format
->values
[0].string
.text
);
8030 * No document format attribute? Auto-type it!
8033 strcpy(super
, "application");
8034 strcpy(type
, "octet-stream");
8037 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
8040 * Auto-type the file...
8043 cupsdLogMessage(CUPSD_LOG_DEBUG
, "send_document: auto-typing file...");
8045 filetype
= mimeFileType(MimeDatabase
, con
->filename
, NULL
, &compression
);
8050 * Replace the document-format attribute value with the auto-typed one.
8053 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
8058 _cups_sp_free(format
->values
[0].string
.text
);
8059 format
->values
[0].string
.text
= _cups_sp_alloc(mimetype
);
8062 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
8063 "document-format", NULL
, mimetype
);
8066 filetype
= mimeType(MimeDatabase
, super
, type
);
8069 filetype
= mimeType(MimeDatabase
, super
, type
);
8073 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8074 _("Unsupported format \'%s/%s\'!"), super
, type
);
8075 cupsdLogMessage(CUPSD_LOG_INFO
,
8076 "Hint: Do you have the raw file printing rules enabled?");
8079 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8080 "document-format", NULL
, format
->values
[0].string
.text
);
8085 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8086 "send_document: request file type is %s/%s.",
8087 filetype
->super
, filetype
->type
);
8090 * Add the file to the job...
8093 if (add_file(con
, job
, filetype
, compression
))
8096 if (job
->dtype
& CUPS_PRINTER_CLASS
)
8097 printer
= cupsdFindClass(job
->dest
);
8099 printer
= cupsdFindPrinter(job
->dest
);
8101 if (stat(con
->filename
, &fileinfo
))
8104 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
8106 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8108 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
8109 IPP_TAG_INTEGER
)) != NULL
)
8110 attr
->values
[0].integer
+= kbytes
;
8112 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
8114 rename(con
->filename
, filename
);
8116 cupsdClearString(&con
->filename
);
8118 cupsdLogMessage(CUPSD_LOG_INFO
,
8119 "File of type %s/%s queued in job #%d by \"%s\".",
8120 filetype
->super
, filetype
->type
, job
->id
, job
->username
);
8123 * Start the job if this is the last document...
8126 if ((attr
= ippFindAttribute(con
->request
, "last-document",
8127 IPP_TAG_BOOLEAN
)) != NULL
&&
8128 attr
->values
[0].boolean
)
8131 * See if we need to add the ending sheet...
8135 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
8136 (attr
= ippFindAttribute(job
->attrs
, "job-sheets",
8137 IPP_TAG_ZERO
)) != NULL
&&
8138 attr
->num_values
> 1)
8144 cupsdLogMessage(CUPSD_LOG_INFO
,
8145 "Adding end banner page \"%s\" to job %d.",
8146 attr
->values
[1].string
.text
, job
->id
);
8148 kbytes
= copy_banner(con
, job
, attr
->values
[1].string
.text
);
8150 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
8153 if (job
->state
->values
[0].integer
== IPP_JOB_STOPPED
)
8154 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
8155 else if (job
->state
->values
[0].integer
== IPP_JOB_HELD
)
8157 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8158 IPP_TAG_KEYWORD
)) == NULL
)
8159 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8161 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
8162 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
8168 * Start the job if possible... Since cupsdCheckJobs() can cancel a
8169 * job if it doesn't print, we need to re-find the job afterwards...
8176 job
= cupsdFindJob(jobid
);
8180 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
8181 IPP_TAG_KEYWORD
)) == NULL
)
8182 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
8184 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
8186 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
8187 job
->hold_until
= time(NULL
) + 60;
8193 * Fill in the response info...
8196 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
8199 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
8202 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
8204 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
8205 job
? job
->state
->values
[0].integer
: IPP_JOB_CANCELLED
);
8206 add_job_state_reasons(con
, job
);
8208 con
->response
->request
.status
.status_code
= IPP_OK
;
8213 * 'send_http_error()' - Send a HTTP error back to the IPP client.
8217 send_http_error(cupsd_client_t
*con
, /* I - Client connection */
8218 http_status_t status
) /* I - HTTP status code */
8220 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s",
8221 ippOpString(con
->request
->request
.op
.operation_id
),
8222 httpStatus(status
));
8224 cupsdSendError(con
, status
);
8226 ippDelete(con
->response
);
8227 con
->response
= NULL
;
8234 * 'send_ipp_status()' - Send a status back to the IPP client.
8238 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
8239 ipp_status_t status
, /* I - IPP status code */
8240 const char *message
, /* I - Status message */
8241 ...) /* I - Additional args as needed */
8243 va_list ap
; /* Pointer to additional args */
8244 char formatted
[1024]; /* Formatted errror message */
8249 va_start(ap
, message
);
8250 vsnprintf(formatted
, sizeof(formatted
),
8251 _cupsLangString(con
->language
, message
), ap
);
8254 cupsdLogMessage(status
>= IPP_BAD_REQUEST
? CUPSD_LOG_ERROR
: CUPSD_LOG_INFO
,
8256 ippOpString(con
->request
->request
.op
.operation_id
),
8257 ippErrorString(status
), formatted
);
8260 cupsdLogMessage(status
>= IPP_BAD_REQUEST
? CUPSD_LOG_ERROR
: CUPSD_LOG_INFO
,
8262 ippOpString(con
->request
->request
.op
.operation_id
),
8263 ippErrorString(status
));
8265 con
->response
->request
.status
.status_code
= status
;
8267 if (ippFindAttribute(con
->response
, "attributes-charset",
8268 IPP_TAG_ZERO
) == NULL
)
8269 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
8270 "attributes-charset", NULL
, DefaultCharset
);
8272 if (ippFindAttribute(con
->response
, "attributes-natural-language",
8273 IPP_TAG_ZERO
) == NULL
)
8274 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
8275 "attributes-natural-language", NULL
, DefaultLanguage
);
8278 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
8279 "status-message", NULL
, formatted
);
8284 * 'set_default()' - Set the default destination...
8288 set_default(cupsd_client_t
*con
, /* I - Client connection */
8289 ipp_attribute_t
*uri
) /* I - Printer URI */
8291 http_status_t status
; /* Policy status */
8292 cups_ptype_t dtype
; /* Destination type (printer or class) */
8293 char method
[HTTP_MAX_URI
],
8294 /* Method portion of URI */
8295 username
[HTTP_MAX_URI
],
8296 /* Username portion of URI */
8298 /* Host portion of URI */
8299 resource
[HTTP_MAX_URI
];
8300 /* Resource portion of URI */
8301 int port
; /* Port portion of URI */
8302 const char *name
; /* Printer name */
8303 cupsd_printer_t
*printer
; /* Printer */
8306 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
8307 con
->http
.fd
, uri
->values
[0].string
.text
);
8310 * Is the destination valid?
8313 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8314 sizeof(method
), username
, sizeof(username
), host
,
8315 sizeof(host
), &port
, resource
, sizeof(resource
));
8317 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
8323 send_ipp_status(con
, IPP_NOT_FOUND
,
8324 _("The printer or class was not found."));
8332 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8334 send_http_error(con
, status
);
8339 * Set it as the default...
8342 DefaultPrinter
= printer
;
8344 cupsdSaveAllPrinters();
8345 cupsdSaveAllClasses();
8347 cupsdWritePrintcap();
8349 cupsdLogMessage(CUPSD_LOG_INFO
,
8350 "Default destination set to \"%s\" by \"%s\".", name
,
8354 * Everything was ok, so return OK status...
8357 con
->response
->request
.status
.status_code
= IPP_OK
;
8362 * 'set_job_attrs()' - Set job attributes.
8366 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
8367 ipp_attribute_t
*uri
) /* I - Job URI */
8369 ipp_attribute_t
*attr
, /* Current attribute */
8370 *attr2
; /* Job attribute */
8371 int jobid
; /* Job ID */
8372 cupsd_job_t
*job
; /* Current job */
8373 char method
[HTTP_MAX_URI
],
8374 /* Method portion of URI */
8375 username
[HTTP_MAX_URI
],
8376 /* Username portion of URI */
8378 /* Host portion of URI */
8379 resource
[HTTP_MAX_URI
];
8380 /* Resource portion of URI */
8381 int port
; /* Port portion of URI */
8384 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
8385 con
->http
.fd
, uri
->values
[0].string
.text
);
8388 * Start with "everything is OK" status...
8391 con
->response
->request
.status
.status_code
= IPP_OK
;
8394 * See if we have a job URI or a printer URI...
8397 if (!strcmp(uri
->name
, "printer-uri"))
8400 * Got a printer URI; see if we also have a job-id attribute...
8403 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8404 IPP_TAG_INTEGER
)) == NULL
)
8406 send_ipp_status(con
, IPP_BAD_REQUEST
,
8407 _("Got a printer-uri attribute but no job-id!"));
8411 jobid
= attr
->values
[0].integer
;
8416 * Got a job URI; parse it to get the job ID...
8419 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8420 sizeof(method
), username
, sizeof(username
), host
,
8421 sizeof(host
), &port
, resource
, sizeof(resource
));
8423 if (strncmp(resource
, "/jobs/", 6))
8429 send_ipp_status(con
, IPP_BAD_REQUEST
,
8430 _("Bad job-uri attribute \"%s\"!"),
8431 uri
->values
[0].string
.text
);
8435 jobid
= atoi(resource
+ 6);
8439 * See if the job exists...
8442 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8445 * Nope - return a "not found" error...
8448 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8453 * See if the job has been completed...
8456 if (job
->state
->values
[0].integer
> IPP_JOB_STOPPED
)
8459 * Return a "not-possible" error...
8462 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8463 _("Job #%d is finished and cannot be altered!"), jobid
);
8468 * See if the job is owned by the requesting user...
8471 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8473 send_ipp_status(con
, IPP_FORBIDDEN
,
8474 _("You are not authorized to alter job id "
8475 "%d owned by \"%s\"!"),
8476 jobid
, job
->username
);
8481 * See what the user wants to change.
8484 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
8486 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8489 if (!strcmp(attr
->name
, "attributes-charset") ||
8490 !strcmp(attr
->name
, "attributes-natural-language") ||
8491 !strcmp(attr
->name
, "document-compression") ||
8492 !strcmp(attr
->name
, "document-format") ||
8493 !strcmp(attr
->name
, "job-detailed-status-messages") ||
8494 !strcmp(attr
->name
, "job-document-access-errors") ||
8495 !strcmp(attr
->name
, "job-id") ||
8496 !strcmp(attr
->name
, "job-k-octets") ||
8497 !strcmp(attr
->name
, "job-originating-host-name") ||
8498 !strcmp(attr
->name
, "job-originating-user-name") ||
8499 !strcmp(attr
->name
, "job-printer-up-time") ||
8500 !strcmp(attr
->name
, "job-printer-uri") ||
8501 !strcmp(attr
->name
, "job-sheets") ||
8502 !strcmp(attr
->name
, "job-state-message") ||
8503 !strcmp(attr
->name
, "job-state-reasons") ||
8504 !strcmp(attr
->name
, "job-uri") ||
8505 !strcmp(attr
->name
, "number-of-documents") ||
8506 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
8507 !strcmp(attr
->name
, "output-device-assigned") ||
8508 !strncmp(attr
->name
, "date-time-at-", 13) ||
8509 !strncmp(attr
->name
, "job-impressions", 15) ||
8510 !strncmp(attr
->name
, "job-k-octets", 12) ||
8511 !strncmp(attr
->name
, "job-media-sheets", 16) ||
8512 !strncmp(attr
->name
, "time-at-", 8))
8518 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
8519 _("%s cannot be changed."), attr
->name
);
8521 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8522 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8527 if (!strcmp(attr
->name
, "job-priority"))
8530 * Change the job priority...
8533 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8535 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
8537 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8538 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8540 else if (job
->state
->values
[0].integer
>= IPP_JOB_PROCESSING
)
8542 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8543 _("Job is completed and cannot be changed."));
8546 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8547 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
8549 else if (!strcmp(attr
->name
, "job-state"))
8552 * Change the job state...
8555 if (attr
->value_tag
!= IPP_TAG_ENUM
)
8557 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
8559 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8560 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8564 switch (attr
->values
[0].integer
)
8566 case IPP_JOB_PENDING
:
8568 if (job
->state
->values
[0].integer
> IPP_JOB_HELD
)
8570 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8571 _("Job state cannot be changed."));
8574 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8575 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
8578 case IPP_JOB_PROCESSING
:
8579 case IPP_JOB_STOPPED
:
8580 if (job
->state
->values
[0].integer
!= attr
->values
[0].integer
)
8582 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8583 _("Job state cannot be changed."));
8588 case IPP_JOB_CANCELLED
:
8589 case IPP_JOB_ABORTED
:
8590 case IPP_JOB_COMPLETED
:
8591 if (job
->state
->values
[0].integer
> IPP_JOB_PROCESSING
)
8593 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8594 _("Job state cannot be changed."));
8597 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8599 cupsdCancelJob(job
, 0);
8603 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
8611 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
8613 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
8614 IPP_TAG_ZERO
)) != NULL
)
8617 * Some other value; first free the old value...
8620 if (job
->attrs
->prev
)
8621 job
->attrs
->prev
->next
= attr2
->next
;
8623 job
->attrs
->attrs
= attr2
->next
;
8625 if (job
->attrs
->last
== attr2
)
8626 job
->attrs
->last
= job
->attrs
->prev
;
8628 _ipp_free_attr(attr2
);
8631 * Then copy the attribute...
8634 copy_attribute(job
->attrs
, attr
, 0);
8637 * See if the job-name or job-hold-until is being changed.
8640 if (!strcmp(attr
->name
, "job-hold-until"))
8642 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
8644 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
8645 cupsdReleaseJob(job
);
8650 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
8653 * Delete the attribute...
8656 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
8657 IPP_TAG_ZERO
)) != NULL
)
8659 if (job
->attrs
->prev
)
8660 job
->attrs
->prev
->next
= attr2
->next
;
8662 job
->attrs
->attrs
= attr2
->next
;
8664 if (attr2
== job
->attrs
->last
)
8665 job
->attrs
->last
= job
->attrs
->prev
;
8667 _ipp_free_attr(attr2
);
8673 * Add new option by copying it...
8676 copy_attribute(job
->attrs
, attr
, 0);
8687 * Start jobs if possible...
8695 * 'start_printer()' - Start a printer.
8699 start_printer(cupsd_client_t
*con
, /* I - Client connection */
8700 ipp_attribute_t
*uri
) /* I - Printer URI */
8702 http_status_t status
; /* Policy status */
8703 cups_ptype_t dtype
; /* Destination type (printer or class) */
8704 char method
[HTTP_MAX_URI
],
8705 /* Method portion of URI */
8706 username
[HTTP_MAX_URI
],
8707 /* Username portion of URI */
8709 /* Host portion of URI */
8710 resource
[HTTP_MAX_URI
];
8711 /* Resource portion of URI */
8712 int port
; /* Port portion of URI */
8713 const char *name
; /* Printer name */
8714 cupsd_printer_t
*printer
; /* Printer data */
8717 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
8718 con
->http
.fd
, uri
->values
[0].string
.text
);
8721 * Is the destination valid?
8724 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8725 sizeof(method
), username
, sizeof(username
), host
,
8726 sizeof(host
), &port
, resource
, sizeof(resource
));
8728 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
8734 send_ipp_status(con
, IPP_NOT_FOUND
,
8735 _("The printer or class was not found."));
8743 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8745 send_http_error(con
, status
);
8750 * Start the printer...
8753 printer
->state_message
[0] = '\0';
8755 cupsdStartPrinter(printer
, 1);
8757 if (dtype
& CUPS_PRINTER_CLASS
)
8758 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".", name
,
8761 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".", name
,
8767 * Everything was ok, so return OK status...
8770 con
->response
->request
.status
.status_code
= IPP_OK
;
8775 * 'stop_printer()' - Stop a printer.
8779 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
8780 ipp_attribute_t
*uri
) /* I - Printer URI */
8782 http_status_t status
; /* Policy status */
8783 cups_ptype_t dtype
; /* Destination type (printer or class) */
8784 char method
[HTTP_MAX_URI
],
8785 /* Method portion of URI */
8786 username
[HTTP_MAX_URI
],
8787 /* Username portion of URI */
8789 /* Host portion of URI */
8790 resource
[HTTP_MAX_URI
];
8791 /* Resource portion of URI */
8792 int port
; /* Port portion of URI */
8793 const char *name
; /* Printer name */
8794 cupsd_printer_t
*printer
; /* Printer data */
8795 ipp_attribute_t
*attr
; /* printer-state-message attribute */
8798 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
8799 con
->http
.fd
, uri
->values
[0].string
.text
);
8802 * Is the destination valid?
8805 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8806 sizeof(method
), username
, sizeof(username
), host
,
8807 sizeof(host
), &port
, resource
, sizeof(resource
));
8809 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
8815 send_ipp_status(con
, IPP_NOT_FOUND
,
8816 _("The printer or class was not found."));
8824 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8826 send_http_error(con
, status
);
8831 * Stop the printer...
8834 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8835 IPP_TAG_TEXT
)) == NULL
)
8836 strcpy(printer
->state_message
, "Paused");
8839 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8840 sizeof(printer
->state_message
));
8843 cupsdStopPrinter(printer
, 1);
8845 if (dtype
& CUPS_PRINTER_CLASS
)
8846 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".", name
,
8849 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".", name
,
8853 * Everything was ok, so return OK status...
8856 con
->response
->request
.status
.status_code
= IPP_OK
;
8861 * 'user_allowed()' - See if a user is allowed to print to a queue.
8864 static int /* O - 0 if not allowed, 1 if allowed */
8865 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
8866 const char *username
) /* I - Username */
8868 int i
; /* Looping var */
8869 struct passwd
*pw
; /* User password data */
8872 if (p
->num_users
== 0)
8875 if (!strcmp(username
, "root"))
8878 pw
= getpwnam(username
);
8881 for (i
= 0; i
< p
->num_users
; i
++)
8883 if (p
->users
[i
][0] == '@')
8886 * Check group membership...
8889 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
8892 else if (!strcasecmp(username
, p
->users
[i
]))
8896 return ((i
< p
->num_users
) != p
->deny_users
);
8901 * 'validate_job()' - Validate printer options and destination.
8905 validate_job(cupsd_client_t
*con
, /* I - Client connection */
8906 ipp_attribute_t
*uri
) /* I - Printer URI */
8908 http_status_t status
; /* Policy status */
8909 ipp_attribute_t
*attr
; /* Current attribute */
8910 ipp_attribute_t
*format
; /* Document-format attribute */
8911 cups_ptype_t dtype
; /* Destination type (printer or class) */
8912 char method
[HTTP_MAX_URI
],
8913 /* Method portion of URI */
8914 username
[HTTP_MAX_URI
],
8915 /* Username portion of URI */
8917 /* Host portion of URI */
8918 resource
[HTTP_MAX_URI
];
8919 /* Resource portion of URI */
8920 int port
; /* Port portion of URI */
8921 char super
[MIME_MAX_SUPER
],
8922 /* Supertype of file */
8923 type
[MIME_MAX_TYPE
];
8924 /* Subtype of file */
8925 cupsd_printer_t
*printer
; /* Printer */
8928 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
8929 con
->http
.fd
, uri
->values
[0].string
.text
);
8932 * OK, see if the client is sending the document compressed - CUPS
8933 * doesn't support compression yet...
8936 if ((attr
= ippFindAttribute(con
->request
, "compression",
8937 IPP_TAG_KEYWORD
)) != NULL
&&
8938 !strcmp(attr
->values
[0].string
.text
, "none"))
8940 send_ipp_status(con
, IPP_ATTRIBUTES
,
8941 _("Unsupported compression attribute %s!"),
8942 attr
->values
[0].string
.text
);
8943 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
8944 "compression", NULL
, attr
->values
[0].string
.text
);
8949 * Is it a format we support?
8952 if ((format
= ippFindAttribute(con
->request
, "document-format",
8953 IPP_TAG_MIMETYPE
)) != NULL
)
8955 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
8957 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
8958 format
->values
[0].string
.text
);
8962 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
8963 !mimeType(MimeDatabase
, super
, type
))
8965 cupsdLogMessage(CUPSD_LOG_INFO
,
8966 "Hint: Do you have the raw file printing rules enabled?");
8967 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
8968 _("Unsupported format \"%s\"!"),
8969 format
->values
[0].string
.text
);
8970 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
8971 "document-format", NULL
, format
->values
[0].string
.text
);
8977 * Is the destination valid?
8980 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8981 sizeof(method
), username
, sizeof(username
), host
,
8982 sizeof(host
), &port
, resource
, sizeof(resource
));
8984 if (cupsdValidateDest(host
, resource
, &dtype
, &printer
) == NULL
)
8990 send_ipp_status(con
, IPP_NOT_FOUND
,
8991 _("The printer or class was not found."));
8999 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9001 send_http_error(con
, status
);
9006 * Everything was ok, so return OK status...
9009 con
->response
->request
.status
.status_code
= IPP_OK
;
9014 * 'validate_name()' - Make sure the printer name only contains valid chars.
9017 static int /* O - 0 if name is no good, 1 if name is good */
9018 validate_name(const char *name
) /* I - Name to check */
9020 const char *ptr
; /* Pointer into name */
9024 * Scan the whole name...
9027 for (ptr
= name
; *ptr
; ptr
++)
9028 if ((*ptr
>= 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
9032 * All the characters are good; validate the length, too...
9035 return ((ptr
- name
) < 128);
9040 * 'validate_user()' - Validate the user for the request.
9043 static int /* O - 1 if permitted, 0 otherwise */
9044 validate_user(cupsd_job_t
*job
, /* I - Job */
9045 cupsd_client_t
*con
, /* I - Client connection */
9046 const char *owner
, /* I - Owner of job/resource */
9047 char *username
, /* O - Authenticated username */
9048 int userlen
) /* I - Length of username */
9050 cupsd_printer_t
*printer
; /* Printer for job */
9053 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9054 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
9056 job
? job
->id
: 0, con
->http
.fd
, owner
? owner
: "(null)",
9063 if (!con
|| !owner
|| !username
|| userlen
<= 0)
9067 * Get the best authenticated username that is available.
9070 strlcpy(username
, get_username(con
), userlen
);
9073 * Check the username against the owner...
9076 if (job
->dtype
& CUPS_PRINTER_CLASS
)
9077 printer
= cupsdFindClass(job
->dest
);
9079 printer
= cupsdFindPrinter(job
->dest
);
9081 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
9082 con
, owner
) == HTTP_OK
);
9087 * End of "$Id: ipp.c 5051 2006-02-02 16:13:16Z mike $".