2 * "$Id: ipp.c 5970 2006-09-19 20:11:08Z 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() - Add a job to a print queue.
31 * add_job_state_reasons() - Add the "job-state-reasons" attribute based
32 * upon the job and printer state...
33 * add_job_subscriptions() - Add any subcriptions for a job.
34 * add_job_uuid() - Add job-uuid attribute to a job.
35 * add_printer() - Add a printer to the system.
36 * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
37 * based upon the printer state...
38 * add_queued_job_count() - Add the "queued-job-count" attribute for
39 * apply_printer_defaults() - Apply printer default options to a job.
40 * authenticate_job() - Set job authentication info.
41 * cancel_all_jobs() - Cancel all print jobs.
42 * cancel_job() - Cancel a print job.
43 * cancel_subscription() - Cancel a subscription.
44 * check_quotas() - Check quotas for a printer and user.
45 * copy_attribute() - Copy a single attribute.
46 * copy_attrs() - Copy attributes from one request to another.
47 * copy_banner() - Copy a banner file to the requests directory
48 * for the specified job.
49 * copy_file() - Copy a PPD file or interface script...
50 * copy_model() - Copy a PPD model file, substituting default
52 * copy_job_attrs() - Copy job attributes.
53 * copy_printer_attrs() - Copy printer attributes.
54 * copy_subscription_attrs() - Copy subscription attributes.
55 * create_job() - Print a file to a printer or class.
56 * create_requested_array() - Create an array for the requested-attributes.
57 * create_subscription() - Create a notification subscription.
58 * delete_printer() - Remove a printer or class from the system.
59 * get_default() - Get the default destination.
60 * get_devices() - Get the list of available devices on the
62 * get_job_attrs() - Get job attributes.
63 * get_jobs() - Get a list of jobs for the specified printer.
64 * get_notifications() - Get events for a subscription.
65 * get_ppds() - Get the list of PPD files on the local
67 * get_printer_attrs() - Get printer attributes.
68 * get_printers() - Get a list of printers.
69 * get_subscription_attrs() - Get subscription attributes.
70 * get_subscriptions() - Get subscriptions.
71 * get_username() - Get the username associated with a request.
72 * hold_job() - Hold a print job.
73 * move_job() - Move a job to a new destination.
74 * ppd_add_default() - Add a PPD default choice.
75 * ppd_parse_line() - Parse a PPD default line.
76 * print_job() - Print a file to a printer or class.
77 * read_ps_line() - Read a line from a PS file...
78 * read_ps_job_ticket() - Reads a job ticket embedded in a PS file.
79 * reject_jobs() - Reject print jobs to a printer.
80 * release_job() - Release a held print job.
81 * restart_job() - Restart an old print job.
82 * save_auth_info() - Save authentication information for a job.
83 * send_document() - Send a file to a printer or class.
84 * send_http_error() - Send a HTTP error back to the IPP client.
85 * send_ipp_status() - Send a status back to the IPP client.
86 * set_default() - Set the default destination...
87 * set_job_attrs() - Set job attributes.
88 * set_printer_defaults() - Set printer default options from a request.
89 * start_printer() - Start a printer.
90 * stop_printer() - Stop a printer.
91 * url_encode_attr() - URL-encode a string attribute.
92 * user_allowed() - See if a user is allowed to print to a queue.
93 * validate_job() - Validate printer options and destination.
94 * validate_name() - Make sure the printer name only contains
96 * validate_user() - Validate the user for the request.
100 * Include necessary headers...
107 #endif /* HAVE_LIBPAPER */
111 * PPD default choice structure...
116 char option
[PPD_MAX_NAME
]; /* Main keyword (option name) */
117 char choice
[PPD_MAX_NAME
]; /* Option keyword (choice name) */
125 static void accept_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
126 static void add_class(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
127 static int add_file(cupsd_client_t
*con
, cupsd_job_t
*job
,
128 mime_type_t
*filetype
, int compression
);
129 static cupsd_job_t
*add_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
,
130 cupsd_printer_t
**dprinter
,
131 mime_type_t
*filetype
);
132 static void add_job_state_reasons(cupsd_client_t
*con
, cupsd_job_t
*job
);
133 static void add_job_subscriptions(cupsd_client_t
*con
, cupsd_job_t
*job
);
134 static void add_job_uuid(cupsd_client_t
*con
, cupsd_job_t
*job
);
135 static void add_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
136 static void add_printer_state_reasons(cupsd_client_t
*con
,
138 static void add_queued_job_count(cupsd_client_t
*con
, cupsd_printer_t
*p
);
139 static void apply_printer_defaults(cupsd_printer_t
*printer
,
141 static void authenticate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
142 static void cancel_all_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
143 static void cancel_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
144 static void cancel_subscription(cupsd_client_t
*con
, int id
);
145 static int check_quotas(cupsd_client_t
*con
, cupsd_printer_t
*p
);
146 static ipp_attribute_t
*copy_attribute(ipp_t
*to
, ipp_attribute_t
*attr
,
148 static void copy_attrs(ipp_t
*to
, ipp_t
*from
, cups_array_t
*ra
,
149 ipp_tag_t group
, int quickcopy
);
150 static int copy_banner(cupsd_client_t
*con
, cupsd_job_t
*job
,
152 static int copy_file(const char *from
, const char *to
);
153 static int copy_model(cupsd_client_t
*con
, const char *from
,
155 static void copy_job_attrs(cupsd_client_t
*con
,
158 static void copy_printer_attrs(cupsd_client_t
*con
,
159 cupsd_printer_t
*printer
,
161 static void copy_subscription_attrs(cupsd_client_t
*con
,
162 cupsd_subscription_t
*sub
,
164 static void create_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
165 static cups_array_t
*create_requested_array(ipp_t
*request
);
166 static void create_subscription(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
167 static void delete_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
168 static void get_default(cupsd_client_t
*con
);
169 static void get_devices(cupsd_client_t
*con
);
170 static void get_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
171 static void get_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
172 static void get_notifications(cupsd_client_t
*con
);
173 static void get_ppds(cupsd_client_t
*con
);
174 static void get_printers(cupsd_client_t
*con
, int type
);
175 static void get_printer_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
176 static void get_subscription_attrs(cupsd_client_t
*con
, int sub_id
);
177 static void get_subscriptions(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
178 static const char *get_username(cupsd_client_t
*con
);
179 static void hold_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
180 static void move_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
181 static int ppd_add_default(const char *option
, const char *choice
,
182 int num_defaults
, ppd_default_t
**defaults
);
183 static int ppd_parse_line(const char *line
, char *option
, int olen
,
184 char *choice
, int clen
);
185 static void print_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
186 static void read_ps_job_ticket(cupsd_client_t
*con
);
187 static void reject_jobs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
188 static void release_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
189 static void renew_subscription(cupsd_client_t
*con
, int sub_id
);
190 static void restart_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
191 static void save_auth_info(cupsd_client_t
*con
, cupsd_job_t
*job
);
192 static void send_document(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
193 static void send_http_error(cupsd_client_t
*con
, http_status_t status
);
194 static void send_ipp_status(cupsd_client_t
*con
, ipp_status_t status
,
195 const char *message
, ...)
197 __attribute__ ((__format__ (__printf__
, 3, 4)))
198 # endif /* __GNUC__ */
200 static void set_default(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
201 static void set_job_attrs(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
202 static void set_printer_defaults(cupsd_client_t
*con
,
203 cupsd_printer_t
*printer
);
204 static void start_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
205 static void stop_printer(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
206 static void url_encode_attr(ipp_attribute_t
*attr
, char *buffer
,
208 static int user_allowed(cupsd_printer_t
*p
, const char *username
);
209 static void validate_job(cupsd_client_t
*con
, ipp_attribute_t
*uri
);
210 static int validate_name(const char *name
);
211 static int validate_user(cupsd_job_t
*job
, cupsd_client_t
*con
,
212 const char *owner
, char *username
,
217 * 'cupsdProcessIPPRequest()' - Process an incoming IPP request...
220 int /* O - 1 on success, 0 on failure */
221 cupsdProcessIPPRequest(
222 cupsd_client_t
*con
) /* I - Client connection */
224 ipp_tag_t group
; /* Current group tag */
225 ipp_attribute_t
*attr
; /* Current attribute */
226 ipp_attribute_t
*charset
; /* Character set attribute */
227 ipp_attribute_t
*language
; /* Language attribute */
228 ipp_attribute_t
*uri
; /* Printer URI attribute */
229 ipp_attribute_t
*username
; /* requesting-user-name attr */
230 int sub_id
; /* Subscription ID */
233 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
234 "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
235 con
, con
->http
.fd
, con
->request
->request
.op
.operation_id
);
238 * First build an empty response message for this request...
241 con
->response
= ippNew();
243 con
->response
->request
.status
.version
[0] = con
->request
->request
.op
.version
[0];
244 con
->response
->request
.status
.version
[1] = con
->request
->request
.op
.version
[1];
245 con
->response
->request
.status
.request_id
= con
->request
->request
.op
.request_id
;
248 * Then validate the request header and required attributes...
251 if (con
->request
->request
.any
.version
[0] != 1)
254 * Return an error, since we only support IPP 1.x.
257 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
258 "%04X %s Bad request version number %d.%d",
259 IPP_VERSION_NOT_SUPPORTED
, con
->http
.hostname
,
260 con
->request
->request
.any
.version
[0],
261 con
->request
->request
.any
.version
[1]);
263 send_ipp_status(con
, IPP_VERSION_NOT_SUPPORTED
,
264 _("Bad request version number %d.%d!"),
265 con
->request
->request
.any
.version
[0],
266 con
->request
->request
.any
.version
[1]);
268 else if (!con
->request
->attrs
)
270 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
271 "%04X %s No attributes in request",
272 IPP_BAD_REQUEST
, con
->http
.hostname
);
274 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No attributes in request!"));
279 * Make sure that the attributes are provided in the correct order and
280 * don't repeat groups...
283 for (attr
= con
->request
->attrs
, group
= attr
->group_tag
;
286 if (attr
->group_tag
< group
&& attr
->group_tag
!= IPP_TAG_ZERO
)
289 * Out of order; return an error...
292 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
293 "%04X %s Attribute groups are out of order",
294 IPP_BAD_REQUEST
, con
->http
.hostname
);
296 send_ipp_status(con
, IPP_BAD_REQUEST
,
297 _("Attribute groups are out of order (%x < %x)!"),
298 attr
->group_tag
, group
);
302 group
= attr
->group_tag
;
307 * Then make sure that the first three attributes are:
310 * attributes-natural-language
311 * printer-uri/job-uri
314 attr
= con
->request
->attrs
;
315 if (attr
&& !strcmp(attr
->name
, "attributes-charset") &&
316 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_CHARSET
)
324 if (attr
&& !strcmp(attr
->name
, "attributes-natural-language") &&
325 (attr
->value_tag
& IPP_TAG_MASK
) == IPP_TAG_LANGUAGE
)
330 if ((attr
= ippFindAttribute(con
->request
, "printer-uri",
331 IPP_TAG_URI
)) != NULL
)
333 else if ((attr
= ippFindAttribute(con
->request
, "job-uri",
334 IPP_TAG_URI
)) != NULL
)
340 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
341 "attributes-charset", NULL
, charset
->values
[0].string
.text
);
343 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
344 "attributes-charset", NULL
, DefaultCharset
);
347 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
348 "attributes-natural-language", NULL
,
349 language
->values
[0].string
.text
);
351 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
352 "attributes-natural-language", NULL
, DefaultLanguage
);
354 if (!charset
|| !language
||
356 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEFAULT
&&
357 con
->request
->request
.op
.operation_id
!= CUPS_GET_PRINTERS
&&
358 con
->request
->request
.op
.operation_id
!= CUPS_GET_CLASSES
&&
359 con
->request
->request
.op
.operation_id
!= CUPS_GET_DEVICES
&&
360 con
->request
->request
.op
.operation_id
!= CUPS_GET_PPDS
))
363 * Return an error, since attributes-charset,
364 * attributes-natural-language, and printer-uri/job-uri are required
365 * for all operations.
370 cupsdLogMessage(CUPSD_LOG_ERROR
,
371 "Missing attributes-charset attribute!");
373 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
374 "%04X %s Missing attributes-charset attribute",
375 IPP_BAD_REQUEST
, con
->http
.hostname
);
380 cupsdLogMessage(CUPSD_LOG_ERROR
,
381 "Missing attributes-natural-language attribute!");
383 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
384 "%04X %s Missing attributes-natural-language attribute",
385 IPP_BAD_REQUEST
, con
->http
.hostname
);
390 cupsdLogMessage(CUPSD_LOG_ERROR
,
391 "Missing printer-uri or job-uri attribute!");
393 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
394 "%04X %s Missing printer-uri or job-uri attribute",
395 IPP_BAD_REQUEST
, con
->http
.hostname
);
398 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Request attributes follow...");
400 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
401 cupsdLogMessage(CUPSD_LOG_DEBUG
,
402 "attr \"%s\": group_tag = %x, value_tag = %x",
403 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
406 cupsdLogMessage(CUPSD_LOG_DEBUG
, "End of attributes...");
408 send_ipp_status(con
, IPP_BAD_REQUEST
,
409 _("Missing required attributes!"));
414 * OK, all the checks pass so far; make sure requesting-user-name is
415 * not "root" from a remote host...
418 if ((username
= ippFindAttribute(con
->request
, "requesting-user-name",
419 IPP_TAG_NAME
)) != NULL
)
422 * Check for root user...
425 if (!strcmp(username
->values
[0].string
.text
, "root") &&
426 strcasecmp(con
->http
.hostname
, "localhost") &&
427 strcmp(con
->username
, "root"))
430 * Remote unauthenticated user masquerading as local root...
433 _cupsStrFree(username
->values
[0].string
.text
);
434 username
->values
[0].string
.text
= _cupsStrAlloc(RemoteRoot
);
438 if ((attr
= ippFindAttribute(con
->request
, "notify-subscription-id",
439 IPP_TAG_INTEGER
)) != NULL
)
440 sub_id
= attr
->values
[0].integer
;
445 * Then try processing the operation...
449 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
450 ippOpString(con
->request
->request
.op
.operation_id
),
451 uri
->values
[0].string
.text
);
453 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s",
454 ippOpString(con
->request
->request
.op
.operation_id
));
456 switch (con
->request
->request
.op
.operation_id
)
462 case IPP_VALIDATE_JOB
:
463 validate_job(con
, uri
);
466 case IPP_CREATE_JOB
:
467 create_job(con
, uri
);
470 case IPP_SEND_DOCUMENT
:
471 send_document(con
, uri
);
474 case IPP_CANCEL_JOB
:
475 cancel_job(con
, uri
);
478 case IPP_GET_JOB_ATTRIBUTES
:
479 get_job_attrs(con
, uri
);
486 case IPP_GET_PRINTER_ATTRIBUTES
:
487 get_printer_attrs(con
, uri
);
494 case IPP_RELEASE_JOB
:
495 release_job(con
, uri
);
498 case IPP_RESTART_JOB
:
499 restart_job(con
, uri
);
502 case IPP_PAUSE_PRINTER
:
503 stop_printer(con
, uri
);
506 case IPP_RESUME_PRINTER
:
507 start_printer(con
, uri
);
510 case IPP_PURGE_JOBS
:
511 cancel_all_jobs(con
, uri
);
514 case IPP_SET_JOB_ATTRIBUTES
:
515 set_job_attrs(con
, uri
);
518 case CUPS_GET_DEFAULT
:
522 case CUPS_GET_PRINTERS
:
523 get_printers(con
, 0);
526 case CUPS_GET_CLASSES
:
527 get_printers(con
, CUPS_PRINTER_CLASS
);
530 case CUPS_ADD_PRINTER
:
531 add_printer(con
, uri
);
534 case CUPS_DELETE_PRINTER
:
535 delete_printer(con
, uri
);
538 case CUPS_ADD_CLASS
:
542 case CUPS_DELETE_CLASS
:
543 delete_printer(con
, uri
);
546 case CUPS_ACCEPT_JOBS
:
547 case IPP_ENABLE_PRINTER
:
548 accept_jobs(con
, uri
);
551 case CUPS_REJECT_JOBS
:
552 case IPP_DISABLE_PRINTER
:
553 reject_jobs(con
, uri
);
556 case CUPS_SET_DEFAULT
:
557 set_default(con
, uri
);
560 case CUPS_GET_DEVICES
:
572 case CUPS_AUTHENTICATE_JOB
:
573 authenticate_job(con
, uri
);
576 case IPP_CREATE_PRINTER_SUBSCRIPTION
:
577 case IPP_CREATE_JOB_SUBSCRIPTION
:
578 create_subscription(con
, uri
);
581 case IPP_GET_SUBSCRIPTION_ATTRIBUTES
:
582 get_subscription_attrs(con
, sub_id
);
585 case IPP_GET_SUBSCRIPTIONS
:
586 get_subscriptions(con
, uri
);
589 case IPP_RENEW_SUBSCRIPTION
:
590 renew_subscription(con
, sub_id
);
593 case IPP_CANCEL_SUBSCRIPTION
:
594 cancel_subscription(con
, sub_id
);
597 case IPP_GET_NOTIFICATIONS
:
598 get_notifications(con
);
602 cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT
, NULL
, NULL
,
603 "%04X %s Operation %04X (%s) not supported",
604 IPP_OPERATION_NOT_SUPPORTED
, con
->http
.hostname
,
605 con
->request
->request
.op
.operation_id
,
606 ippOpString(con
->request
->request
.op
.operation_id
));
608 send_ipp_status(con
, IPP_OPERATION_NOT_SUPPORTED
,
609 _("%s not supported!"),
610 ippOpString(con
->request
->request
.op
.operation_id
));
620 * Sending data from the scheduler...
623 cupsdLogMessage(CUPSD_LOG_DEBUG
,
624 "cupsdProcessIPPRequest: %d status_code=%x (%s)",
625 con
->http
.fd
, con
->response
->request
.status
.status_code
,
626 ippErrorString(con
->response
->request
.status
.status_code
));
628 if (cupsdSendHeader(con
, HTTP_OK
, "application/ipp"))
630 #ifdef CUPSD_USE_CHUNKING
632 * Because older versions of CUPS (1.1.17 and older) and some IPP
633 * clients do not implement chunking properly, we cannot use
634 * chunking by default. This may become the default in future
635 * CUPS releases, or we might add a configuration directive for
639 if (con
->http
.version
== HTTP_1_1
)
641 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n\r\n") < 0)
644 if (cupsdFlushHeader(con
) < 0)
647 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
650 #endif /* CUPSD_USE_CHUNKING */
652 size_t length
; /* Length of response */
655 length
= ippLength(con
->response
);
657 if (httpPrintf(HTTP(con
), "Content-Length: " CUPS_LLFMT
"\r\n\r\n",
658 CUPS_LLCAST length
) < 0)
661 if (cupsdFlushHeader(con
) < 0)
664 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
665 con
->http
.data_remaining
= length
;
668 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
669 "cupsdProcessIPPRequest: Adding fd %d to OutputSet...",
672 FD_SET(con
->http
.fd
, OutputSet
);
675 * Tell the caller the response header was sent successfully...
683 * Tell the caller the response header could not be sent...
692 * Sending data from a subprocess like cups-deviced; tell the caller
693 * everything is A-OK so far...
702 * 'accept_jobs()' - Accept print jobs to a printer.
706 accept_jobs(cupsd_client_t
*con
, /* I - Client connection */
707 ipp_attribute_t
*uri
) /* I - Printer or class URI */
709 http_status_t status
; /* Policy status */
710 cups_ptype_t dtype
; /* Destination type (printer or class) */
711 char method
[HTTP_MAX_URI
], /* Method portion of URI */
712 username
[HTTP_MAX_URI
], /* Username portion of URI */
713 host
[HTTP_MAX_URI
], /* Host portion of URI */
714 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
715 int port
; /* Port portion of URI */
716 const char *name
; /* Printer name */
717 cupsd_printer_t
*printer
; /* Printer data */
720 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "accept_jobs(%p[%d], %s)", con
,
721 con
->http
.fd
, uri
->values
[0].string
.text
);
724 * Is the destination valid?
727 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
728 sizeof(method
), username
, sizeof(username
), host
,
729 sizeof(host
), &port
, resource
, sizeof(resource
));
731 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
737 send_ipp_status(con
, IPP_NOT_FOUND
,
738 _("The printer or class was not found."));
746 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
748 send_http_error(con
, status
);
753 * Accept jobs sent to the printer...
756 printer
->accepting
= 1;
757 printer
->state_message
[0] = '\0';
759 cupsdAddPrinterHistory(printer
);
761 if (dtype
& CUPS_PRINTER_CLASS
)
762 cupsdSaveAllClasses();
764 cupsdSaveAllPrinters();
766 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" now accepting jobs (\"%s\").", name
,
770 * Everything was ok, so return OK status...
773 con
->response
->request
.status
.status_code
= IPP_OK
;
778 * 'add_class()' - Add a class to the system.
782 add_class(cupsd_client_t
*con
, /* I - Client connection */
783 ipp_attribute_t
*uri
) /* I - URI of class */
785 http_status_t status
; /* Policy status */
786 int i
; /* Looping var */
787 char method
[HTTP_MAX_URI
], /* Method portion of URI */
788 username
[HTTP_MAX_URI
], /* Username portion of URI */
789 host
[HTTP_MAX_URI
], /* Host portion of URI */
790 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
791 int port
; /* Port portion of URI */
792 cupsd_printer_t
*pclass
, /* Class */
793 *member
; /* Member printer/class */
794 cups_ptype_t dtype
; /* Destination type */
795 ipp_attribute_t
*attr
; /* Printer attribute */
796 int modify
; /* Non-zero if we just modified */
797 char newname
[IPP_MAX_NAME
]; /* New class name */
798 int need_restart_job
; /* Need to restart job? */
801 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_class(%p[%d], %s)", con
,
802 con
->http
.fd
, uri
->values
[0].string
.text
);
805 * Do we have a valid URI?
808 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
809 sizeof(method
), username
, sizeof(username
), host
,
810 sizeof(host
), &port
, resource
, sizeof(resource
));
813 if (strncmp(resource
, "/classes/", 9) || strlen(resource
) == 9)
816 * No, return an error...
819 send_ipp_status(con
, IPP_BAD_REQUEST
,
820 _("The printer-uri must be of the form "
821 "\"ipp://HOSTNAME/classes/CLASSNAME\"."));
826 * Do we have a valid printer name?
829 if (!validate_name(resource
+ 9))
832 * No, return an error...
835 send_ipp_status(con
, IPP_BAD_REQUEST
,
836 _("The printer-uri \"%s\" contains invalid characters."),
837 uri
->values
[0].string
.text
);
845 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
847 send_http_error(con
, status
);
852 * See if the class already exists; if not, create a new class...
855 if ((pclass
= cupsdFindClass(resource
+ 9)) == NULL
)
858 * Class doesn't exist; see if we have a printer of the same name...
861 if ((pclass
= cupsdFindPrinter(resource
+ 9)) != NULL
&&
862 !(pclass
->type
& CUPS_PRINTER_REMOTE
))
865 * Yes, return an error...
868 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
869 _("A printer named \"%s\" already exists!"),
875 * No, add the pclass...
878 pclass
= cupsdAddClass(resource
+ 9);
881 else if (pclass
->type
& CUPS_PRINTER_IMPLICIT
)
884 * Rename the implicit class to "AnyClass" or remove it...
887 if (ImplicitAnyClasses
)
889 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 9);
890 cupsdRenamePrinter(pclass
, newname
);
893 cupsdDeletePrinter(pclass
, 1);
896 * Add the class as a new local class...
899 pclass
= cupsdAddClass(resource
+ 9);
902 else if (pclass
->type
& CUPS_PRINTER_REMOTE
)
905 * Rename the remote class to "Class"...
908 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 9, pclass
->hostname
);
909 cupsdRenamePrinter(pclass
, newname
);
912 * Add the class as a new local class...
915 pclass
= cupsdAddClass(resource
+ 9);
922 * Look for attributes and copy them over as needed...
925 need_restart_job
= 0;
927 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
928 IPP_TAG_TEXT
)) != NULL
)
929 cupsdSetString(&pclass
->location
, attr
->values
[0].string
.text
);
931 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
932 IPP_TAG_TEXT
)) != NULL
)
933 cupsdSetString(&pclass
->info
, attr
->values
[0].string
.text
);
935 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
936 IPP_TAG_BOOLEAN
)) != NULL
)
938 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-is-accepting-jobs to %d (was %d.)",
939 pclass
->name
, attr
->values
[0].boolean
, pclass
->accepting
);
941 pclass
->accepting
= attr
->values
[0].boolean
;
942 cupsdAddPrinterHistory(pclass
);
945 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
946 IPP_TAG_BOOLEAN
)) != NULL
)
948 if (pclass
->shared
&& !attr
->values
[0].boolean
)
949 cupsdSendBrowseDelete(pclass
);
951 cupsdLogMessage(CUPSD_LOG_INFO
,
952 "Setting %s printer-is-shared to %d (was %d.)",
953 pclass
->name
, attr
->values
[0].boolean
, pclass
->shared
);
955 pclass
->shared
= attr
->values
[0].boolean
;
958 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
959 IPP_TAG_ENUM
)) != NULL
)
961 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
962 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
964 send_ipp_status(con
, IPP_BAD_REQUEST
,
965 _("Attempt to set %s printer-state to bad value %d!"),
966 pclass
->name
, attr
->values
[0].integer
);
970 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)", pclass
->name
,
971 attr
->values
[0].integer
, pclass
->state
);
973 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
974 cupsdStopPrinter(pclass
, 0);
977 cupsdSetPrinterState(pclass
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
978 need_restart_job
= 1;
981 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
982 IPP_TAG_TEXT
)) != NULL
)
984 strlcpy(pclass
->state_message
, attr
->values
[0].string
.text
,
985 sizeof(pclass
->state_message
));
986 cupsdAddPrinterHistory(pclass
);
988 if ((attr
= ippFindAttribute(con
->request
, "member-uris",
989 IPP_TAG_URI
)) != NULL
)
992 * Clear the printer array as needed...
995 need_restart_job
= 1;
997 if (pclass
->num_printers
> 0)
999 free(pclass
->printers
);
1000 pclass
->num_printers
= 0;
1004 * Add each printer or class that is listed...
1007 for (i
= 0; i
< attr
->num_values
; i
++)
1010 * Search for the printer or class URI...
1013 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[i
].string
.text
, method
,
1014 sizeof(method
), username
, sizeof(username
), host
,
1015 sizeof(host
), &port
, resource
, sizeof(resource
));
1017 if (!cupsdValidateDest(host
, resource
, &dtype
, &member
))
1023 send_ipp_status(con
, IPP_NOT_FOUND
,
1024 _("The printer or class was not found."));
1029 * Add it to the class...
1032 cupsdAddPrinterToClass(pclass
, member
);
1036 set_printer_defaults(con
, pclass
);
1039 * Update the printer class attributes and return...
1042 cupsdSetPrinterAttrs(pclass
);
1043 cupsdSaveAllClasses();
1045 if (need_restart_job
&& pclass
->job
)
1050 * Stop the current job and then restart it below...
1053 job
= (cupsd_job_t
*)pclass
->job
;
1055 cupsdStopJob(job
, 1);
1057 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1058 job
->state_value
= IPP_JOB_PENDING
;
1061 if (need_restart_job
)
1064 cupsdWritePrintcap();
1068 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, pclass
, NULL
,
1069 "Class \"%s\" modified by \"%s\".", pclass
->name
,
1072 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" modified by \"%s\".",
1073 pclass
->name
, get_username(con
));
1077 cupsdAddPrinterHistory(pclass
);
1079 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, pclass
, NULL
,
1080 "New class \"%s\" added by \"%s\".", pclass
->name
,
1083 cupsdLogMessage(CUPSD_LOG_INFO
, "New class \"%s\" added by \"%s\".",
1084 pclass
->name
, get_username(con
));
1087 con
->response
->request
.status
.status_code
= IPP_OK
;
1092 * 'add_file()' - Add a file to a job.
1095 static int /* O - 0 on success, -1 on error */
1096 add_file(cupsd_client_t
*con
, /* I - Connection to client */
1097 cupsd_job_t
*job
, /* I - Job to add to */
1098 mime_type_t
*filetype
, /* I - Type of file */
1099 int compression
) /* I - Compression */
1101 mime_type_t
**filetypes
; /* New filetypes array... */
1102 int *compressions
; /* New compressions array... */
1105 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1106 "add_file(con=%p[%d], job=%d, filetype=%s/%s, compression=%d)",
1107 con
, con
->http
.fd
, job
->id
, filetype
->super
, filetype
->type
,
1111 * Add the file to the job...
1114 if (job
->num_files
== 0)
1116 compressions
= (int *)malloc(sizeof(int));
1117 filetypes
= (mime_type_t
**)malloc(sizeof(mime_type_t
*));
1121 compressions
= (int *)realloc(job
->compressions
,
1122 (job
->num_files
+ 1) * sizeof(int));
1123 filetypes
= (mime_type_t
**)realloc(job
->filetypes
,
1124 (job
->num_files
+ 1) *
1125 sizeof(mime_type_t
*));
1128 if (!compressions
|| !filetypes
)
1130 cupsdCancelJob(job
, 1, IPP_JOB_ABORTED
);
1132 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1133 _("Unable to allocate memory for file types!"));
1137 job
->compressions
= compressions
;
1138 job
->compressions
[job
->num_files
] = compression
;
1139 job
->filetypes
= filetypes
;
1140 job
->filetypes
[job
->num_files
] = filetype
;
1149 * 'add_job()' - Add a job to a print queue.
1152 static cupsd_job_t
* /* O - Job object */
1153 add_job(cupsd_client_t
*con
, /* I - Client connection */
1154 ipp_attribute_t
*uri
, /* I - printer-uri */
1155 cupsd_printer_t
**dprinter
, /* I - Destination printer */
1156 mime_type_t
*filetype
) /* I - First print file type, if any */
1158 http_status_t status
; /* Policy status */
1159 ipp_attribute_t
*attr
; /* Current attribute */
1160 const char *dest
; /* Destination */
1161 cups_ptype_t dtype
; /* Destination type (printer or class) */
1162 const char *val
; /* Default option value */
1163 int priority
; /* Job priority */
1164 char *title
; /* Job name/title */
1165 cupsd_job_t
*job
; /* Current job */
1166 char job_uri
[HTTP_MAX_URI
], /* Job URI */
1167 method
[HTTP_MAX_URI
], /* Method portion of URI */
1168 username
[HTTP_MAX_URI
], /* Username portion of URI */
1169 host
[HTTP_MAX_URI
], /* Host portion of URI */
1170 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
1171 int port
; /* Port portion of URI */
1172 cupsd_printer_t
*printer
; /* Printer data */
1173 int kbytes
; /* Size of print file */
1174 int i
; /* Looping var */
1175 int lowerpagerange
; /* Page range bound */
1178 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job(%p[%d], %s)", con
,
1179 con
->http
.fd
, uri
->values
[0].string
.text
);
1182 * Is the destination valid?
1185 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
1186 sizeof(method
), username
, sizeof(username
), host
,
1187 sizeof(host
), &port
, resource
, sizeof(resource
));
1189 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
1195 send_ipp_status(con
, IPP_NOT_FOUND
,
1196 _("The printer or class was not found."));
1201 *dprinter
= printer
;
1204 * Check remote printing to non-shared printer...
1207 if (!printer
->shared
&&
1208 strcasecmp(con
->http
.hostname
, "localhost") &&
1209 strcasecmp(con
->http
.hostname
, ServerName
))
1211 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
1212 _("The printer or class is not shared!"));
1220 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
1222 send_http_error(con
, status
);
1225 else if ((printer
->type
& CUPS_PRINTER_AUTHENTICATED
) && !con
->username
[0])
1227 send_http_error(con
, HTTP_UNAUTHORIZED
);
1232 * See if the printer is accepting jobs...
1235 if (!printer
->accepting
)
1237 send_ipp_status(con
, IPP_NOT_ACCEPTING
,
1238 _("Destination \"%s\" is not accepting jobs."),
1244 * Validate job template attributes; for now just document-format,
1245 * copies, and page-ranges...
1248 if (filetype
&& printer
->filetypes
&&
1249 !cupsArrayFind(printer
->filetypes
, filetype
))
1251 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
1252 /* MIME media type string */
1255 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
1258 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
1259 _("Unsupported format \'%s\'!"), mimetype
);
1261 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
1262 "document-format", NULL
, mimetype
);
1267 if ((attr
= ippFindAttribute(con
->request
, "copies",
1268 IPP_TAG_INTEGER
)) != NULL
)
1270 if (attr
->values
[0].integer
< 1 || attr
->values
[0].integer
> MaxCopies
)
1272 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Bad copies value %d."),
1273 attr
->values
[0].integer
);
1274 ippAddInteger(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_INTEGER
,
1275 "copies", attr
->values
[0].integer
);
1280 if ((attr
= ippFindAttribute(con
->request
, "page-ranges",
1281 IPP_TAG_RANGE
)) != NULL
)
1283 for (i
= 0, lowerpagerange
= 1; i
< attr
->num_values
; i
++)
1285 if (attr
->values
[i
].range
.lower
< lowerpagerange
||
1286 attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
1288 send_ipp_status(con
, IPP_BAD_REQUEST
,
1289 _("Bad page-ranges values %d-%d."),
1290 attr
->values
[i
].range
.lower
,
1291 attr
->values
[i
].range
.upper
);
1295 lowerpagerange
= attr
->values
[i
].range
.upper
+ 1;
1300 * Make sure we aren't over our limit...
1303 if (MaxJobs
&& cupsArrayCount(Jobs
) >= MaxJobs
)
1306 if (cupsArrayCount(Jobs
) >= MaxJobs
&& MaxJobs
)
1308 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
1309 _("Too many active jobs."));
1313 if (!check_quotas(con
, printer
))
1315 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Quota limit reached."));
1320 * Create the job and set things up...
1323 if ((attr
= ippFindAttribute(con
->request
, "job-priority",
1324 IPP_TAG_INTEGER
)) != NULL
)
1325 priority
= attr
->values
[0].integer
;
1328 if ((val
= cupsGetOption("job-priority", printer
->num_options
,
1329 printer
->options
)) != NULL
)
1330 priority
= atoi(val
);
1334 ippAddInteger(con
->request
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-priority",
1338 if ((attr
= ippFindAttribute(con
->request
, "job-name",
1339 IPP_TAG_NAME
)) != NULL
)
1340 title
= attr
->values
[0].string
.text
;
1342 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1343 title
= "Untitled");
1345 if ((job
= cupsdAddJob(priority
, printer
->name
)) == NULL
)
1347 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
1348 _("Unable to add job for destination \"%s\"!"), dest
);
1353 job
->attrs
= con
->request
;
1354 con
->request
= NULL
;
1356 add_job_uuid(con
, job
);
1357 apply_printer_defaults(printer
, job
);
1359 attr
= ippFindAttribute(job
->attrs
, "requesting-user-name", IPP_TAG_NAME
);
1361 if (con
->username
[0])
1363 cupsdSetString(&job
->username
, con
->username
);
1366 cupsdSetString(&attr
->values
[0].string
.text
, con
->username
);
1368 save_auth_info(con
, job
);
1372 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1373 "add_job: requesting-user-name=\"%s\"",
1374 attr
->values
[0].string
.text
);
1376 cupsdSetString(&job
->username
, attr
->values
[0].string
.text
);
1379 cupsdSetString(&job
->username
, "anonymous");
1382 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1383 "job-originating-user-name", NULL
, job
->username
);
1386 attr
->group_tag
= IPP_TAG_JOB
;
1387 _cupsStrFree(attr
->name
);
1388 attr
->name
= _cupsStrAlloc("job-originating-user-name");
1391 if ((attr
= ippFindAttribute(job
->attrs
, "job-originating-host-name",
1392 IPP_TAG_ZERO
)) != NULL
)
1395 * Request contains a job-originating-host-name attribute; validate it...
1398 if (attr
->value_tag
!= IPP_TAG_NAME
||
1399 attr
->num_values
!= 1 ||
1400 strcmp(con
->http
.hostname
, "localhost"))
1403 * Can't override the value if we aren't connected via localhost.
1404 * Also, we can only have 1 value and it must be a name value.
1407 switch (attr
->value_tag
)
1409 case IPP_TAG_STRING
:
1410 case IPP_TAG_TEXTLANG
:
1411 case IPP_TAG_NAMELANG
:
1414 case IPP_TAG_KEYWORD
:
1416 case IPP_TAG_URISCHEME
:
1417 case IPP_TAG_CHARSET
:
1418 case IPP_TAG_LANGUAGE
:
1419 case IPP_TAG_MIMETYPE
:
1421 * Free old strings...
1424 for (i
= 0; i
< attr
->num_values
; i
++)
1426 _cupsStrFree(attr
->values
[i
].string
.text
);
1427 attr
->values
[i
].string
.text
= NULL
;
1428 if (attr
->values
[i
].string
.charset
)
1430 _cupsStrFree(attr
->values
[i
].string
.charset
);
1431 attr
->values
[i
].string
.charset
= NULL
;
1440 * Use the default connection hostname instead...
1443 attr
->value_tag
= IPP_TAG_NAME
;
1444 attr
->num_values
= 1;
1445 attr
->values
[0].string
.text
= _cupsStrAlloc(con
->http
.hostname
);
1448 attr
->group_tag
= IPP_TAG_JOB
;
1453 * No job-originating-host-name attribute, so use the hostname from
1457 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
,
1458 "job-originating-host-name", NULL
, con
->http
.hostname
);
1461 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "time-at-creation",
1463 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1464 "time-at-processing", 0);
1465 attr
->value_tag
= IPP_TAG_NOVALUE
;
1466 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1467 "time-at-completed", 0);
1468 attr
->value_tag
= IPP_TAG_NOVALUE
;
1471 * Add remaining job attributes...
1474 ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1475 job
->state
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_ENUM
,
1476 "job-state", IPP_JOB_STOPPED
);
1477 job
->state_value
= (ipp_jstate_t
)job
->state
->values
[0].integer
;
1478 job
->sheets
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1479 "job-media-sheets-completed", 0);
1480 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-printer-uri", NULL
,
1482 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-name", NULL
,
1485 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
1486 IPP_TAG_INTEGER
)) != NULL
)
1487 attr
->values
[0].integer
= 0;
1489 attr
= ippAddInteger(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
1492 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
1493 IPP_TAG_KEYWORD
)) == NULL
)
1494 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
1497 if ((val
= cupsGetOption("job-hold-until", printer
->num_options
,
1498 printer
->options
)) == NULL
)
1501 attr
= ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1502 "job-hold-until", NULL
, val
);
1504 if (attr
&& strcmp(attr
->values
[0].string
.text
, "no-hold") &&
1505 !(printer
->type
& CUPS_PRINTER_REMOTE
))
1508 * Hold job until specified time...
1511 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
1513 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1514 job
->state_value
= IPP_JOB_HELD
;
1516 else if (job
->attrs
->request
.op
.operation_id
== IPP_CREATE_JOB
)
1518 job
->hold_until
= time(NULL
) + 60;
1519 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
1520 job
->state_value
= IPP_JOB_HELD
;
1524 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
1525 job
->state_value
= IPP_JOB_PENDING
;
1528 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) ||
1532 * Add job sheets options...
1535 if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1536 IPP_TAG_ZERO
)) == NULL
)
1538 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1539 "Adding default job-sheets values \"%s,%s\"...",
1540 printer
->job_sheets
[0], printer
->job_sheets
[1]);
1542 attr
= ippAddStrings(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_NAME
, "job-sheets",
1544 attr
->values
[0].string
.text
= _cupsStrAlloc(printer
->job_sheets
[0]);
1545 attr
->values
[1].string
.text
= _cupsStrAlloc(printer
->job_sheets
[1]);
1548 job
->job_sheets
= attr
;
1551 * Enforce classification level if set...
1556 cupsdLogMessage(CUPSD_LOG_INFO
,
1557 "Classification=\"%s\", ClassifyOverride=%d",
1558 Classification
? Classification
: "(null)",
1561 if (ClassifyOverride
)
1563 if (!strcmp(attr
->values
[0].string
.text
, "none") &&
1564 (attr
->num_values
== 1 ||
1565 !strcmp(attr
->values
[1].string
.text
, "none")))
1568 * Force the leading banner to have the classification on it...
1571 cupsdSetString(&attr
->values
[0].string
.text
, Classification
);
1573 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
1574 "job-sheets=\"%s,none\", "
1575 "job-originating-user-name=\"%s\"",
1576 job
->id
, Classification
, job
->username
);
1578 else if (attr
->num_values
== 2 &&
1579 strcmp(attr
->values
[0].string
.text
,
1580 attr
->values
[1].string
.text
) &&
1581 strcmp(attr
->values
[0].string
.text
, "none") &&
1582 strcmp(attr
->values
[1].string
.text
, "none"))
1585 * Can't put two different security markings on the same document!
1588 cupsdSetString(&attr
->values
[1].string
.text
, attr
->values
[0].string
.text
);
1590 cupsdLogMessage(CUPSD_LOG_NOTICE
, "[Job %d] CLASSIFICATION FORCED "
1591 "job-sheets=\"%s,%s\", "
1592 "job-originating-user-name=\"%s\"",
1593 job
->id
, attr
->values
[0].string
.text
,
1594 attr
->values
[1].string
.text
, job
->username
);
1596 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1597 strcmp(attr
->values
[0].string
.text
, "none") &&
1598 (attr
->num_values
== 1 ||
1599 (strcmp(attr
->values
[1].string
.text
, Classification
) &&
1600 strcmp(attr
->values
[1].string
.text
, "none"))))
1602 if (attr
->num_values
== 1)
1603 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1604 "[Job %d] CLASSIFICATION OVERRIDDEN "
1605 "job-sheets=\"%s\", "
1606 "job-originating-user-name=\"%s\"",
1607 job
->id
, attr
->values
[0].string
.text
, job
->username
);
1609 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1610 "[Job %d] CLASSIFICATION OVERRIDDEN "
1611 "job-sheets=\"%s,%s\",fffff "
1612 "job-originating-user-name=\"%s\"",
1613 job
->id
, attr
->values
[0].string
.text
,
1614 attr
->values
[1].string
.text
, job
->username
);
1617 else if (strcmp(attr
->values
[0].string
.text
, Classification
) &&
1618 (attr
->num_values
== 1 ||
1619 strcmp(attr
->values
[1].string
.text
, Classification
)))
1622 * Force the banner to have the classification on it...
1625 if (attr
->num_values
> 1 &&
1626 !strcmp(attr
->values
[0].string
.text
, attr
->values
[1].string
.text
))
1628 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1629 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1633 if (attr
->num_values
== 1 ||
1634 strcmp(attr
->values
[0].string
.text
, "none"))
1635 cupsdSetString(&(attr
->values
[0].string
.text
), Classification
);
1637 if (attr
->num_values
> 1 &&
1638 strcmp(attr
->values
[1].string
.text
, "none"))
1639 cupsdSetString(&(attr
->values
[1].string
.text
), Classification
);
1642 if (attr
->num_values
> 1)
1643 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1644 "[Job %d] CLASSIFICATION FORCED "
1645 "job-sheets=\"%s,%s\", "
1646 "job-originating-user-name=\"%s\"",
1647 job
->id
, attr
->values
[0].string
.text
,
1648 attr
->values
[1].string
.text
, job
->username
);
1650 cupsdLogMessage(CUPSD_LOG_NOTICE
,
1651 "[Job %d] CLASSIFICATION FORCED "
1652 "job-sheets=\"%s\", "
1653 "job-originating-user-name=\"%s\"",
1654 job
->id
, Classification
, job
->username
);
1659 * See if we need to add the starting sheet...
1662 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)))
1664 cupsdLogMessage(CUPSD_LOG_INFO
,
1665 "Adding start banner page \"%s\" to job %d.",
1666 attr
->values
[0].string
.text
, job
->id
);
1668 kbytes
= copy_banner(con
, job
, attr
->values
[0].string
.text
);
1670 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
1673 else if ((attr
= ippFindAttribute(job
->attrs
, "job-sheets",
1674 IPP_TAG_ZERO
)) != NULL
)
1678 * Fill in the response info...
1681 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
1682 LocalPort
, job
->id
);
1684 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
1687 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", job
->id
);
1689 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
1691 add_job_state_reasons(con
, job
);
1693 con
->response
->request
.status
.status_code
= IPP_OK
;
1696 * Add any job subscriptions...
1699 add_job_subscriptions(con
, job
);
1702 * Set all but the first two attributes to the job attributes group...
1705 for (attr
= job
->attrs
->attrs
->next
->next
; attr
; attr
= attr
->next
)
1706 attr
->group_tag
= IPP_TAG_JOB
;
1709 * Fire the "job created" event...
1712 cupsdAddEvent(CUPSD_EVENT_JOB_CREATED
, printer
, job
, "Job created.");
1715 * Return the new job...
1723 * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
1724 * upon the job and printer state...
1728 add_job_state_reasons(
1729 cupsd_client_t
*con
, /* I - Client connection */
1730 cupsd_job_t
*job
) /* I - Job info */
1732 cupsd_printer_t
*dest
; /* Destination printer */
1735 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_job_state_reasons(%p[%d], %d)",
1736 con
, con
->http
.fd
, job
? job
->id
: 0);
1738 switch (job
? job
->state_value
: IPP_JOB_CANCELED
)
1740 case IPP_JOB_PENDING
:
1741 dest
= cupsdFindDest(job
->dest
);
1743 if (dest
&& dest
->state
== IPP_PRINTER_STOPPED
)
1744 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1745 "job-state-reasons", NULL
, "printer-stopped");
1747 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1748 "job-state-reasons", NULL
, "none");
1752 if (ippFindAttribute(job
->attrs
, "job-hold-until",
1753 IPP_TAG_KEYWORD
) != NULL
||
1754 ippFindAttribute(job
->attrs
, "job-hold-until",
1755 IPP_TAG_NAME
) != NULL
)
1756 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1757 "job-state-reasons", NULL
, "job-hold-until-specified");
1759 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1760 "job-state-reasons", NULL
, "job-incoming");
1763 case IPP_JOB_PROCESSING
:
1764 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1765 "job-state-reasons", NULL
, "job-printing");
1768 case IPP_JOB_STOPPED
:
1769 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1770 "job-state-reasons", NULL
, "job-stopped");
1773 case IPP_JOB_CANCELED
:
1774 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1775 "job-state-reasons", NULL
, "job-canceled-by-user");
1778 case IPP_JOB_ABORTED
:
1779 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1780 "job-state-reasons", NULL
, "aborted-by-system");
1783 case IPP_JOB_COMPLETED
:
1784 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_KEYWORD
,
1785 "job-state-reasons", NULL
, "job-completed-successfully");
1792 * 'add_job_subscriptions()' - Add any subcriptions for a job.
1796 add_job_subscriptions(
1797 cupsd_client_t
*con
, /* I - Client connection */
1798 cupsd_job_t
*job
) /* I - Newly created job */
1800 int i
; /* Looping var */
1801 ipp_attribute_t
*prev
, /* Previous attribute */
1802 *next
, /* Next attribute */
1803 *attr
; /* Current attribute */
1804 cupsd_subscription_t
*sub
; /* Subscription object */
1805 const char *recipient
, /* notify-recipient-uri */
1806 *pullmethod
; /* notify-pull-method */
1807 ipp_attribute_t
*user_data
; /* notify-user-data */
1808 int interval
; /* notify-time-interval */
1809 unsigned mask
; /* notify-events */
1813 * Find the first subscription group attribute; return if we have
1817 for (attr
= job
->attrs
->attrs
, prev
= NULL
;
1819 prev
= attr
, attr
= attr
->next
)
1820 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
1827 * Process the subscription attributes in the request...
1836 mask
= CUPSD_EVENT_NONE
;
1838 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
1840 if (!strcmp(attr
->name
, "notify-recipient") &&
1841 attr
->value_tag
== IPP_TAG_URI
)
1842 recipient
= attr
->values
[0].string
.text
;
1843 else if (!strcmp(attr
->name
, "notify-pull-method") &&
1844 attr
->value_tag
== IPP_TAG_KEYWORD
)
1845 pullmethod
= attr
->values
[0].string
.text
;
1846 else if (!strcmp(attr
->name
, "notify-charset") &&
1847 attr
->value_tag
== IPP_TAG_CHARSET
&&
1848 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
1849 strcmp(attr
->values
[0].string
.text
, "utf-8"))
1851 send_ipp_status(con
, IPP_CHARSET
,
1852 _("Character set \"%s\" not supported!"),
1853 attr
->values
[0].string
.text
);
1856 else if (!strcmp(attr
->name
, "notify-natural-language") &&
1857 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
1858 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
1860 send_ipp_status(con
, IPP_CHARSET
,
1861 _("Language \"%s\" not supported!"),
1862 attr
->values
[0].string
.text
);
1865 else if (!strcmp(attr
->name
, "notify-user-data") &&
1866 attr
->value_tag
== IPP_TAG_STRING
)
1868 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
1870 send_ipp_status(con
, IPP_REQUEST_VALUE
,
1871 _("The notify-user-data value is too large "
1872 "(%d > 63 octets)!"),
1873 attr
->values
[0].unknown
.length
);
1879 else if (!strcmp(attr
->name
, "notify-events") &&
1880 attr
->value_tag
== IPP_TAG_KEYWORD
)
1882 for (i
= 0; i
< attr
->num_values
; i
++)
1883 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
1885 else if (!strcmp(attr
->name
, "notify-lease-duration"))
1887 send_ipp_status(con
, IPP_BAD_REQUEST
,
1888 _("The notify-lease-duration attribute cannot be "
1889 "used with job subscriptions."));
1892 else if (!strcmp(attr
->name
, "notify-time-interval") &&
1893 attr
->value_tag
== IPP_TAG_INTEGER
)
1894 interval
= attr
->values
[0].integer
;
1899 if (!recipient
&& !pullmethod
)
1902 if (mask
== CUPSD_EVENT_NONE
)
1903 mask
= CUPSD_EVENT_JOB_COMPLETED
;
1905 sub
= cupsdAddSubscription(mask
, cupsdFindDest(job
->dest
), job
, recipient
,
1908 sub
->interval
= interval
;
1910 cupsdSetString(&sub
->owner
, job
->username
);
1914 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
1915 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
1916 sub
->user_data_len
);
1919 ippAddSeparator(con
->response
);
1920 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
1921 "notify-subscription-id", sub
->id
);
1927 cupsdSaveAllSubscriptions();
1930 * Remove all of the subscription attributes from the job request...
1933 for (attr
= job
->attrs
->attrs
, prev
= NULL
; attr
; attr
= next
)
1937 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
||
1938 attr
->group_tag
== IPP_TAG_ZERO
)
1941 * Free and remove this attribute...
1949 job
->attrs
->attrs
= next
;
1955 job
->attrs
->last
= prev
;
1956 job
->attrs
->current
= prev
;
1961 * 'add_job_uuid()' - Add job-uuid attribute to a job.
1963 * See RFC 4122 for the definition of UUIDs and the format.
1967 add_job_uuid(cupsd_client_t
*con
, /* I - Client connection */
1968 cupsd_job_t
*job
) /* I - Job */
1970 char uuid
[1024]; /* job-uuid string */
1971 _cups_md5_state_t md5state
; /* MD5 state */
1972 unsigned char md5sum
[16]; /* MD5 digest/sum */
1976 * First see if the job already has a job-uuid attribute; if so, return...
1979 if (ippFindAttribute(job
->attrs
, "job-uuid", IPP_TAG_URI
))
1983 * No job-uuid attribute, so build a version 3 UUID with the local job
1984 * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
1985 * the ServerName, server name and port that the client connected to,
1986 * and local job ID...
1989 snprintf(uuid
, sizeof(uuid
), "%s:%s:%d:%d", ServerName
, con
->servername
,
1990 con
->serverport
, job
->id
);
1992 _cupsMD5Init(&md5state
);
1993 _cupsMD5Append(&md5state
, (unsigned char *)uuid
, strlen(uuid
));
1994 _cupsMD5Finish(&md5state
, md5sum
);
1997 * Format the UUID URI using the MD5 sum and job ID.
2000 snprintf(uuid
, sizeof(uuid
),
2001 "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
2002 "%02x%02x%02x%02x%02x%02x",
2003 md5sum
[0], md5sum
[1], md5sum
[2], md5sum
[3], md5sum
[4], md5sum
[5],
2004 (md5sum
[6] & 15) | 0x30, md5sum
[7], (md5sum
[8] & 0x3f) | 0x40,
2005 md5sum
[9], md5sum
[10], md5sum
[11], md5sum
[12], md5sum
[13],
2006 md5sum
[14], md5sum
[15]);
2008 ippAddString(job
->attrs
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uuid", NULL
, uuid
);
2013 * 'add_printer()' - Add a printer to the system.
2017 add_printer(cupsd_client_t
*con
, /* I - Client connection */
2018 ipp_attribute_t
*uri
) /* I - URI of printer */
2020 http_status_t status
; /* Policy status */
2021 int i
; /* Looping var */
2022 char method
[HTTP_MAX_URI
], /* Method portion of URI */
2023 username
[HTTP_MAX_URI
], /* Username portion of URI */
2024 host
[HTTP_MAX_URI
], /* Host portion of URI */
2025 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2026 int port
; /* Port portion of URI */
2027 cupsd_printer_t
*printer
; /* Printer/class */
2028 ipp_attribute_t
*attr
; /* Printer attribute */
2029 cups_file_t
*fp
; /* Script/PPD file */
2030 char line
[1024]; /* Line from file... */
2031 char srcfile
[1024], /* Source Script/PPD file */
2032 dstfile
[1024]; /* Destination Script/PPD file */
2033 int modify
; /* Non-zero if we are modifying */
2034 char newname
[IPP_MAX_NAME
]; /* New printer name */
2035 int need_restart_job
; /* Need to restart job? */
2038 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer(%p[%d], %s)", con
,
2039 con
->http
.fd
, uri
->values
[0].string
.text
);
2042 * Do we have a valid URI?
2045 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2046 sizeof(method
), username
, sizeof(username
), host
,
2047 sizeof(host
), &port
, resource
, sizeof(resource
));
2049 if (strncmp(resource
, "/printers/", 10) || strlen(resource
) == 10)
2052 * No, return an error...
2055 send_ipp_status(con
, IPP_BAD_REQUEST
,
2056 _("The printer-uri must be of the form "
2057 "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
2062 * Do we have a valid printer name?
2065 if (!validate_name(resource
+ 10))
2068 * No, return an error...
2071 send_ipp_status(con
, IPP_BAD_REQUEST
,
2072 _("The printer-uri \"%s\" contains invalid characters."),
2073 uri
->values
[0].string
.text
);
2081 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2083 send_http_error(con
, status
);
2088 * See if the printer already exists; if not, create a new printer...
2091 if ((printer
= cupsdFindPrinter(resource
+ 10)) == NULL
)
2094 * Printer doesn't exist; see if we have a class of the same name...
2097 if ((printer
= cupsdFindClass(resource
+ 10)) != NULL
&&
2098 !(printer
->type
& CUPS_PRINTER_REMOTE
))
2101 * Yes, return an error...
2104 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2105 _("A class named \"%s\" already exists!"),
2111 * No, add the printer...
2114 printer
= cupsdAddPrinter(resource
+ 10);
2117 else if (printer
->type
& CUPS_PRINTER_IMPLICIT
)
2120 * Rename the implicit printer to "AnyPrinter" or delete it...
2123 if (ImplicitAnyClasses
)
2125 snprintf(newname
, sizeof(newname
), "Any%s", resource
+ 10);
2126 cupsdRenamePrinter(printer
, newname
);
2129 cupsdDeletePrinter(printer
, 1);
2132 * Add the printer as a new local printer...
2135 printer
= cupsdAddPrinter(resource
+ 10);
2138 else if (printer
->type
& CUPS_PRINTER_REMOTE
)
2141 * Rename the remote printer to "Printer@server"...
2144 snprintf(newname
, sizeof(newname
), "%s@%s", resource
+ 10,
2146 cupsdRenamePrinter(printer
, newname
);
2149 * Add the printer as a new local printer...
2152 printer
= cupsdAddPrinter(resource
+ 10);
2159 * Look for attributes and copy them over as needed...
2162 need_restart_job
= 0;
2164 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
2165 IPP_TAG_TEXT
)) != NULL
)
2166 cupsdSetString(&printer
->location
, attr
->values
[0].string
.text
);
2168 if ((attr
= ippFindAttribute(con
->request
, "printer-info",
2169 IPP_TAG_TEXT
)) != NULL
)
2170 cupsdSetString(&printer
->info
, attr
->values
[0].string
.text
);
2172 if ((attr
= ippFindAttribute(con
->request
, "device-uri",
2173 IPP_TAG_URI
)) != NULL
)
2176 * Do we have a valid device URI?
2179 need_restart_job
= 1;
2181 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[0].string
.text
, method
,
2182 sizeof(method
), username
, sizeof(username
), host
,
2183 sizeof(host
), &port
, resource
, sizeof(resource
));
2185 if (!strcmp(method
, "file"))
2188 * See if the administrator has enabled file devices...
2191 if (!FileDevice
&& strcmp(resource
, "/dev/null"))
2194 * File devices are disabled and the URL is not file:/dev/null...
2197 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2198 _("File device URIs have been disabled! "
2199 "To enable, see the FileDevice directive in "
2200 "\"%s/cupsd.conf\"."),
2208 * See if the backend exists and is executable...
2211 snprintf(srcfile
, sizeof(srcfile
), "%s/backend/%s", ServerBin
, method
);
2212 if (access(srcfile
, X_OK
))
2215 * Could not find device in list!
2218 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad device-uri \"%s\"!"),
2219 attr
->values
[0].string
.text
);
2224 cupsdLogMessage(CUPSD_LOG_INFO
,
2225 "Setting %s device-uri to \"%s\" (was \"%s\".)",
2227 cupsdSanitizeURI(attr
->values
[0].string
.text
, line
,
2229 cupsdSanitizeURI(printer
->device_uri
, resource
,
2232 cupsdSetString(&printer
->device_uri
, attr
->values
[0].string
.text
);
2235 if ((attr
= ippFindAttribute(con
->request
, "port-monitor",
2236 IPP_TAG_KEYWORD
)) != NULL
)
2238 ipp_attribute_t
*supported
; /* port-monitor-supported attribute */
2241 need_restart_job
= 1;
2243 supported
= ippFindAttribute(printer
->attrs
, "port-monitor-supported",
2245 for (i
= 0; i
< supported
->num_values
; i
++)
2246 if (!strcmp(supported
->values
[i
].string
.text
,
2247 attr
->values
[0].string
.text
))
2250 if (i
>= supported
->num_values
)
2252 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Bad port-monitor \"%s\"!"),
2253 attr
->values
[0].string
.text
);
2257 cupsdLogMessage(CUPSD_LOG_INFO
,
2258 "Setting %s port-monitor to \"%s\" (was \"%s\".)",
2259 printer
->name
, attr
->values
[0].string
.text
,
2260 printer
->port_monitor
);
2262 if (strcmp(attr
->values
[0].string
.text
, "none"))
2263 cupsdSetString(&printer
->port_monitor
, attr
->values
[0].string
.text
);
2265 cupsdClearString(&printer
->port_monitor
);
2268 if ((attr
= ippFindAttribute(con
->request
, "printer-is-accepting-jobs",
2269 IPP_TAG_BOOLEAN
)) != NULL
)
2271 cupsdLogMessage(CUPSD_LOG_INFO
,
2272 "Setting %s printer-is-accepting-jobs to %d (was %d.)",
2273 printer
->name
, attr
->values
[0].boolean
, printer
->accepting
);
2275 printer
->accepting
= attr
->values
[0].boolean
;
2276 cupsdAddPrinterHistory(printer
);
2279 if ((attr
= ippFindAttribute(con
->request
, "printer-is-shared",
2280 IPP_TAG_BOOLEAN
)) != NULL
)
2282 if (printer
->shared
&& !attr
->values
[0].boolean
)
2283 cupsdSendBrowseDelete(printer
);
2285 cupsdLogMessage(CUPSD_LOG_INFO
,
2286 "Setting %s printer-is-shared to %d (was %d.)",
2287 printer
->name
, attr
->values
[0].boolean
, printer
->shared
);
2289 printer
->shared
= attr
->values
[0].boolean
;
2292 if ((attr
= ippFindAttribute(con
->request
, "printer-state",
2293 IPP_TAG_ENUM
)) != NULL
)
2295 if (attr
->values
[0].integer
!= IPP_PRINTER_IDLE
&&
2296 attr
->values
[0].integer
!= IPP_PRINTER_STOPPED
)
2298 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad printer-state value %d!"),
2299 attr
->values
[0].integer
);
2303 cupsdLogMessage(CUPSD_LOG_INFO
, "Setting %s printer-state to %d (was %d.)", printer
->name
,
2304 attr
->values
[0].integer
, printer
->state
);
2306 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
2307 cupsdStopPrinter(printer
, 0);
2310 need_restart_job
= 1;
2311 cupsdSetPrinterState(printer
, (ipp_pstate_t
)(attr
->values
[0].integer
), 0);
2314 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
2315 IPP_TAG_TEXT
)) != NULL
)
2317 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
2318 sizeof(printer
->state_message
));
2319 cupsdAddPrinterHistory(printer
);
2322 set_printer_defaults(con
, printer
);
2325 * See if we have all required attributes...
2328 if (!printer
->device_uri
)
2329 cupsdSetString(&printer
->device_uri
, "file:///dev/null");
2332 * See if we have an interface script or PPD file attached to the request...
2337 need_restart_job
= 1;
2339 strlcpy(srcfile
, con
->filename
, sizeof(srcfile
));
2341 if ((fp
= cupsFileOpen(srcfile
, "rb")))
2344 * Yes; get the first line from it...
2348 cupsFileGets(fp
, line
, sizeof(line
));
2352 * Then see what kind of file it is...
2355 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2358 if (!strncmp(line
, "*PPD-Adobe", 10))
2361 * The new file is a PPD file, so remove any old interface script
2362 * that might be lying around...
2370 * This must be an interface script, so move the file over to the
2371 * interfaces directory and make it executable...
2374 if (copy_file(srcfile
, dstfile
))
2376 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2377 _("Unable to copy interface script - %s!"),
2383 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2384 "Copied interface script successfully!");
2385 chmod(dstfile
, 0755);
2389 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2392 if (!strncmp(line
, "*PPD-Adobe", 10))
2395 * The new file is a PPD file, so move the file over to the
2396 * ppd directory and make it readable by all...
2399 if (copy_file(srcfile
, dstfile
))
2401 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
2402 _("Unable to copy PPD file - %s!"),
2408 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2409 "Copied PPD file successfully!");
2410 chmod(dstfile
, 0644);
2416 * This must be an interface script, so remove any old PPD file that
2417 * may be lying around...
2424 else if ((attr
= ippFindAttribute(con
->request
, "ppd-name",
2425 IPP_TAG_NAME
)) != NULL
)
2427 need_restart_job
= 1;
2429 if (!strcmp(attr
->values
[0].string
.text
, "raw"))
2432 * Raw driver, remove any existing PPD or interface script files.
2435 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2439 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2449 snprintf(dstfile
, sizeof(dstfile
), "%s/interfaces/%s", ServerRoot
,
2453 snprintf(dstfile
, sizeof(dstfile
), "%s/ppd/%s.ppd", ServerRoot
,
2456 if (copy_model(con
, attr
->values
[0].string
.text
, dstfile
))
2458 send_ipp_status(con
, IPP_INTERNAL_ERROR
, _("Unable to copy PPD file!"));
2463 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2464 "Copied PPD file successfully!");
2465 chmod(dstfile
, 0644);
2471 * Update the printer attributes and return...
2474 cupsdSetPrinterAttrs(printer
);
2475 cupsdSaveAllPrinters();
2477 if (need_restart_job
&& printer
->job
)
2482 * Stop the current job and then restart it below...
2485 job
= (cupsd_job_t
*)printer
->job
;
2487 cupsdStopJob(job
, 1);
2489 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
2490 job
->state_value
= IPP_JOB_PENDING
;
2493 if (need_restart_job
)
2496 cupsdWritePrintcap();
2500 cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED
, printer
, NULL
,
2501 "Printer \"%s\" modified by \"%s\".", printer
->name
,
2504 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" modified by \"%s\".",
2505 printer
->name
, get_username(con
));
2509 cupsdAddPrinterHistory(printer
);
2511 cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED
, printer
, NULL
,
2512 "New printer \"%s\" added by \"%s\".", printer
->name
,
2515 cupsdLogMessage(CUPSD_LOG_INFO
, "New printer \"%s\" added by \"%s\".",
2516 printer
->name
, get_username(con
));
2519 con
->response
->request
.status
.status_code
= IPP_OK
;
2524 * 'add_printer_state_reasons()' - Add the "printer-state-reasons" attribute
2525 * based upon the printer state...
2529 add_printer_state_reasons(
2530 cupsd_client_t
*con
, /* I - Client connection */
2531 cupsd_printer_t
*p
) /* I - Printer info */
2533 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2534 "add_printer_state_reasons(%p[%d], %p[%s])",
2535 con
, con
->http
.fd
, p
, p
->name
);
2537 if (p
->num_reasons
== 0)
2538 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2539 "printer-state-reasons", NULL
,
2540 p
->state
== IPP_PRINTER_STOPPED
? "paused" : "none");
2542 ippAddStrings(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2543 "printer-state-reasons", p
->num_reasons
, NULL
,
2544 (const char * const *)p
->reasons
);
2549 * 'add_queued_job_count()' - Add the "queued-job-count" attribute for
2550 * the specified printer or class.
2554 add_queued_job_count(
2555 cupsd_client_t
*con
, /* I - Client connection */
2556 cupsd_printer_t
*p
) /* I - Printer or class */
2558 int count
; /* Number of jobs on destination */
2561 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_queued_job_count(%p[%d], %p[%s])",
2562 con
, con
->http
.fd
, p
, p
->name
);
2564 count
= cupsdGetPrinterJobCount(p
->name
);
2566 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2567 "queued-job-count", count
);
2572 * 'apply_printer_defaults()' - Apply printer default options to a job.
2576 apply_printer_defaults(
2577 cupsd_printer_t
*printer
, /* I - Printer */
2578 cupsd_job_t
*job
) /* I - Job */
2580 int i
, /* Looping var */
2581 num_options
; /* Number of default options */
2582 cups_option_t
*options
, /* Default options */
2583 *option
; /* Current option */
2587 * Collect all of the default options and add the missing ones to the
2591 for (i
= printer
->num_options
, num_options
= 0, option
= printer
->options
;
2594 if (!ippFindAttribute(job
->attrs
, option
->name
, IPP_TAG_ZERO
))
2596 num_options
= cupsAddOption(option
->name
, option
->value
, num_options
,
2601 * Encode these options as attributes in the job object...
2604 cupsEncodeOptions2(job
->attrs
, num_options
, options
, IPP_TAG_JOB
);
2605 cupsFreeOptions(num_options
, options
);
2610 * 'authenticate_job()' - Set job authentication info.
2614 authenticate_job(cupsd_client_t
*con
, /* I - Client connection */
2615 ipp_attribute_t
*uri
) /* I - Job URI */
2617 ipp_attribute_t
*attr
; /* Job-id attribute */
2618 int jobid
; /* Job ID */
2619 cupsd_job_t
*job
; /* Current job */
2620 char method
[HTTP_MAX_URI
],
2621 /* Method portion of URI */
2622 username
[HTTP_MAX_URI
],
2623 /* Username portion of URI */
2625 /* Host portion of URI */
2626 resource
[HTTP_MAX_URI
];
2627 /* Resource portion of URI */
2628 int port
; /* Port portion of URI */
2631 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "authenticate_job(%p[%d], %s)",
2632 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
2635 * Start with "everything is OK" status...
2638 con
->response
->request
.status
.status_code
= IPP_OK
;
2641 * See if we have a job URI or a printer URI...
2644 if (!strcmp(uri
->name
, "printer-uri"))
2647 * Got a printer URI; see if we also have a job-id attribute...
2650 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2651 IPP_TAG_INTEGER
)) == NULL
)
2653 send_ipp_status(con
, IPP_BAD_REQUEST
,
2654 _("Got a printer-uri attribute but no job-id!"));
2658 jobid
= attr
->values
[0].integer
;
2663 * Got a job URI; parse it to get the job ID...
2666 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2667 sizeof(method
), username
, sizeof(username
), host
,
2668 sizeof(host
), &port
, resource
, sizeof(resource
));
2670 if (strncmp(resource
, "/jobs/", 6))
2676 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad job-uri attribute \"%s\"!"),
2677 uri
->values
[0].string
.text
);
2681 jobid
= atoi(resource
+ 6);
2685 * See if the job exists...
2688 if ((job
= cupsdFindJob(jobid
)) == NULL
)
2691 * Nope - return a "not found" error...
2694 send_ipp_status(con
, IPP_NOT_FOUND
,
2695 _("Job #%d does not exist!"), jobid
);
2700 * See if the job has been completed...
2703 if (job
->state_value
!= IPP_JOB_HELD
)
2706 * Return a "not-possible" error...
2709 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
2710 _("Job #%d is not held for authentication!"),
2716 * See if we have already authenticated...
2719 if (!con
->username
[0])
2721 send_ipp_status(con
, IPP_NOT_AUTHORIZED
,
2722 _("No authentication information provided!"));
2727 * See if the job is owned by the requesting user...
2730 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
2732 send_http_error(con
, HTTP_UNAUTHORIZED
);
2737 * Save the authentication information for this job...
2740 save_auth_info(con
, job
);
2743 * Reset the job-hold-until value to "no-hold"...
2746 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
2747 IPP_TAG_KEYWORD
)) == NULL
)
2748 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
2752 attr
->value_tag
= IPP_TAG_KEYWORD
;
2753 cupsdSetString(&(attr
->values
[0].string
.text
), "no-hold");
2757 * Release the job and return...
2760 cupsdReleaseJob(job
);
2762 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was authenticated by \"%s\".", jobid
,
2768 * 'cancel_all_jobs()' - Cancel all print jobs.
2772 cancel_all_jobs(cupsd_client_t
*con
, /* I - Client connection */
2773 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
2775 http_status_t status
; /* Policy status */
2776 const char *dest
; /* Destination */
2777 cups_ptype_t dtype
; /* Destination type */
2778 char method
[HTTP_MAX_URI
], /* Method portion of URI */
2779 userpass
[HTTP_MAX_URI
], /* Username portion of URI */
2780 host
[HTTP_MAX_URI
], /* Host portion of URI */
2781 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2782 int port
; /* Port portion of URI */
2783 ipp_attribute_t
*attr
; /* Attribute in request */
2784 const char *username
; /* Username */
2785 int purge
; /* Purge? */
2786 cupsd_printer_t
*printer
; /* Printer */
2789 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_all_jobs(%p[%d], %s)", con
,
2790 con
->http
.fd
, uri
->values
[0].string
.text
);
2793 * See if we have a printer URI...
2796 if (strcmp(uri
->name
, "printer-uri"))
2798 send_ipp_status(con
, IPP_BAD_REQUEST
,
2799 _("The printer-uri attribute is required!"));
2804 * Get the username (if any) for the jobs we want to cancel (only if
2805 * "my-jobs" is specified...
2808 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
2809 IPP_TAG_BOOLEAN
)) != NULL
&&
2810 attr
->values
[0].boolean
)
2812 if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
2813 IPP_TAG_NAME
)) != NULL
)
2814 username
= attr
->values
[0].string
.text
;
2817 send_ipp_status(con
, IPP_BAD_REQUEST
,
2818 _("Missing requesting-user-name attribute!"));
2826 * Look for the "purge-jobs" attribute...
2829 if ((attr
= ippFindAttribute(con
->request
, "purge-jobs",
2830 IPP_TAG_BOOLEAN
)) != NULL
)
2831 purge
= attr
->values
[0].boolean
;
2836 * And if the destination is valid...
2839 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2840 sizeof(method
), userpass
, sizeof(userpass
), host
,
2841 sizeof(host
), &port
, resource
, sizeof(resource
));
2843 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
2849 if ((!strncmp(resource
, "/printers/", 10) && resource
[10]) ||
2850 (!strncmp(resource
, "/classes/", 9) && resource
[9]))
2852 send_ipp_status(con
, IPP_NOT_FOUND
,
2853 _("The printer or class was not found."));
2856 else if (strcmp(resource
, "/printers/"))
2858 send_ipp_status(con
, IPP_NOT_FOUND
,
2859 _("The printer-uri \"%s\" is not valid."),
2860 uri
->values
[0].string
.text
);
2868 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
2870 send_http_error(con
, status
);
2875 * Cancel all jobs on all printers...
2878 cupsdCancelJobs(NULL
, username
, purge
);
2880 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs were %s by \"%s\".",
2881 purge
? "purged" : "canceled", get_username(con
));
2889 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
2891 send_http_error(con
, status
);
2896 * Cancel all of the jobs on the named printer...
2899 cupsdCancelJobs(dest
, username
, purge
);
2901 cupsdLogMessage(CUPSD_LOG_INFO
, "All jobs on \"%s\" were %s by \"%s\".",
2902 dest
, purge
? "purged" : "canceled", get_username(con
));
2905 con
->response
->request
.status
.status_code
= IPP_OK
;
2910 * 'cancel_job()' - Cancel a print job.
2914 cancel_job(cupsd_client_t
*con
, /* I - Client connection */
2915 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
2917 ipp_attribute_t
*attr
; /* Current attribute */
2918 int jobid
; /* Job ID */
2919 char method
[HTTP_MAX_URI
], /* Method portion of URI */
2920 username
[HTTP_MAX_URI
], /* Username portion of URI */
2921 host
[HTTP_MAX_URI
], /* Host portion of URI */
2922 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2923 int port
; /* Port portion of URI */
2924 cupsd_job_t
*job
; /* Job information */
2925 const char *dest
; /* Destination */
2926 cups_ptype_t dtype
; /* Destination type (printer or class) */
2927 cupsd_printer_t
*printer
; /* Printer data */
2930 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cancel_job(%p[%d], %s)", con
,
2931 con
->http
.fd
, uri
->values
[0].string
.text
);
2934 * See if we have a job URI or a printer URI...
2937 if (!strcmp(uri
->name
, "printer-uri"))
2940 * Got a printer URI; see if we also have a job-id attribute...
2943 if ((attr
= ippFindAttribute(con
->request
, "job-id",
2944 IPP_TAG_INTEGER
)) == NULL
)
2946 send_ipp_status(con
, IPP_BAD_REQUEST
,
2947 _("Got a printer-uri attribute but no job-id!"));
2951 if ((jobid
= attr
->values
[0].integer
) == 0)
2954 * Find the current job on the specified printer...
2957 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
2958 sizeof(method
), username
, sizeof(username
), host
,
2959 sizeof(host
), &port
, resource
, sizeof(resource
));
2961 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
2967 send_ipp_status(con
, IPP_NOT_FOUND
,
2968 _("The printer or class was not found."));
2973 * See if the printer is currently printing a job...
2977 jobid
= ((cupsd_job_t
*)printer
->job
)->id
;
2981 * No, see if there are any pending jobs...
2984 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2986 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2987 if (job
->state_value
<= IPP_JOB_PROCESSING
&&
2988 !strcasecmp(job
->dest
, dest
))
2995 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("No active jobs on %s!"),
3005 * Got a job URI; parse it to get the job ID...
3008 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
3009 sizeof(method
), username
, sizeof(username
), host
,
3010 sizeof(host
), &port
, resource
, sizeof(resource
));
3012 if (strncmp(resource
, "/jobs/", 6))
3018 send_ipp_status(con
, IPP_BAD_REQUEST
,
3019 _("Bad job-uri attribute \"%s\"!"),
3020 uri
->values
[0].string
.text
);
3024 jobid
= atoi(resource
+ 6);
3028 * See if the job exists...
3031 if ((job
= cupsdFindJob(jobid
)) == NULL
)
3034 * Nope - return a "not found" error...
3037 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
3042 * See if the job is owned by the requesting user...
3045 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
3047 send_http_error(con
, HTTP_UNAUTHORIZED
);
3052 * See if the job is already completed, canceled, or aborted; if so,
3053 * we can't cancel...
3056 if (job
->state_value
>= IPP_JOB_CANCELED
)
3058 switch (job
->state_value
)
3060 case IPP_JOB_CANCELED
:
3061 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3062 _("Job #%d is already canceled - can\'t cancel."),
3066 case IPP_JOB_ABORTED
:
3067 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3068 _("Job #%d is already aborted - can\'t cancel."),
3073 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
3074 _("Job #%d is already completed - can\'t cancel."),
3083 * Cancel the job and return...
3086 cupsdCancelJob(job
, 0, IPP_JOB_CANCELED
);
3089 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was canceled by \"%s\".", jobid
,
3092 con
->response
->request
.status
.status_code
= IPP_OK
;
3097 * 'cancel_subscription()' - Cancel a subscription.
3101 cancel_subscription(
3102 cupsd_client_t
*con
, /* I - Client connection */
3103 int sub_id
) /* I - Subscription ID */
3105 http_status_t status
; /* Policy status */
3106 cupsd_subscription_t
*sub
; /* Subscription */
3109 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3110 "cancel_subscription(con=%p[%d], sub_id=%d)",
3111 con
, con
->http
.fd
, sub_id
);
3114 * Is the subscription ID valid?
3117 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
3120 * Bad subscription ID...
3123 send_ipp_status(con
, IPP_NOT_FOUND
,
3124 _("notify-subscription-id %d no good!"), sub_id
);
3132 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
3134 con
, sub
->owner
)) != HTTP_OK
)
3136 send_http_error(con
, status
);
3141 * Cancel the subscription...
3144 cupsdDeleteSubscription(sub
, 1);
3146 con
->response
->request
.status
.status_code
= IPP_OK
;
3151 * 'check_quotas()' - Check quotas for a printer and user.
3154 static int /* O - 1 if OK, 0 if not */
3155 check_quotas(cupsd_client_t
*con
, /* I - Client connection */
3156 cupsd_printer_t
*p
) /* I - Printer or class */
3158 int i
; /* Looping var */
3159 char username
[33]; /* Username */
3160 cupsd_quota_t
*q
; /* Quota data */
3161 struct passwd
*pw
; /* User password data */
3164 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "check_quotas(%p[%d], %p[%s])",
3165 con
, con
->http
.fd
, p
, p
->name
);
3175 * Figure out who is printing...
3178 strlcpy(username
, get_username(con
), sizeof(username
));
3181 * Check global active job limits for printers and users...
3184 if (MaxJobsPerPrinter
)
3187 * Check if there are too many pending jobs on this printer...
3190 if (cupsdGetPrinterJobCount(p
->name
) >= MaxJobsPerPrinter
)
3192 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for printer \"%s\"...",
3201 * Check if there are too many pending jobs for this user...
3204 if (cupsdGetUserJobCount(username
) >= MaxJobsPerUser
)
3206 cupsdLogMessage(CUPSD_LOG_INFO
, "Too many jobs for user \"%s\"...",
3213 * Check against users...
3216 if (p
->num_users
== 0 && p
->k_limit
== 0 && p
->page_limit
== 0)
3221 pw
= getpwnam(username
);
3224 for (i
= 0; i
< p
->num_users
; i
++)
3225 if (p
->users
[i
][0] == '@')
3228 * Check group membership...
3231 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
3234 else if (!strcasecmp(username
, p
->users
[i
]))
3237 if ((i
< p
->num_users
) == p
->deny_users
)
3239 cupsdLogMessage(CUPSD_LOG_INFO
,
3240 "Denying user \"%s\" access to printer \"%s\"...",
3250 if (p
->k_limit
|| p
->page_limit
)
3252 if ((q
= cupsdUpdateQuota(p
, username
, 0, 0)) == NULL
)
3254 cupsdLogMessage(CUPSD_LOG_ERROR
,
3255 "Unable to allocate quota data for user \"%s\"!",
3260 if ((q
->k_count
>= p
->k_limit
&& p
->k_limit
) ||
3261 (q
->page_count
>= p
->page_limit
&& p
->page_limit
))
3263 cupsdLogMessage(CUPSD_LOG_INFO
, "User \"%s\" is over the quota limit...",
3270 * If we have gotten this far, we're done!
3278 * 'copy_attribute()' - Copy a single attribute.
3281 static ipp_attribute_t
* /* O - New attribute */
3283 ipp_t
*to
, /* O - Destination request/response */
3284 ipp_attribute_t
*attr
, /* I - Attribute to copy */
3285 int quickcopy
) /* I - Do a quick copy? */
3287 int i
; /* Looping var */
3288 ipp_attribute_t
*toattr
; /* Destination attribute */
3291 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3292 "copy_attribute(%p, %p[%s,%x,%x])", to
, attr
,
3293 attr
->name
? attr
->name
: "(null)", attr
->group_tag
,
3296 switch (attr
->value_tag
& ~IPP_TAG_COPY
)
3299 toattr
= ippAddSeparator(to
);
3302 case IPP_TAG_INTEGER
:
3304 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
3305 attr
->name
, attr
->num_values
, NULL
);
3307 for (i
= 0; i
< attr
->num_values
; i
++)
3308 toattr
->values
[i
].integer
= attr
->values
[i
].integer
;
3311 case IPP_TAG_BOOLEAN
:
3312 toattr
= ippAddBooleans(to
, attr
->group_tag
, attr
->name
,
3313 attr
->num_values
, NULL
);
3315 for (i
= 0; i
< attr
->num_values
; i
++)
3316 toattr
->values
[i
].boolean
= attr
->values
[i
].boolean
;
3319 case IPP_TAG_STRING
:
3322 case IPP_TAG_KEYWORD
:
3324 case IPP_TAG_URISCHEME
:
3325 case IPP_TAG_CHARSET
:
3326 case IPP_TAG_LANGUAGE
:
3327 case IPP_TAG_MIMETYPE
:
3328 toattr
= ippAddStrings(to
, attr
->group_tag
,
3329 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
3330 attr
->name
, attr
->num_values
, NULL
, NULL
);
3334 for (i
= 0; i
< attr
->num_values
; i
++)
3335 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
3339 for (i
= 0; i
< attr
->num_values
; i
++)
3340 toattr
->values
[i
].string
.text
= _cupsStrAlloc(attr
->values
[i
].string
.text
);
3345 toattr
= ippAddDate(to
, attr
->group_tag
, attr
->name
,
3346 attr
->values
[0].date
);
3349 case IPP_TAG_RESOLUTION
:
3350 toattr
= ippAddResolutions(to
, attr
->group_tag
, attr
->name
,
3351 attr
->num_values
, IPP_RES_PER_INCH
,
3354 for (i
= 0; i
< attr
->num_values
; i
++)
3356 toattr
->values
[i
].resolution
.xres
= attr
->values
[i
].resolution
.xres
;
3357 toattr
->values
[i
].resolution
.yres
= attr
->values
[i
].resolution
.yres
;
3358 toattr
->values
[i
].resolution
.units
= attr
->values
[i
].resolution
.units
;
3362 case IPP_TAG_RANGE
:
3363 toattr
= ippAddRanges(to
, attr
->group_tag
, attr
->name
,
3364 attr
->num_values
, NULL
, NULL
);
3366 for (i
= 0; i
< attr
->num_values
; i
++)
3368 toattr
->values
[i
].range
.lower
= attr
->values
[i
].range
.lower
;
3369 toattr
->values
[i
].range
.upper
= attr
->values
[i
].range
.upper
;
3373 case IPP_TAG_TEXTLANG
:
3374 case IPP_TAG_NAMELANG
:
3375 toattr
= ippAddStrings(to
, attr
->group_tag
,
3376 (ipp_tag_t
)(attr
->value_tag
| quickcopy
),
3377 attr
->name
, attr
->num_values
, NULL
, NULL
);
3381 for (i
= 0; i
< attr
->num_values
; i
++)
3383 toattr
->values
[i
].string
.charset
= attr
->values
[i
].string
.charset
;
3384 toattr
->values
[i
].string
.text
= attr
->values
[i
].string
.text
;
3389 for (i
= 0; i
< attr
->num_values
; i
++)
3392 toattr
->values
[i
].string
.charset
=
3393 _cupsStrAlloc(attr
->values
[i
].string
.charset
);
3395 toattr
->values
[i
].string
.charset
=
3396 toattr
->values
[0].string
.charset
;
3398 toattr
->values
[i
].string
.text
= _cupsStrAlloc(attr
->values
[i
].string
.text
);
3403 case IPP_TAG_BEGIN_COLLECTION
:
3404 toattr
= ippAddCollections(to
, attr
->group_tag
, attr
->name
,
3405 attr
->num_values
, NULL
);
3407 for (i
= 0; i
< attr
->num_values
; i
++)
3409 toattr
->values
[i
].collection
= ippNew();
3410 copy_attrs(toattr
->values
[i
].collection
, attr
->values
[i
].collection
,
3411 NULL
, IPP_TAG_ZERO
, 0);
3416 toattr
= ippAddIntegers(to
, attr
->group_tag
, attr
->value_tag
,
3417 attr
->name
, attr
->num_values
, NULL
);
3419 for (i
= 0; i
< attr
->num_values
; i
++)
3421 toattr
->values
[i
].unknown
.length
= attr
->values
[i
].unknown
.length
;
3423 if (toattr
->values
[i
].unknown
.length
> 0)
3425 if ((toattr
->values
[i
].unknown
.data
=
3426 malloc(toattr
->values
[i
].unknown
.length
)) == NULL
)
3427 toattr
->values
[i
].unknown
.length
= 0;
3429 memcpy(toattr
->values
[i
].unknown
.data
,
3430 attr
->values
[i
].unknown
.data
,
3431 toattr
->values
[i
].unknown
.length
);
3434 break; /* anti-compiler-warning-code */
3442 * 'copy_attrs()' - Copy attributes from one request to another.
3446 copy_attrs(ipp_t
*to
, /* I - Destination request */
3447 ipp_t
*from
, /* I - Source request */
3448 cups_array_t
*ra
, /* I - Requested attributes */
3449 ipp_tag_t group
, /* I - Group to copy */
3450 int quickcopy
) /* I - Do a quick copy? */
3452 ipp_attribute_t
*fromattr
; /* Source attribute */
3455 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3456 "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
3457 to
, from
, ra
, group
, quickcopy
);
3462 for (fromattr
= from
->attrs
; fromattr
; fromattr
= fromattr
->next
)
3465 * Filter attributes as needed...
3468 if (group
!= IPP_TAG_ZERO
&& fromattr
->group_tag
!= group
&&
3469 fromattr
->group_tag
!= IPP_TAG_ZERO
&& !fromattr
->name
)
3472 if (!ra
|| cupsArrayFind(ra
, fromattr
->name
))
3473 copy_attribute(to
, fromattr
, quickcopy
);
3479 * 'copy_banner()' - Copy a banner file to the requests directory for the
3483 static int /* O - Size of banner file in kbytes */
3484 copy_banner(cupsd_client_t
*con
, /* I - Client connection */
3485 cupsd_job_t
*job
, /* I - Job information */
3486 const char *name
) /* I - Name of banner */
3488 int i
; /* Looping var */
3489 int kbytes
; /* Size of banner file in kbytes */
3490 char filename
[1024]; /* Job filename */
3491 cupsd_banner_t
*banner
; /* Pointer to banner */
3492 cups_file_t
*in
; /* Input file */
3493 cups_file_t
*out
; /* Output file */
3494 int ch
; /* Character from file */
3495 char attrname
[255], /* Name of attribute */
3496 *s
; /* Pointer into name */
3497 ipp_attribute_t
*attr
; /* Attribute */
3500 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_banner(%p[%d], %p[%d], %s)",
3501 con
, con
->http
.fd
, job
, job
->id
, name
? name
: "(null)");
3504 * Find the banner; return if not found or "none"...
3507 if (!name
|| !strcmp(name
, "none") ||
3508 (banner
= cupsdFindBanner(name
)) == NULL
)
3512 * Open the banner and job files...
3515 if (add_file(con
, job
, banner
->filetype
, 0))
3518 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
3520 if ((out
= cupsFileOpen(filename
, "w")) == NULL
)
3522 cupsdLogMessage(CUPSD_LOG_ERROR
,
3523 "copy_banner: Unable to create banner job file %s - %s",
3524 filename
, strerror(errno
));
3529 fchmod(cupsFileNumber(out
), 0640);
3530 fchown(cupsFileNumber(out
), RunUser
, Group
);
3533 * Try the localized banner file under the subdirectory...
3536 strlcpy(attrname
, job
->attrs
->attrs
->next
->values
[0].string
.text
,
3538 if (strlen(attrname
) > 2 && attrname
[2] == '-')
3541 * Convert ll-cc to ll_CC...
3545 attrname
[3] = toupper(attrname
[3] & 255);
3546 attrname
[4] = toupper(attrname
[4] & 255);
3549 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
3552 if (access(filename
, 0) && strlen(attrname
) > 2)
3555 * Wasn't able to find "ll_CC" locale file; try the non-national
3556 * localization banner directory.
3561 snprintf(filename
, sizeof(filename
), "%s/banners/%s/%s", DataDir
,
3565 if (access(filename
, 0))
3568 * Use the non-localized banner file.
3571 snprintf(filename
, sizeof(filename
), "%s/banners/%s", DataDir
, name
);
3574 if ((in
= cupsFileOpen(filename
, "r")) == NULL
)
3578 cupsdLogMessage(CUPSD_LOG_ERROR
,
3579 "copy_banner: Unable to open banner template file %s - %s",
3580 filename
, strerror(errno
));
3586 * Parse the file to the end...
3589 while ((ch
= cupsFileGetChar(in
)) != EOF
)
3593 * Get an attribute name...
3596 for (s
= attrname
; (ch
= cupsFileGetChar(in
)) != EOF
;)
3597 if (!isalpha(ch
& 255) && ch
!= '-' && ch
!= '?')
3599 else if (s
< (attrname
+ sizeof(attrname
) - 1))
3609 * Ignore { followed by stuff that is not an attribute name...
3612 cupsFilePrintf(out
, "{%s%c", attrname
, ch
);
3617 * See if it is defined...
3620 if (attrname
[0] == '?')
3625 if (!strcmp(s
, "printer-name"))
3627 cupsFilePuts(out
, job
->dest
);
3630 else if ((attr
= ippFindAttribute(job
->attrs
, s
, IPP_TAG_ZERO
)) == NULL
)
3633 * See if we have a leading question mark...
3636 if (attrname
[0] != '?')
3639 * Nope, write to file as-is; probably a PostScript procedure...
3642 cupsFilePrintf(out
, "{%s}", attrname
);
3649 * Output value(s)...
3652 for (i
= 0; i
< attr
->num_values
; i
++)
3655 cupsFilePutChar(out
, ',');
3657 switch (attr
->value_tag
)
3659 case IPP_TAG_INTEGER
:
3661 if (!strncmp(s
, "time-at-", 8))
3662 cupsFilePuts(out
, cupsdGetDateTime(attr
->values
[i
].integer
));
3664 cupsFilePrintf(out
, "%d", attr
->values
[i
].integer
);
3667 case IPP_TAG_BOOLEAN
:
3668 cupsFilePrintf(out
, "%d", attr
->values
[i
].boolean
);
3671 case IPP_TAG_NOVALUE
:
3672 cupsFilePuts(out
, "novalue");
3675 case IPP_TAG_RANGE
:
3676 cupsFilePrintf(out
, "%d-%d", attr
->values
[i
].range
.lower
,
3677 attr
->values
[i
].range
.upper
);
3680 case IPP_TAG_RESOLUTION
:
3681 cupsFilePrintf(out
, "%dx%d%s", attr
->values
[i
].resolution
.xres
,
3682 attr
->values
[i
].resolution
.yres
,
3683 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
3688 case IPP_TAG_STRING
:
3691 case IPP_TAG_KEYWORD
:
3692 case IPP_TAG_CHARSET
:
3693 case IPP_TAG_LANGUAGE
:
3694 if (!strcasecmp(banner
->filetype
->type
, "postscript"))
3697 * Need to quote strings for PS banners...
3702 for (p
= attr
->values
[i
].string
.text
; *p
; p
++)
3704 if (*p
== '(' || *p
== ')' || *p
== '\\')
3706 cupsFilePutChar(out
, '\\');
3707 cupsFilePutChar(out
, *p
);
3709 else if (*p
< 32 || *p
> 126)
3710 cupsFilePrintf(out
, "\\%03o", *p
& 255);
3712 cupsFilePutChar(out
, *p
);
3716 cupsFilePuts(out
, attr
->values
[i
].string
.text
);
3720 break; /* anti-compiler-warning-code */
3724 else if (ch
== '\\') /* Quoted char */
3726 ch
= cupsFileGetChar(in
);
3728 if (ch
!= '{') /* Only do special handling for \{ */
3729 cupsFilePutChar(out
, '\\');
3731 cupsFilePutChar(out
, ch
);
3734 cupsFilePutChar(out
, ch
);
3738 kbytes
= (cupsFileTell(out
) + 1023) / 1024;
3740 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
3741 IPP_TAG_INTEGER
)) != NULL
)
3742 attr
->values
[0].integer
+= kbytes
;
3751 * 'copy_file()' - Copy a PPD file or interface script...
3754 static int /* O - 0 = success, -1 = error */
3755 copy_file(const char *from
, /* I - Source file */
3756 const char *to
) /* I - Destination file */
3758 cups_file_t
*src
, /* Source file */
3759 *dst
; /* Destination file */
3760 int bytes
; /* Bytes to read/write */
3761 char buffer
[2048]; /* Copy buffer */
3764 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "copy_file(\"%s\", \"%s\")", from
, to
);
3767 * Open the source and destination file for a copy...
3770 if ((src
= cupsFileOpen(from
, "rb")) == NULL
)
3773 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
3780 * Copy the source file to the destination...
3783 while ((bytes
= cupsFileRead(src
, buffer
, sizeof(buffer
))) > 0)
3784 if (cupsFileWrite(dst
, buffer
, bytes
) < bytes
)
3792 * Close both files and return...
3797 return (cupsFileClose(dst
));
3802 * 'copy_model()' - Copy a PPD model file, substituting default values
3806 static int /* O - 0 = success, -1 = error */
3807 copy_model(cupsd_client_t
*con
, /* I - Client connection */
3808 const char *from
, /* I - Source file */
3809 const char *to
) /* I - Destination file */
3811 fd_set
*input
; /* select() input set */
3812 struct timeval timeout
; /* select() timeout */
3813 int maxfd
; /* Maximum file descriptor for select() */
3814 char tempfile
[1024]; /* Temporary PPD file */
3815 int tempfd
; /* Temporary PPD file descriptor */
3816 int temppid
; /* Process ID of cups-driverd */
3817 int temppipe
[2]; /* Temporary pipes */
3818 char *argv
[4], /* Command-line arguments */
3819 *envp
[MAX_ENV
]; /* Environment */
3820 cups_file_t
*src
, /* Source file */
3821 *dst
; /* Destination file */
3822 int bytes
, /* Bytes from pipe */
3823 total
; /* Total bytes from pipe */
3824 char buffer
[2048], /* Copy buffer */
3825 *ptr
; /* Pointer into buffer */
3826 int i
; /* Looping var */
3827 char option
[PPD_MAX_NAME
], /* Option name */
3828 choice
[PPD_MAX_NAME
]; /* Choice name */
3829 int num_defaults
; /* Number of default options */
3830 ppd_default_t
*defaults
; /* Default options */
3831 char cups_protocol
[PPD_MAX_LINE
];
3832 /* cupsProtocol attribute */
3833 int have_letter
, /* Have Letter size */
3834 have_a4
; /* Have A4 size */
3835 #ifdef HAVE_LIBPAPER
3836 char *paper_result
; /* Paper size name from libpaper */
3837 char system_paper
[64]; /* Paper size name buffer */
3838 #endif /* HAVE_LIBPAPER */
3841 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3842 "copy_model(con=%p, from=\"%s\", to=\"%s\")",
3846 * Run cups-driverd to get the PPD file...
3849 argv
[0] = "cups-driverd";
3851 argv
[2] = (char *)from
;
3854 cupsdLoadEnv(envp
, (int)(sizeof(envp
) / sizeof(envp
[0])));
3856 snprintf(buffer
, sizeof(buffer
), "%s/daemon/cups-driverd", ServerBin
);
3857 snprintf(tempfile
, sizeof(tempfile
), "%s/%d.ppd", TempDir
, con
->http
.fd
);
3858 tempfd
= open(tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0600);
3862 cupsdOpenPipe(temppipe
);
3864 if ((input
= calloc(1, SetSize
)) == NULL
)
3869 cupsdLogMessage(CUPSD_LOG_ERROR
,
3870 "copy_model: Unable to allocate %d bytes for select()...",
3875 cupsdLogMessage(CUPSD_LOG_DEBUG
,
3876 "copy_model: Running \"cups-driverd cat %s\"...", from
);
3878 if (!cupsdStartProcess(buffer
, argv
, envp
, -1, temppipe
[1], CGIPipes
[1],
3890 * Wait up to 30 seconds for the PPD file to be copied...
3895 if (temppipe
[0] > CGIPipes
[0])
3896 maxfd
= temppipe
[0] + 1;
3898 maxfd
= CGIPipes
[0] + 1;
3903 * See if we have data ready...
3908 FD_SET(temppipe
[0], input
);
3909 FD_SET(CGIPipes
[0], input
);
3911 timeout
.tv_sec
= 30;
3912 timeout
.tv_usec
= 0;
3914 if ((i
= select(maxfd
, input
, NULL
, NULL
, &timeout
)) < 0)
3924 * We have timed out...
3930 if (FD_ISSET(temppipe
[0], input
))
3933 * Read the PPD file from the pipe, and write it to the PPD file.
3936 if ((bytes
= read(temppipe
[0], buffer
, sizeof(buffer
))) > 0)
3938 if (write(tempfd
, buffer
, bytes
) < bytes
)
3947 if (FD_ISSET(CGIPipes
[0], input
))
3959 * No data from cups-deviced...
3962 cupsdLogMessage(CUPSD_LOG_ERROR
, "copy_model: empty PPD file!");
3968 * Read the source file and see what page sizes are supported...
3971 if ((src
= cupsFileOpen(tempfile
, "rb")) == NULL
)
3980 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
3981 if (!strncmp(buffer
, "*PageSize ", 10))
3984 * Strip UI text and command data from the end of the line...
3987 if ((ptr
= strchr(buffer
+ 10, '/')) != NULL
)
3989 if ((ptr
= strchr(buffer
+ 10, ':')) != NULL
)
3992 for (ptr
= buffer
+ 10; isspace(*ptr
); ptr
++);
3995 * Look for Letter and A4 page sizes...
3998 if (!strcmp(ptr
, "Letter"))
4001 if (!strcmp(ptr
, "A4"))
4005 cupsFileRewind(src
);
4008 * Open the destination (if possible) and set the default options...
4013 cups_protocol
[0] = '\0';
4015 if ((dst
= cupsFileOpen(to
, "rb")) != NULL
)
4018 * Read all of the default lines from the old PPD...
4021 while (cupsFileGets(dst
, buffer
, sizeof(buffer
)))
4022 if (!strncmp(buffer
, "*Default", 8))
4025 * Add the default option...
4028 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4029 choice
, sizeof(choice
)))
4030 num_defaults
= ppd_add_default(option
, choice
, num_defaults
,
4033 else if (!strncmp(buffer
, "*cupsProtocol:", 14))
4034 strlcpy(cups_protocol
, buffer
, sizeof(cups_protocol
));
4038 #ifdef HAVE_LIBPAPER
4039 else if ((paper_result
= systempapername()) != NULL
)
4042 * Set the default media sizes from the systemwide default...
4045 strlcpy(system_paper
, paper_result
, sizeof(system_paper
));
4046 system_paper
[0] = toupper(system_paper
[0] & 255);
4048 if ((!strcmp(system_paper
, "Letter") && have_letter
) ||
4049 (!strcmp(system_paper
, "A4") && have_a4
))
4051 num_defaults
= ppd_add_default("PageSize", system_paper
,
4052 num_defaults
, &defaults
);
4053 num_defaults
= ppd_add_default("PageRegion", system_paper
,
4054 num_defaults
, &defaults
);
4055 num_defaults
= ppd_add_default("PaperDimension", system_paper
,
4056 num_defaults
, &defaults
);
4057 num_defaults
= ppd_add_default("ImageableArea", system_paper
,
4058 num_defaults
, &defaults
);
4061 #endif /* HAVE_LIBPAPER */
4065 * Add the default media sizes...
4067 * Note: These values are generally not valid for large-format devices
4068 * like plotters, however it is probably safe to say that those
4069 * users will configure the media size after initially adding
4070 * the device anyways...
4073 if (!DefaultLanguage
||
4074 !strcasecmp(DefaultLanguage
, "C") ||
4075 !strcasecmp(DefaultLanguage
, "POSIX") ||
4076 !strcasecmp(DefaultLanguage
, "en") ||
4077 !strncasecmp(DefaultLanguage
, "en_US", 5) ||
4078 !strncasecmp(DefaultLanguage
, "en_CA", 5) ||
4079 !strncasecmp(DefaultLanguage
, "fr_CA", 5))
4082 * These are the only locales that will default to "letter" size...
4087 num_defaults
= ppd_add_default("PageSize", "Letter", num_defaults
,
4089 num_defaults
= ppd_add_default("PageRegion", "Letter", num_defaults
,
4091 num_defaults
= ppd_add_default("PaperDimension", "Letter", num_defaults
,
4093 num_defaults
= ppd_add_default("ImageableArea", "Letter", num_defaults
,
4100 * The rest default to "a4" size...
4103 num_defaults
= ppd_add_default("PageSize", "A4", num_defaults
,
4105 num_defaults
= ppd_add_default("PageRegion", "A4", num_defaults
,
4107 num_defaults
= ppd_add_default("PaperDimension", "A4", num_defaults
,
4109 num_defaults
= ppd_add_default("ImageableArea", "A4", num_defaults
,
4115 * Open the destination file for a copy...
4118 if ((dst
= cupsFileOpen(to
, "wb")) == NULL
)
4120 if (num_defaults
> 0)
4129 * Copy the source file to the destination...
4132 while (cupsFileGets(src
, buffer
, sizeof(buffer
)))
4134 if (!strncmp(buffer
, "*Default", 8))
4137 * Check for an previous default option choice...
4140 if (!ppd_parse_line(buffer
, option
, sizeof(option
),
4141 choice
, sizeof(choice
)))
4143 for (i
= 0; i
< num_defaults
; i
++)
4144 if (!strcmp(option
, defaults
[i
].option
))
4147 * Substitute the previous choice...
4150 snprintf(buffer
, sizeof(buffer
), "*Default%s: %s", option
,
4151 defaults
[i
].choice
);
4157 cupsFilePrintf(dst
, "%s\n", buffer
);
4160 if (cups_protocol
[0])
4161 cupsFilePrintf(dst
, "%s\n", cups_protocol
);
4163 if (num_defaults
> 0)
4167 * Close both files and return...
4174 return (cupsFileClose(dst
));
4179 * 'copy_job_attrs()' - Copy job attributes.
4183 copy_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
4184 cupsd_job_t
*job
, /* I - Job */
4185 cups_array_t
*ra
) /* I - Requested attributes array */
4187 char job_uri
[HTTP_MAX_URI
]; /* Job URI */
4191 * Send the requested attributes for each job...
4194 httpAssembleURIf(HTTP_URI_CODING_ALL
, job_uri
, sizeof(job_uri
), "ipp", NULL
,
4195 con
->servername
, con
->serverport
, "/jobs/%d",
4198 if (!ra
|| cupsArrayFind(ra
, "job-more-info"))
4199 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4200 "job-more-info", NULL
, job_uri
);
4202 if (job
->state_value
> IPP_JOB_PROCESSING
&&
4203 (!ra
|| cupsArrayFind(ra
, "job-preserved")))
4204 ippAddBoolean(con
->response
, IPP_TAG_JOB
, "job-preserved",
4205 job
->num_files
> 0);
4207 if (!ra
|| cupsArrayFind(ra
, "job-printer-up-time"))
4208 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
,
4209 "job-printer-up-time", time(NULL
));
4211 if (!ra
|| cupsArrayFind(ra
, "job-state-reasons"))
4212 add_job_state_reasons(con
, job
);
4214 if (!ra
|| cupsArrayFind(ra
, "job-uri"))
4215 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
,
4216 "job-uri", NULL
, job_uri
);
4218 copy_attrs(con
->response
, job
->attrs
, ra
, IPP_TAG_JOB
, 0);
4223 * 'copy_printer_attrs()' - Copy printer attributes.
4228 cupsd_client_t
*con
, /* I - Client connection */
4229 cupsd_printer_t
*printer
, /* I - Printer */
4230 cups_array_t
*ra
) /* I - Requested attributes array */
4232 char printer_uri
[HTTP_MAX_URI
];
4234 time_t curtime
; /* Current time */
4235 int i
; /* Looping var */
4236 ipp_attribute_t
*history
; /* History collection */
4240 * Copy the printer attributes to the response using requested-attributes
4241 * and document-format attributes that may be provided by the client.
4244 curtime
= time(NULL
);
4247 if ((!ra
|| cupsArrayFind(ra
, "com.apple.print.recoverable-message")) &&
4248 printer
->recoverable
)
4249 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4250 "com.apple.print.recoverable-message", NULL
,
4251 printer
->recoverable
);
4252 #endif /* __APPLE__ */
4254 if (!ra
|| cupsArrayFind(ra
, "printer-current-time"))
4255 ippAddDate(con
->response
, IPP_TAG_PRINTER
, "printer-current-time",
4256 ippTimeToDate(curtime
));
4258 if (!ra
|| cupsArrayFind(ra
, "printer-error-policy"))
4259 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4260 "printer-error-policy", NULL
, printer
->error_policy
);
4262 if (!ra
|| cupsArrayFind(ra
, "printer-is-accepting-jobs"))
4263 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs",
4264 printer
->accepting
);
4266 if (!ra
|| cupsArrayFind(ra
, "printer-is-shared"))
4267 ippAddBoolean(con
->response
, IPP_TAG_PRINTER
, "printer-is-shared",
4270 if (!ra
|| cupsArrayFind(ra
, "printer-op-policy"))
4271 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4272 "printer-op-policy", NULL
, printer
->op_policy
);
4274 if (!ra
|| cupsArrayFind(ra
, "printer-state"))
4275 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
4278 if (!ra
|| cupsArrayFind(ra
, "printer-state-change-time"))
4279 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4280 "printer-state-change-time", printer
->state_time
);
4282 if (MaxPrinterHistory
> 0 && printer
->num_history
> 0 &&
4283 cupsArrayFind(ra
, "printer-state-history"))
4286 * Printer history is only sent if specifically requested, so that
4287 * older CUPS/IPP clients won't barf on the collection attributes.
4290 history
= ippAddCollections(con
->response
, IPP_TAG_PRINTER
,
4291 "printer-state-history",
4292 printer
->num_history
, NULL
);
4294 for (i
= 0; i
< printer
->num_history
; i
++)
4295 copy_attrs(history
->values
[i
].collection
= ippNew(), printer
->history
[i
],
4296 NULL
, IPP_TAG_ZERO
, 0);
4299 if (!ra
|| cupsArrayFind(ra
, "printer-state-message"))
4300 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4301 "printer-state-message", NULL
, printer
->state_message
);
4303 if (!ra
|| cupsArrayFind(ra
, "printer-state-reasons"))
4304 add_printer_state_reasons(con
, printer
);
4306 if (!ra
|| cupsArrayFind(ra
, "printer-type"))
4308 int type
; /* printer-type value */
4312 * Add the CUPS-specific printer-type attribute...
4315 type
= printer
->type
;
4317 if (printer
== DefaultPrinter
)
4318 type
|= CUPS_PRINTER_DEFAULT
;
4320 if (!printer
->accepting
)
4321 type
|= CUPS_PRINTER_REJECTING
;
4323 if (!printer
->shared
)
4324 type
|= CUPS_PRINTER_NOT_SHARED
;
4326 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-type",
4330 if (!ra
|| cupsArrayFind(ra
, "printer-up-time"))
4331 ippAddInteger(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4332 "printer-up-time", curtime
);
4334 if ((!ra
|| cupsArrayFind(ra
, "printer-uri-supported")) &&
4335 !ippFindAttribute(printer
->attrs
, "printer-uri-supported",
4338 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4339 "ipp", NULL
, con
->servername
, con
->serverport
,
4340 (printer
->type
& CUPS_PRINTER_CLASS
) ?
4341 "/classes/%s" : "/printers/%s", printer
->name
);
4342 ippAddString(con
->response
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4343 "printer-uri-supported", NULL
, printer_uri
);
4344 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "printer-uri-supported=\"%s\"",
4348 if (!ra
|| cupsArrayFind(ra
, "queued-job-count"))
4349 add_queued_job_count(con
, printer
);
4351 copy_attrs(con
->response
, printer
->attrs
, ra
, IPP_TAG_ZERO
, 0);
4352 copy_attrs(con
->response
, CommonData
, ra
, IPP_TAG_ZERO
, IPP_TAG_COPY
);
4357 * 'copy_subscription_attrs()' - Copy subscription attributes.
4361 copy_subscription_attrs(
4362 cupsd_client_t
*con
, /* I - Client connection */
4363 cupsd_subscription_t
*sub
, /* I - Subscription */
4364 cups_array_t
*ra
) /* I - Requested attributes array */
4366 ipp_attribute_t
*attr
; /* Current attribute */
4367 char printer_uri
[HTTP_MAX_URI
];
4369 int count
; /* Number of events */
4370 unsigned mask
; /* Current event mask */
4371 const char *name
; /* Current event name */
4375 * Copy the subscription attributes to the response using the
4376 * requested-attributes attribute that may be provided by the client.
4379 if (!ra
|| cupsArrayFind(ra
, "notify-events"))
4381 if ((name
= cupsdEventName((cupsd_eventmask_t
)sub
->mask
)) != NULL
)
4384 * Simple event list...
4387 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
,
4388 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
4389 "notify-events", NULL
, name
);
4394 * Complex event list...
4397 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
4398 if (sub
->mask
& mask
)
4401 attr
= ippAddStrings(con
->response
, IPP_TAG_SUBSCRIPTION
,
4402 (ipp_tag_t
)(IPP_TAG_KEYWORD
| IPP_TAG_COPY
),
4403 "notify-events", count
, NULL
, NULL
);
4405 for (mask
= 1, count
= 0; mask
< CUPSD_EVENT_ALL
; mask
<<= 1)
4406 if (sub
->mask
& mask
)
4408 attr
->values
[count
].string
.text
=
4409 (char *)cupsdEventName((cupsd_eventmask_t
)mask
);
4416 if (sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-job-id")))
4417 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4418 "notify-job-id", sub
->job
->id
);
4420 if (!sub
->job
&& (!ra
|| cupsArrayFind(ra
, "notify-lease-duration")))
4421 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4422 "notify-lease-duration", sub
->lease
);
4424 if (sub
->dest
&& (!ra
|| cupsArrayFind(ra
, "notify-printer-uri")))
4426 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
4427 "ipp", NULL
, con
->servername
, con
->serverport
,
4428 "/printers/%s", sub
->dest
->name
);
4429 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
4430 "notify-printer-uri", NULL
, printer_uri
);
4433 if (sub
->recipient
&& (!ra
|| cupsArrayFind(ra
, "notify-recipient-uri")))
4434 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
4435 "notify-recipient-uri", NULL
, sub
->recipient
);
4436 else if (!ra
|| cupsArrayFind(ra
, "notify-pull-method"))
4437 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
,
4438 "notify-pull-method", NULL
, "ippget");
4440 if (!ra
|| cupsArrayFind(ra
, "notify-subscriber-user-name"))
4441 ippAddString(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_NAME
,
4442 "notify-subscriber-user-name", NULL
, sub
->owner
);
4444 if (!ra
|| cupsArrayFind(ra
, "notify-subscription-id"))
4445 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4446 "notify-subscription-id", sub
->id
);
4448 if (!ra
|| cupsArrayFind(ra
, "notify-time-interval"))
4449 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4450 "notify-time-interval", sub
->interval
);
4452 if (sub
->user_data_len
> 0 && (!ra
|| cupsArrayFind(ra
, "notify-user-data")))
4453 ippAddOctetString(con
->response
, IPP_TAG_SUBSCRIPTION
, "notify-user-data",
4454 sub
->user_data
, sub
->user_data_len
);
4459 * 'create_job()' - Print a file to a printer or class.
4463 create_job(cupsd_client_t
*con
, /* I - Client connection */
4464 ipp_attribute_t
*uri
) /* I - Printer URI */
4466 cupsd_job_t
*job
; /* New job */
4469 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "create_job(%p[%d], %s)", con
,
4470 con
->http
.fd
, uri
->values
[0].string
.text
);
4473 * Create the job object...
4476 if ((job
= add_job(con
, uri
, NULL
, NULL
)) == NULL
)
4480 * Save and log the job...
4485 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d created on \"%s\" by \"%s\".",
4486 job
->id
, job
->dest
, job
->username
);
4491 * 'create_requested_array()' - Create an array for the requested-attributes.
4494 static cups_array_t
* /* O - Array of attributes or NULL */
4495 create_requested_array(ipp_t
*request
) /* I - IPP request */
4497 int i
; /* Looping var */
4498 ipp_attribute_t
*requested
; /* requested-attributes attribute */
4499 cups_array_t
*ra
; /* Requested attributes array */
4500 char *value
; /* Current value */
4504 * Get the requested-attributes attribute, and return NULL if we don't
4508 if ((requested
= ippFindAttribute(request
, "requested-attributes",
4509 IPP_TAG_KEYWORD
)) == NULL
)
4513 * If the attribute contains a single "all" keyword, return NULL...
4516 if (requested
->num_values
== 1 &&
4517 !strcmp(requested
->values
[0].string
.text
, "all"))
4521 * Create an array using "strcmp" as the comparison function...
4524 ra
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
4526 for (i
= 0; i
< requested
->num_values
; i
++)
4528 value
= requested
->values
[i
].string
.text
;
4530 if (!strcmp(value
, "job-template"))
4532 cupsArrayAdd(ra
, "copies");
4533 cupsArrayAdd(ra
, "copies-default");
4534 cupsArrayAdd(ra
, "copies-supported");
4535 cupsArrayAdd(ra
, "finishings");
4536 cupsArrayAdd(ra
, "finishings-default");
4537 cupsArrayAdd(ra
, "finishings-supported");
4538 cupsArrayAdd(ra
, "job-hold-until");
4539 cupsArrayAdd(ra
, "job-hold-until-default");
4540 cupsArrayAdd(ra
, "job-hold-until-supported");
4541 cupsArrayAdd(ra
, "job-priority");
4542 cupsArrayAdd(ra
, "job-priority-default");
4543 cupsArrayAdd(ra
, "job-priority-supported");
4544 cupsArrayAdd(ra
, "job-sheets");
4545 cupsArrayAdd(ra
, "job-sheets-default");
4546 cupsArrayAdd(ra
, "job-sheets-supported");
4547 cupsArrayAdd(ra
, "media");
4548 cupsArrayAdd(ra
, "media-default");
4549 cupsArrayAdd(ra
, "media-supported");
4550 cupsArrayAdd(ra
, "multiple-document-handling");
4551 cupsArrayAdd(ra
, "multiple-document-handling-default");
4552 cupsArrayAdd(ra
, "multiple-document-handling-supported");
4553 cupsArrayAdd(ra
, "number-up");
4554 cupsArrayAdd(ra
, "number-up-default");
4555 cupsArrayAdd(ra
, "number-up-supported");
4556 cupsArrayAdd(ra
, "orientation-requested");
4557 cupsArrayAdd(ra
, "orientation-requested-default");
4558 cupsArrayAdd(ra
, "orientation-requested-supported");
4559 cupsArrayAdd(ra
, "page-ranges");
4560 cupsArrayAdd(ra
, "page-ranges-supported");
4561 cupsArrayAdd(ra
, "printer-resolution");
4562 cupsArrayAdd(ra
, "printer-resolution-default");
4563 cupsArrayAdd(ra
, "printer-resolution-supported");
4564 cupsArrayAdd(ra
, "print-quality");
4565 cupsArrayAdd(ra
, "print-quality-default");
4566 cupsArrayAdd(ra
, "print-quality-supported");
4567 cupsArrayAdd(ra
, "sides");
4568 cupsArrayAdd(ra
, "sides-default");
4569 cupsArrayAdd(ra
, "sides-supported");
4571 else if (!strcmp(value
, "job-description"))
4573 cupsArrayAdd(ra
, "date-time-at-completed");
4574 cupsArrayAdd(ra
, "date-time-at-creation");
4575 cupsArrayAdd(ra
, "date-time-at-processing");
4576 cupsArrayAdd(ra
, "job-detailed-status-message");
4577 cupsArrayAdd(ra
, "job-document-access-errors");
4578 cupsArrayAdd(ra
, "job-id");
4579 cupsArrayAdd(ra
, "job-impressions");
4580 cupsArrayAdd(ra
, "job-impressions-completed");
4581 cupsArrayAdd(ra
, "job-k-octets");
4582 cupsArrayAdd(ra
, "job-k-octets-processed");
4583 cupsArrayAdd(ra
, "job-media-sheets");
4584 cupsArrayAdd(ra
, "job-media-sheets-completed");
4585 cupsArrayAdd(ra
, "job-message-from-operator");
4586 cupsArrayAdd(ra
, "job-more-info");
4587 cupsArrayAdd(ra
, "job-name");
4588 cupsArrayAdd(ra
, "job-originating-user-name");
4589 cupsArrayAdd(ra
, "job-printer-up-time");
4590 cupsArrayAdd(ra
, "job-printer-uri");
4591 cupsArrayAdd(ra
, "job-state");
4592 cupsArrayAdd(ra
, "job-state-message");
4593 cupsArrayAdd(ra
, "job-state-reasons");
4594 cupsArrayAdd(ra
, "job-uri");
4595 cupsArrayAdd(ra
, "number-of-documents");
4596 cupsArrayAdd(ra
, "number-of-intervening-jobs");
4597 cupsArrayAdd(ra
, "output-device-assigned");
4598 cupsArrayAdd(ra
, "time-at-completed");
4599 cupsArrayAdd(ra
, "time-at-creation");
4600 cupsArrayAdd(ra
, "time-at-processing");
4602 else if (!strcmp(value
, "printer-description"))
4604 cupsArrayAdd(ra
, "charset-configured");
4605 cupsArrayAdd(ra
, "charset-supported");
4606 cupsArrayAdd(ra
, "color-supported");
4607 cupsArrayAdd(ra
, "compression-supported");
4608 cupsArrayAdd(ra
, "document-format-default");
4609 cupsArrayAdd(ra
, "document-format-supported");
4610 cupsArrayAdd(ra
, "generated-natural-language-supported");
4611 cupsArrayAdd(ra
, "ipp-versions-supported");
4612 cupsArrayAdd(ra
, "job-impressions-supported");
4613 cupsArrayAdd(ra
, "job-k-octets-supported");
4614 cupsArrayAdd(ra
, "job-media-sheets-supported");
4615 cupsArrayAdd(ra
, "multiple-document-jobs-supported");
4616 cupsArrayAdd(ra
, "multiple-operation-time-out");
4617 cupsArrayAdd(ra
, "natural-language-configured");
4618 cupsArrayAdd(ra
, "notify-attributes-supported");
4619 cupsArrayAdd(ra
, "notify-lease-duration-default");
4620 cupsArrayAdd(ra
, "notify-lease-duration-supported");
4621 cupsArrayAdd(ra
, "notify-max-events-supported");
4622 cupsArrayAdd(ra
, "notify-events-default");
4623 cupsArrayAdd(ra
, "notify-events-supported");
4624 cupsArrayAdd(ra
, "notify-pull-method-supported");
4625 cupsArrayAdd(ra
, "notify-schemes-supported");
4626 cupsArrayAdd(ra
, "operations-supported");
4627 cupsArrayAdd(ra
, "pages-per-minute");
4628 cupsArrayAdd(ra
, "pages-per-minute-color");
4629 cupsArrayAdd(ra
, "pdl-override-supported");
4630 cupsArrayAdd(ra
, "printer-current-time");
4631 cupsArrayAdd(ra
, "printer-driver-installer");
4632 cupsArrayAdd(ra
, "printer-info");
4633 cupsArrayAdd(ra
, "printer-is-accepting-jobs");
4634 cupsArrayAdd(ra
, "printer-location");
4635 cupsArrayAdd(ra
, "printer-make-and-model");
4636 cupsArrayAdd(ra
, "printer-message-from-operator");
4637 cupsArrayAdd(ra
, "printer-more-info");
4638 cupsArrayAdd(ra
, "printer-more-info-manufacturer");
4639 cupsArrayAdd(ra
, "printer-name");
4640 cupsArrayAdd(ra
, "printer-state");
4641 cupsArrayAdd(ra
, "printer-state-message");
4642 cupsArrayAdd(ra
, "printer-state-reasons");
4643 cupsArrayAdd(ra
, "printer-up-time");
4644 cupsArrayAdd(ra
, "printer-uri-supported");
4645 cupsArrayAdd(ra
, "queued-job-count");
4646 cupsArrayAdd(ra
, "reference-uri-schemes-supported");
4647 cupsArrayAdd(ra
, "uri-authentication-supported");
4648 cupsArrayAdd(ra
, "uri-security-supported");
4650 else if (!strcmp(value
, "subscription-template"))
4652 cupsArrayAdd(ra
, "notify-attributes");
4653 cupsArrayAdd(ra
, "notify-charset");
4654 cupsArrayAdd(ra
, "notify-events");
4655 cupsArrayAdd(ra
, "notify-lease-duration");
4656 cupsArrayAdd(ra
, "notify-natural-language");
4657 cupsArrayAdd(ra
, "notify-pull-method");
4658 cupsArrayAdd(ra
, "notify-recipient-uri");
4659 cupsArrayAdd(ra
, "notify-time-interval");
4660 cupsArrayAdd(ra
, "notify-user-data");
4663 cupsArrayAdd(ra
, value
);
4671 * 'create_subscription()' - Create a notification subscription.
4675 create_subscription(
4676 cupsd_client_t
*con
, /* I - Client connection */
4677 ipp_attribute_t
*uri
) /* I - Printer URI */
4679 http_status_t status
; /* Policy status */
4680 int i
; /* Looping var */
4681 ipp_attribute_t
*attr
; /* Current attribute */
4682 cups_ptype_t dtype
; /* Destination type (printer or class) */
4683 char scheme
[HTTP_MAX_URI
],
4684 /* Scheme portion of URI */
4685 userpass
[HTTP_MAX_URI
],
4686 /* Username portion of URI */
4688 /* Host portion of URI */
4689 resource
[HTTP_MAX_URI
];
4690 /* Resource portion of URI */
4691 int port
; /* Port portion of URI */
4692 cupsd_printer_t
*printer
; /* Printer/class */
4693 cupsd_job_t
*job
; /* Job */
4694 int jobid
; /* Job ID */
4695 cupsd_subscription_t
*sub
; /* Subscription object */
4696 const char *username
, /* requesting-user-name or authenticated username */
4697 *recipient
, /* notify-recipient-uri */
4698 *pullmethod
; /* notify-pull-method */
4699 ipp_attribute_t
*user_data
; /* notify-user-data */
4700 int interval
, /* notify-time-interval */
4701 lease
; /* notify-lease-duration */
4702 unsigned mask
; /* notify-events */
4706 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
4708 if (attr
->group_tag
!= IPP_TAG_ZERO
)
4709 cupsdLogMessage(CUPSD_LOG_DEBUG
, "g%04x v%04x %s", attr
->group_tag
,
4710 attr
->value_tag
, attr
->name
);
4712 cupsdLogMessage(CUPSD_LOG_DEBUG
, "----SEP----");
4717 * Is the destination valid?
4720 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4721 "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
4722 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
4724 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, scheme
,
4725 sizeof(scheme
), userpass
, sizeof(userpass
), host
,
4726 sizeof(host
), &port
, resource
, sizeof(resource
));
4728 if (!strcmp(resource
, "/"))
4730 dtype
= (cups_ptype_t
)0;
4733 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
4735 dtype
= (cups_ptype_t
)0;
4738 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
4740 dtype
= CUPS_PRINTER_CLASS
;
4743 else if (!cupsdValidateDest(host
, resource
, &dtype
, &printer
))
4749 send_ipp_status(con
, IPP_NOT_FOUND
,
4750 _("The printer or class was not found."));
4760 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
4762 send_http_error(con
, status
);
4766 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
4768 send_http_error(con
, status
);
4773 * Get the user that is requesting the subscription...
4776 username
= get_username(con
);
4779 * Find the first subscription group attribute; return if we have
4783 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
4784 if (attr
->group_tag
== IPP_TAG_SUBSCRIPTION
)
4789 send_ipp_status(con
, IPP_BAD_REQUEST
,
4790 _("No subscription attributes in request!"));
4795 * Process the subscription attributes in the request...
4798 con
->response
->request
.status
.status_code
= IPP_BAD_REQUEST
;
4806 lease
= DefaultLeaseDuration
;
4808 mask
= CUPSD_EVENT_NONE
;
4810 while (attr
&& attr
->group_tag
!= IPP_TAG_ZERO
)
4812 if (!strcmp(attr
->name
, "notify-recipient") &&
4813 attr
->value_tag
== IPP_TAG_URI
)
4816 * Validate the recipient scheme against the ServerBin/notifier
4820 char notifier
[1024]; /* Notifier filename */
4823 recipient
= attr
->values
[0].string
.text
;
4825 if (httpSeparateURI(HTTP_URI_CODING_ALL
, recipient
,
4826 scheme
, sizeof(scheme
), userpass
, sizeof(userpass
),
4827 host
, sizeof(host
), &port
,
4828 resource
, sizeof(resource
)) < HTTP_URI_OK
)
4830 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4831 _("Bad notify-recipient URI \"%s\"!"), recipient
);
4832 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
4833 "notify-status-code", IPP_URI_SCHEME
);
4837 snprintf(notifier
, sizeof(notifier
), "%s/notifier/%s", ServerBin
,
4839 if (access(notifier
, X_OK
))
4841 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4842 _("notify-recipient URI \"%s\" uses unknown scheme!"),
4844 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
4845 "notify-status-code", IPP_URI_SCHEME
);
4849 else if (!strcmp(attr
->name
, "notify-pull-method") &&
4850 attr
->value_tag
== IPP_TAG_KEYWORD
)
4852 pullmethod
= attr
->values
[0].string
.text
;
4854 if (strcmp(pullmethod
, "ippget"))
4856 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
4857 _("Bad notify-pull-method \"%s\"!"), pullmethod
);
4858 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_ENUM
,
4859 "notify-status-code", IPP_ATTRIBUTES
);
4863 else if (!strcmp(attr
->name
, "notify-charset") &&
4864 attr
->value_tag
== IPP_TAG_CHARSET
&&
4865 strcmp(attr
->values
[0].string
.text
, "us-ascii") &&
4866 strcmp(attr
->values
[0].string
.text
, "utf-8"))
4868 send_ipp_status(con
, IPP_CHARSET
,
4869 _("Character set \"%s\" not supported!"),
4870 attr
->values
[0].string
.text
);
4873 else if (!strcmp(attr
->name
, "notify-natural-language") &&
4874 (attr
->value_tag
!= IPP_TAG_LANGUAGE
||
4875 strcmp(attr
->values
[0].string
.text
, DefaultLanguage
)))
4877 send_ipp_status(con
, IPP_CHARSET
,
4878 _("Language \"%s\" not supported!"),
4879 attr
->values
[0].string
.text
);
4882 else if (!strcmp(attr
->name
, "notify-user-data") &&
4883 attr
->value_tag
== IPP_TAG_STRING
)
4885 if (attr
->num_values
> 1 || attr
->values
[0].unknown
.length
> 63)
4887 send_ipp_status(con
, IPP_REQUEST_VALUE
,
4888 _("The notify-user-data value is too large "
4889 "(%d > 63 octets)!"),
4890 attr
->values
[0].unknown
.length
);
4896 else if (!strcmp(attr
->name
, "notify-events") &&
4897 attr
->value_tag
== IPP_TAG_KEYWORD
)
4899 for (i
= 0; i
< attr
->num_values
; i
++)
4900 mask
|= cupsdEventValue(attr
->values
[i
].string
.text
);
4902 else if (!strcmp(attr
->name
, "notify-lease-duration") &&
4903 attr
->value_tag
== IPP_TAG_INTEGER
)
4904 lease
= attr
->values
[0].integer
;
4905 else if (!strcmp(attr
->name
, "notify-time-interval") &&
4906 attr
->value_tag
== IPP_TAG_INTEGER
)
4907 interval
= attr
->values
[0].integer
;
4908 else if (!strcmp(attr
->name
, "notify-job-id") &&
4909 attr
->value_tag
== IPP_TAG_INTEGER
)
4910 jobid
= attr
->values
[0].integer
;
4916 cupsdLogMessage(CUPSD_LOG_DEBUG
, "recipient=\"%s\"", recipient
);
4918 cupsdLogMessage(CUPSD_LOG_DEBUG
, "pullmethod=\"%s\"", pullmethod
);
4919 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-lease-duration=%d", lease
);
4920 cupsdLogMessage(CUPSD_LOG_DEBUG
, "notify-time-interval=%d", interval
);
4922 if (!recipient
&& !pullmethod
)
4925 if (mask
== CUPSD_EVENT_NONE
)
4928 mask
= CUPSD_EVENT_JOB_COMPLETED
;
4930 mask
= CUPSD_EVENT_PRINTER_STATE_CHANGED
;
4933 send_ipp_status(con
, IPP_BAD_REQUEST
,
4934 _("notify-events not specified!"));
4939 if (MaxLeaseDuration
&& (lease
== 0 || lease
> MaxLeaseDuration
))
4941 cupsdLogMessage(CUPSD_LOG_INFO
,
4942 "create_subscription: Limiting notify-lease-duration to "
4945 lease
= MaxLeaseDuration
;
4950 if ((job
= cupsdFindJob(jobid
)) == NULL
)
4952 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job %d not found!"), jobid
);
4959 sub
= cupsdAddSubscription(mask
, printer
, job
, recipient
, 0);
4962 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for job %d",
4965 cupsdLogMessage(CUPSD_LOG_DEBUG
,
4966 "Added subscription %d for printer \"%s\"",
4967 sub
->id
, printer
->name
);
4969 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Added subscription %d for server",
4972 sub
->interval
= interval
;
4974 sub
->expire
= lease
? time(NULL
) + lease
: 0;
4976 cupsdSetString(&sub
->owner
, username
);
4980 sub
->user_data_len
= user_data
->values
[0].unknown
.length
;
4981 memcpy(sub
->user_data
, user_data
->values
[0].unknown
.data
,
4982 sub
->user_data_len
);
4985 ippAddSeparator(con
->response
);
4986 ippAddInteger(con
->response
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
4987 "notify-subscription-id", sub
->id
);
4989 con
->response
->request
.status
.status_code
= IPP_OK
;
4995 cupsdSaveAllSubscriptions();
5001 * 'delete_printer()' - Remove a printer or class from the system.
5005 delete_printer(cupsd_client_t
*con
, /* I - Client connection */
5006 ipp_attribute_t
*uri
) /* I - URI of printer or class */
5008 http_status_t status
; /* Policy status */
5009 const char *dest
; /* Destination */
5010 cups_ptype_t dtype
; /* Destination type (printer or class) */
5011 char method
[HTTP_MAX_URI
], /* Method portion of URI */
5012 username
[HTTP_MAX_URI
], /* Username portion of URI */
5013 host
[HTTP_MAX_URI
], /* Host portion of URI */
5014 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5015 int port
; /* Port portion of URI */
5016 cupsd_printer_t
*printer
; /* Printer/class */
5017 char filename
[1024]; /* Script/PPD filename */
5020 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "delete_printer(%p[%d], %s)", con
,
5021 con
->http
.fd
, uri
->values
[0].string
.text
);
5024 * Do we have a valid URI?
5027 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5028 sizeof(method
), username
, sizeof(username
), host
,
5029 sizeof(host
), &port
, resource
, sizeof(resource
));
5031 if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
5037 send_ipp_status(con
, IPP_NOT_FOUND
,
5038 _("The printer or class was not found."));
5046 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5048 send_http_error(con
, status
);
5053 * Remove old jobs...
5056 cupsdCancelJobs(dest
, NULL
, 1);
5059 * Remove old subscriptions and send a "deleted printer" event...
5062 cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED
, printer
, NULL
,
5063 "%s \"%s\" deleted by \"%s\".",
5064 (dtype
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
5065 dest
, get_username(con
));
5067 cupsdExpireSubscriptions(printer
, NULL
);
5070 * Remove any old PPD or script files...
5073 snprintf(filename
, sizeof(filename
), "%s/interfaces/%s", ServerRoot
, dest
);
5076 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, dest
);
5079 if (dtype
& CUPS_PRINTER_CLASS
)
5081 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" deleted by \"%s\".", dest
,
5084 cupsdDeletePrinter(printer
, 0);
5085 cupsdSaveAllClasses();
5089 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" deleted by \"%s\".", dest
,
5092 cupsdDeletePrinter(printer
, 0);
5093 cupsdSaveAllPrinters();
5096 cupsdWritePrintcap();
5099 * Return with no errors...
5102 con
->response
->request
.status
.status_code
= IPP_OK
;
5107 * 'get_default()' - Get the default destination.
5111 get_default(cupsd_client_t
*con
) /* I - Client connection */
5113 http_status_t status
; /* Policy status */
5114 cups_array_t
*ra
; /* Requested attributes array */
5117 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_default(%p[%d])", con
, con
->http
.fd
);
5123 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5125 send_http_error(con
, status
);
5131 ra
= create_requested_array(con
->request
);
5133 copy_printer_attrs(con
, DefaultPrinter
, ra
);
5135 cupsArrayDelete(ra
);
5137 con
->response
->request
.status
.status_code
= IPP_OK
;
5140 send_ipp_status(con
, IPP_NOT_FOUND
, _("No default printer"));
5145 * 'get_devices()' - Get the list of available devices on the local system.
5149 get_devices(cupsd_client_t
*con
) /* I - Client connection */
5151 http_status_t status
; /* Policy status */
5152 ipp_attribute_t
*limit
, /* Limit attribute */
5153 *requested
; /* requested-attributes attribute */
5154 char command
[1024], /* cups-deviced command */
5155 options
[1024], /* Options to pass to command */
5157 /* String for requested attributes */
5160 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_devices(%p[%d])", con
, con
->http
.fd
);
5166 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5168 send_http_error(con
, status
);
5173 * Run cups-deviced command with the given options...
5176 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5177 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5181 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5183 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5185 snprintf(command
, sizeof(command
), "%s/daemon/cups-deviced", ServerBin
);
5186 snprintf(options
, sizeof(options
),
5188 con
->request
->request
.op
.request_id
,
5189 limit
? limit
->values
[0].integer
: 0, (int)User
,
5192 if (cupsdSendCommand(con
, command
, options
, 1))
5195 * Command started successfully, don't send an IPP response here...
5198 ippDelete(con
->response
);
5199 con
->response
= NULL
;
5204 * Command failed, return "internal error" so the user knows something
5208 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5209 _("cups-deviced failed to execute."));
5215 * 'get_job_attrs()' - Get job attributes.
5219 get_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
5220 ipp_attribute_t
*uri
) /* I - Job URI */
5222 http_status_t status
; /* Policy status */
5223 ipp_attribute_t
*attr
; /* Current attribute */
5224 int jobid
; /* Job ID */
5225 cupsd_job_t
*job
; /* Current job */
5226 char method
[HTTP_MAX_URI
], /* Method portion of URI */
5227 username
[HTTP_MAX_URI
], /* Username portion of URI */
5228 host
[HTTP_MAX_URI
], /* Host portion of URI */
5229 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5230 int port
; /* Port portion of URI */
5231 cups_array_t
*ra
; /* Requested attributes array */
5234 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_job_attrs(%p[%d], %s)", con
,
5235 con
->http
.fd
, uri
->values
[0].string
.text
);
5238 * See if we have a job URI or a printer URI...
5241 if (!strcmp(uri
->name
, "printer-uri"))
5244 * Got a printer URI; see if we also have a job-id attribute...
5247 if ((attr
= ippFindAttribute(con
->request
, "job-id",
5248 IPP_TAG_INTEGER
)) == NULL
)
5250 send_ipp_status(con
, IPP_BAD_REQUEST
,
5251 _("Got a printer-uri attribute but no job-id!"));
5255 jobid
= attr
->values
[0].integer
;
5260 * Got a job URI; parse it to get the job ID...
5263 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5264 sizeof(method
), username
, sizeof(username
), host
,
5265 sizeof(host
), &port
, resource
, sizeof(resource
));
5267 if (strncmp(resource
, "/jobs/", 6))
5273 send_ipp_status(con
, IPP_BAD_REQUEST
,
5274 _("Bad job-uri attribute \"%s\"!"),
5275 uri
->values
[0].string
.text
);
5279 jobid
= atoi(resource
+ 6);
5283 * See if the job exists...
5286 if ((job
= cupsdFindJob(jobid
)) == NULL
)
5289 * Nope - return a "not found" error...
5292 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
5300 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5302 send_http_error(con
, status
);
5307 * Copy attributes...
5312 ra
= create_requested_array(con
->request
);
5313 copy_job_attrs(con
, job
, ra
);
5314 cupsArrayDelete(ra
);
5316 con
->response
->request
.status
.status_code
= IPP_OK
;
5321 * 'get_jobs()' - Get a list of jobs for the specified printer.
5325 get_jobs(cupsd_client_t
*con
, /* I - Client connection */
5326 ipp_attribute_t
*uri
) /* I - Printer URI */
5328 http_status_t status
; /* Policy status */
5329 ipp_attribute_t
*attr
; /* Current attribute */
5330 const char *dest
; /* Destination */
5331 cups_ptype_t dtype
; /* Destination type (printer or class) */
5332 cups_ptype_t dmask
; /* Destination type mask */
5333 char method
[HTTP_MAX_URI
], /* Method portion of URI */
5334 username
[HTTP_MAX_URI
], /* Username portion of URI */
5335 host
[HTTP_MAX_URI
], /* Host portion of URI */
5336 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
5337 int port
; /* Port portion of URI */
5338 int completed
; /* Completed jobs? */
5339 int first_job_id
; /* First job ID */
5340 int limit
; /* Maximum number of jobs to return */
5341 int count
; /* Number of jobs that match */
5342 cupsd_job_t
*job
; /* Current job pointer */
5343 cupsd_printer_t
*printer
; /* Printer */
5344 cups_array_t
*list
; /* Which job list... */
5345 cups_array_t
*ra
; /* Requested attributes array */
5348 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs(%p[%d], %s)", con
, con
->http
.fd
,
5349 uri
->values
[0].string
.text
);
5352 * Is the destination valid?
5355 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5356 sizeof(method
), username
, sizeof(username
), host
,
5357 sizeof(host
), &port
, resource
, sizeof(resource
));
5359 if (!strcmp(resource
, "/") ||
5360 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6))
5363 dtype
= (cups_ptype_t
)0;
5364 dmask
= (cups_ptype_t
)0;
5367 else if (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10)
5370 dtype
= (cups_ptype_t
)0;
5371 dmask
= CUPS_PRINTER_CLASS
;
5374 else if (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9)
5377 dtype
= CUPS_PRINTER_CLASS
;
5378 dmask
= CUPS_PRINTER_CLASS
;
5381 else if ((dest
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
5387 send_ipp_status(con
, IPP_NOT_FOUND
,
5388 _("The printer or class was not found."));
5392 dmask
= CUPS_PRINTER_CLASS
;
5400 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
5402 send_http_error(con
, status
);
5406 else if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5408 send_http_error(con
, status
);
5413 * See if the "which-jobs" attribute have been specified...
5416 if ((attr
= ippFindAttribute(con
->request
, "which-jobs",
5417 IPP_TAG_KEYWORD
)) != NULL
&&
5418 !strcmp(attr
->values
[0].string
.text
, "completed"))
5423 else if (attr
&& !strcmp(attr
->values
[0].string
.text
, "all"))
5435 * See if they want to limit the number of jobs reported...
5438 if ((attr
= ippFindAttribute(con
->request
, "limit",
5439 IPP_TAG_INTEGER
)) != NULL
)
5440 limit
= attr
->values
[0].integer
;
5444 if ((attr
= ippFindAttribute(con
->request
, "first-job-id",
5445 IPP_TAG_INTEGER
)) != NULL
)
5446 first_job_id
= attr
->values
[0].integer
;
5451 * See if we only want to see jobs for a specific user...
5454 if ((attr
= ippFindAttribute(con
->request
, "my-jobs",
5455 IPP_TAG_BOOLEAN
)) != NULL
&&
5456 attr
->values
[0].boolean
)
5457 strlcpy(username
, get_username(con
), sizeof(username
));
5461 ra
= create_requested_array(con
->request
);
5464 * OK, build a list of jobs for this printer...
5467 for (count
= 0, job
= (cupsd_job_t
*)cupsArrayFirst(list
);
5468 count
< limit
&& job
;
5469 job
= (cupsd_job_t
*)cupsArrayNext(list
))
5472 * Filter out jobs that don't match...
5475 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: job->id = %d", job
->id
);
5477 if ((dest
&& strcmp(job
->dest
, dest
)) &&
5478 (!job
->printer
|| !dest
|| strcmp(job
->printer
->name
, dest
)))
5480 if ((job
->dtype
& dmask
) != dtype
&&
5481 (!job
->printer
|| (job
->printer
->type
& dmask
) != dtype
))
5483 if (username
[0] && strcasecmp(username
, job
->username
))
5486 if (completed
&& job
->state_value
<= IPP_JOB_STOPPED
)
5489 if (job
->id
< first_job_id
)
5498 ippAddSeparator(con
->response
);
5502 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_jobs: count = %d", count
);
5504 copy_job_attrs(con
, job
, ra
);
5507 cupsArrayDelete(ra
);
5509 con
->response
->request
.status
.status_code
= IPP_OK
;
5514 * 'get_notifications()' - Get events for a subscription.
5518 get_notifications(cupsd_client_t
*con
) /* I - Client connection */
5520 int i
, j
; /* Looping vars */
5521 http_status_t status
; /* Policy status */
5522 cupsd_subscription_t
*sub
; /* Subscription */
5523 ipp_attribute_t
*ids
, /* notify-subscription-ids */
5524 *sequences
; /* notify-sequence-numbers */
5525 int min_seq
; /* Minimum sequence number */
5526 int interval
; /* Poll interval */
5529 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_subscription_attrs(con=%p[%d])",
5533 * Get subscription attributes...
5536 ids
= ippFindAttribute(con
->request
, "notify-subscription-ids",
5538 sequences
= ippFindAttribute(con
->request
, "notify-sequence-numbers",
5543 send_ipp_status(con
, IPP_BAD_REQUEST
,
5544 _("Missing notify-subscription-ids attribute!"));
5549 * Are the subscription IDs valid?
5552 for (i
= 0, interval
= 60; i
< ids
->num_values
; i
++)
5554 if ((sub
= cupsdFindSubscription(ids
->values
[i
].integer
)) == NULL
)
5557 * Bad subscription ID...
5560 send_ipp_status(con
, IPP_NOT_FOUND
,
5561 _("notify-subscription-id %d no good!"),
5562 ids
->values
[i
].integer
);
5570 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
5572 con
, sub
->owner
)) != HTTP_OK
)
5574 send_http_error(con
, status
);
5579 * Check the subscription type and update the interval accordingly.
5582 if (sub
->job
&& sub
->job
->state_value
== IPP_JOB_PROCESSING
&&
5585 else if (sub
->job
&& sub
->job
->state_value
>= IPP_JOB_STOPPED
)
5587 else if (sub
->dest
&& sub
->dest
->state
== IPP_PRINTER_PROCESSING
&&
5593 * Tell the client to poll again in N seconds...
5597 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
5598 "notify-get-interval", interval
);
5600 ippAddInteger(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
5601 "printer-up-time", time(NULL
));
5604 * Copy the subscription event attributes to the response.
5607 con
->response
->request
.status
.status_code
=
5608 interval
? IPP_OK
: IPP_OK_EVENTS_COMPLETE
;
5610 for (i
= 0; i
< ids
->num_values
; i
++)
5613 * Get the subscription and sequence number...
5616 sub
= cupsdFindSubscription(ids
->values
[i
].integer
);
5618 if (sequences
&& i
< sequences
->num_values
)
5619 min_seq
= sequences
->values
[i
].integer
;
5624 * If we don't have any new events, nothing to do here...
5627 if (min_seq
> (sub
->first_event_id
+ sub
->num_events
))
5631 * Otherwise copy all of the new events...
5634 if (sub
->first_event_id
> min_seq
)
5637 j
= min_seq
- sub
->first_event_id
;
5639 for (; j
< sub
->num_events
; j
++)
5641 ippAddSeparator(con
->response
);
5643 copy_attrs(con
->response
, sub
->events
[j
]->attrs
, NULL
,
5644 IPP_TAG_EVENT_NOTIFICATION
, 0);
5651 * 'get_ppds()' - Get the list of PPD files on the local system.
5655 get_ppds(cupsd_client_t
*con
) /* I - Client connection */
5657 http_status_t status
; /* Policy status */
5658 ipp_attribute_t
*limit
, /* Limit attribute */
5659 *make
, /* ppd-make attribute */
5660 *requested
; /* requested-attributes attribute */
5661 char command
[1024], /* cups-deviced command */
5662 options
[1024], /* Options to pass to command */
5664 /* String for requested attributes */
5665 make_str
[256]; /* Escaped ppd-make string */
5668 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_ppds(%p[%d])", con
, con
->http
.fd
);
5674 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5676 send_http_error(con
, status
);
5681 * Run cups-driverd command with the given options...
5684 limit
= ippFindAttribute(con
->request
, "limit", IPP_TAG_INTEGER
);
5685 make
= ippFindAttribute(con
->request
, "ppd-make", IPP_TAG_TEXT
);
5686 requested
= ippFindAttribute(con
->request
, "requested-attributes",
5690 url_encode_attr(requested
, requested_str
, sizeof(requested_str
));
5692 strlcpy(requested_str
, "requested-attributes=all", sizeof(requested_str
));
5695 url_encode_attr(make
, make_str
, sizeof(make_str
));
5699 snprintf(command
, sizeof(command
), "%s/daemon/cups-driverd", ServerBin
);
5700 snprintf(options
, sizeof(options
), "list+%d+%d+%s%s%s",
5701 con
->request
->request
.op
.request_id
,
5702 limit
? limit
->values
[0].integer
: 0,
5703 requested_str
, make
? "%20" : "", make_str
);
5705 if (cupsdSendCommand(con
, command
, options
, 0))
5708 * Command started successfully, don't send an IPP response here...
5711 ippDelete(con
->response
);
5712 con
->response
= NULL
;
5717 * Command failed, return "internal error" so the user knows something
5721 send_ipp_status(con
, IPP_INTERNAL_ERROR
,
5722 _("cups-driverd failed to execute."));
5728 * 'get_printer_attrs()' - Get printer attributes.
5732 get_printer_attrs(cupsd_client_t
*con
, /* I - Client connection */
5733 ipp_attribute_t
*uri
) /* I - Printer URI */
5735 http_status_t status
; /* Policy status */
5736 cups_ptype_t dtype
; /* Destination type (printer or class) */
5737 char method
[HTTP_MAX_URI
],
5738 /* Method portion of URI */
5739 username
[HTTP_MAX_URI
],
5740 /* Username portion of URI */
5742 /* Host portion of URI */
5743 resource
[HTTP_MAX_URI
];
5744 /* Resource portion of URI */
5745 int port
; /* Port portion of URI */
5746 cupsd_printer_t
*printer
; /* Printer/class */
5747 cups_array_t
*ra
; /* Requested attributes array */
5750 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printer_attrs(%p[%d], %s)", con
,
5751 con
->http
.fd
, uri
->values
[0].string
.text
);
5754 * Is the destination valid?
5757 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
5758 sizeof(method
), username
, sizeof(username
), host
,
5759 sizeof(host
), &port
, resource
, sizeof(resource
));
5761 if (!cupsdValidateDest(host
, resource
, &dtype
, &printer
))
5767 send_ipp_status(con
, IPP_NOT_FOUND
,
5768 _("The printer or class was not found."));
5776 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
5778 send_http_error(con
, status
);
5783 * Send the attributes...
5786 ra
= create_requested_array(con
->request
);
5788 copy_printer_attrs(con
, printer
, ra
);
5790 cupsArrayDelete(ra
);
5792 con
->response
->request
.status
.status_code
= IPP_OK
;
5797 * 'get_printers()' - Get a list of printers or classes.
5801 get_printers(cupsd_client_t
*con
, /* I - Client connection */
5802 int type
) /* I - 0 or CUPS_PRINTER_CLASS */
5804 http_status_t status
; /* Policy status */
5805 ipp_attribute_t
*attr
; /* Current attribute */
5806 int limit
; /* Maximum number of printers to return */
5807 int count
; /* Number of printers that match */
5808 cupsd_printer_t
*printer
; /* Current printer pointer */
5809 int printer_type
, /* printer-type attribute */
5810 printer_mask
; /* printer-type-mask attribute */
5811 char *location
; /* Location string */
5812 const char *username
; /* Current user */
5813 char *first_printer_name
; /* first-printer-name attribute */
5814 cups_array_t
*ra
; /* Requested attributes array */
5817 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "get_printers(%p[%d], %x)", con
,
5818 con
->http
.fd
, type
);
5824 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
5826 send_http_error(con
, status
);
5831 * Check for printers...
5834 if (!Printers
|| !cupsArrayCount(Printers
))
5836 send_ipp_status(con
, IPP_NOT_FOUND
, _("No destinations added."));
5841 * See if they want to limit the number of printers reported...
5844 if ((attr
= ippFindAttribute(con
->request
, "limit",
5845 IPP_TAG_INTEGER
)) != NULL
)
5846 limit
= attr
->values
[0].integer
;
5850 if ((attr
= ippFindAttribute(con
->request
, "first-printer-name",
5851 IPP_TAG_NAME
)) != NULL
)
5852 first_printer_name
= attr
->values
[0].string
.text
;
5854 first_printer_name
= NULL
;
5857 * Support filtering...
5860 if ((attr
= ippFindAttribute(con
->request
, "printer-type",
5861 IPP_TAG_ENUM
)) != NULL
)
5862 printer_type
= attr
->values
[0].integer
;
5866 if ((attr
= ippFindAttribute(con
->request
, "printer-type-mask",
5867 IPP_TAG_ENUM
)) != NULL
)
5868 printer_mask
= attr
->values
[0].integer
;
5872 if ((attr
= ippFindAttribute(con
->request
, "printer-location",
5873 IPP_TAG_TEXT
)) != NULL
)
5874 location
= attr
->values
[0].string
.text
;
5878 if (con
->username
[0])
5879 username
= con
->username
;
5880 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
5881 IPP_TAG_NAME
)) != NULL
)
5882 username
= attr
->values
[0].string
.text
;
5886 ra
= create_requested_array(con
->request
);
5889 * OK, build a list of printers for this printer...
5892 if (first_printer_name
)
5894 if ((printer
= cupsdFindDest(first_printer_name
)) == NULL
)
5895 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
5898 printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
5901 count
< limit
&& printer
;
5902 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
5904 if ((!type
|| (printer
->type
& CUPS_PRINTER_CLASS
) == type
) &&
5905 (printer
->type
& printer_mask
) == printer_type
&&
5906 (!location
|| !printer
->location
||
5907 !strcasecmp(printer
->location
, location
)))
5910 * If HideImplicitMembers is enabled, see if this printer or class
5911 * is a member of an implicit class...
5914 if (ImplicitClasses
&& HideImplicitMembers
&&
5915 printer
->in_implicit_class
)
5919 * If a username is specified, see if it is allowed or denied
5923 if (printer
->num_users
&& username
&& !user_allowed(printer
, username
))
5927 * Add the group separator as needed...
5931 ippAddSeparator(con
->response
);
5936 * Send the attributes...
5939 copy_printer_attrs(con
, printer
, ra
);
5943 cupsArrayDelete(ra
);
5945 con
->response
->request
.status
.status_code
= IPP_OK
;
5950 * 'get_subscription_attrs()' - Get subscription attributes.
5954 get_subscription_attrs(
5955 cupsd_client_t
*con
, /* I - Client connection */
5956 int sub_id
) /* I - Subscription ID */
5958 http_status_t status
; /* Policy status */
5959 cupsd_subscription_t
*sub
; /* Subscription */
5960 cups_array_t
*ra
; /* Requested attributes array */
5963 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
5964 "get_subscription_attrs(con=%p[%d], sub_id=%d)",
5965 con
, con
->http
.fd
, sub_id
);
5968 * Is the subscription ID valid?
5971 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
5974 * Bad subscription ID...
5977 send_ipp_status(con
, IPP_NOT_FOUND
,
5978 _("notify-subscription-id %d no good!"), sub_id
);
5986 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
5988 con
, sub
->owner
)) != HTTP_OK
)
5990 send_http_error(con
, status
);
5995 * Copy the subscription attributes to the response using the
5996 * requested-attributes attribute that may be provided by the client.
5999 ra
= create_requested_array(con
->request
);
6001 copy_subscription_attrs(con
, sub
, ra
);
6003 cupsArrayDelete(ra
);
6005 con
->response
->request
.status
.status_code
= IPP_OK
;
6010 * 'get_subscriptions()' - Get subscriptions.
6014 get_subscriptions(cupsd_client_t
*con
, /* I - Client connection */
6015 ipp_attribute_t
*uri
) /* I - Printer/job URI */
6017 http_status_t status
; /* Policy status */
6018 int count
; /* Number of subscriptions */
6019 int limit
; /* Limit */
6020 cupsd_subscription_t
*sub
; /* Subscription */
6021 cups_array_t
*ra
; /* Requested attributes array */
6022 ipp_attribute_t
*attr
; /* Attribute */
6023 cups_ptype_t dtype
; /* Destination type (printer or class) */
6024 char method
[HTTP_MAX_URI
],
6025 /* Method portion of URI */
6026 username
[HTTP_MAX_URI
],
6027 /* Username portion of URI */
6029 /* Host portion of URI */
6030 resource
[HTTP_MAX_URI
];
6031 /* Resource portion of URI */
6032 int port
; /* Port portion of URI */
6033 cupsd_job_t
*job
; /* Job pointer */
6034 cupsd_printer_t
*printer
; /* Printer */
6037 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
6038 "get_subscriptions(con=%p[%d], uri=%s)",
6039 con
, con
->http
.fd
, uri
->values
[0].string
.text
);
6042 * Is the destination valid?
6045 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6046 sizeof(method
), username
, sizeof(username
), host
,
6047 sizeof(host
), &port
, resource
, sizeof(resource
));
6049 if (!strcmp(resource
, "/") ||
6050 (!strncmp(resource
, "/jobs", 5) && strlen(resource
) <= 6) ||
6051 (!strncmp(resource
, "/printers", 9) && strlen(resource
) <= 10) ||
6052 (!strncmp(resource
, "/classes", 8) && strlen(resource
) <= 9))
6057 else if (!strncmp(resource
, "/jobs/", 6) && resource
[6])
6060 job
= cupsdFindJob(atoi(resource
+ 6));
6064 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%s does not exist!"),
6069 else if (!cupsdValidateDest(host
, resource
, &dtype
, &printer
))
6075 send_ipp_status(con
, IPP_NOT_FOUND
,
6076 _("The printer or class was not found."));
6079 else if ((attr
= ippFindAttribute(con
->request
, "notify-job-id",
6080 IPP_TAG_INTEGER
)) != NULL
)
6082 job
= cupsdFindJob(attr
->values
[0].integer
);
6086 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"),
6087 attr
->values
[0].integer
);
6098 if ((status
= cupsdCheckPolicy(printer
? printer
->op_policy_ptr
:
6100 con
, NULL
)) != HTTP_OK
)
6102 send_http_error(con
, status
);
6107 * Copy the subscription attributes to the response using the
6108 * requested-attributes attribute that may be provided by the client.
6111 ra
= create_requested_array(con
->request
);
6113 if ((attr
= ippFindAttribute(con
->request
, "limit",
6114 IPP_TAG_INTEGER
)) != NULL
)
6115 limit
= attr
->values
[0].integer
;
6120 * See if we only want to see subscriptions for a specific user...
6123 if ((attr
= ippFindAttribute(con
->request
, "my-subscriptions",
6124 IPP_TAG_BOOLEAN
)) != NULL
&&
6125 attr
->values
[0].boolean
)
6126 strlcpy(username
, get_username(con
), sizeof(username
));
6130 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
), count
= 0;
6132 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
6133 if ((!printer
|| sub
->dest
== printer
) && (!job
|| sub
->job
== job
) &&
6134 (!username
[0] || !strcasecmp(username
, sub
->owner
)))
6136 ippAddSeparator(con
->response
);
6137 copy_subscription_attrs(con
, sub
, ra
);
6140 if (limit
&& count
>= limit
)
6144 cupsArrayDelete(ra
);
6147 con
->response
->request
.status
.status_code
= IPP_OK
;
6149 send_ipp_status(con
, IPP_NOT_FOUND
, _("No subscriptions found."));
6154 * 'get_username()' - Get the username associated with a request.
6157 static const char * /* O - Username */
6158 get_username(cupsd_client_t
*con
) /* I - Connection */
6160 ipp_attribute_t
*attr
; /* Attribute */
6163 if (con
->username
[0])
6164 return (con
->username
);
6165 else if ((attr
= ippFindAttribute(con
->request
, "requesting-user-name",
6166 IPP_TAG_NAME
)) != NULL
)
6167 return (attr
->values
[0].string
.text
);
6169 return ("anonymous");
6174 * 'hold_job()' - Hold a print job.
6178 hold_job(cupsd_client_t
*con
, /* I - Client connection */
6179 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
6181 ipp_attribute_t
*attr
, /* Current job-hold-until */
6182 *newattr
; /* New job-hold-until */
6183 int jobid
; /* Job ID */
6184 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6185 username
[HTTP_MAX_URI
], /* Username portion of URI */
6186 host
[HTTP_MAX_URI
], /* Host portion of URI */
6187 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6188 int port
; /* Port portion of URI */
6189 cupsd_job_t
*job
; /* Job information */
6192 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "hold_job(%p[%d], %s)", con
, con
->http
.fd
,
6193 uri
->values
[0].string
.text
);
6196 * See if we have a job URI or a printer URI...
6199 if (!strcmp(uri
->name
, "printer-uri"))
6202 * Got a printer URI; see if we also have a job-id attribute...
6205 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6206 IPP_TAG_INTEGER
)) == NULL
)
6208 send_ipp_status(con
, IPP_BAD_REQUEST
,
6209 _("Got a printer-uri attribute but no job-id!"));
6213 jobid
= attr
->values
[0].integer
;
6218 * Got a job URI; parse it to get the job ID...
6221 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6222 sizeof(method
), username
, sizeof(username
), host
,
6223 sizeof(host
), &port
, resource
, sizeof(resource
));
6225 if (strncmp(resource
, "/jobs/", 6))
6231 send_ipp_status(con
, IPP_BAD_REQUEST
,
6232 _("Bad job-uri attribute \"%s\"!"),
6233 uri
->values
[0].string
.text
);
6237 jobid
= atoi(resource
+ 6);
6241 * See if the job exists...
6244 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6247 * Nope - return a "not found" error...
6250 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
6255 * See if the job is owned by the requesting user...
6258 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6260 send_http_error(con
, HTTP_UNAUTHORIZED
);
6265 * Hold the job and return...
6270 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
6271 "Job held by user.");
6273 if ((newattr
= ippFindAttribute(con
->request
, "job-hold-until",
6274 IPP_TAG_KEYWORD
)) == NULL
)
6275 newattr
= ippFindAttribute(con
->request
, "job-hold-until", IPP_TAG_NAME
);
6277 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
6278 IPP_TAG_KEYWORD
)) == NULL
)
6279 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
6284 * Free the old hold value and copy the new one over...
6287 _cupsStrFree(attr
->values
[0].string
.text
);
6291 attr
->value_tag
= newattr
->value_tag
;
6292 attr
->values
[0].string
.text
=
6293 _cupsStrAlloc(newattr
->values
[0].string
.text
);
6297 attr
->value_tag
= IPP_TAG_KEYWORD
;
6298 attr
->values
[0].string
.text
= _cupsStrAlloc("indefinite");
6302 * Hold job until specified time...
6305 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
6307 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
6308 "Job job-hold-until value changed by user.");
6311 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was held by \"%s\".", jobid
,
6314 con
->response
->request
.status
.status_code
= IPP_OK
;
6319 * 'move_job()' - Move a job to a new destination.
6323 move_job(cupsd_client_t
*con
, /* I - Client connection */
6324 ipp_attribute_t
*uri
) /* I - Job URI */
6326 http_status_t status
; /* Policy status */
6327 ipp_attribute_t
*attr
; /* Current attribute */
6328 int jobid
; /* Job ID */
6329 cupsd_job_t
*job
; /* Current job */
6330 const char *src
; /* Source printer/class */
6331 cups_ptype_t stype
, /* Source type (printer or class) */
6332 dtype
; /* Destination type (printer or class) */
6333 char method
[HTTP_MAX_URI
], /* Method portion of URI */
6334 username
[HTTP_MAX_URI
], /* Username portion of URI */
6335 host
[HTTP_MAX_URI
], /* Host portion of URI */
6336 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
6337 int port
; /* Port portion of URI */
6338 cupsd_printer_t
*sprinter
, /* Source printer */
6339 *dprinter
; /* Destination printer */
6342 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "move_job(%p[%d], %s)", con
, con
->http
.fd
,
6343 uri
->values
[0].string
.text
);
6346 * Get the new printer or class...
6349 if ((attr
= ippFindAttribute(con
->request
, "job-printer-uri",
6350 IPP_TAG_URI
)) == NULL
)
6353 * Need job-printer-uri...
6356 send_ipp_status(con
, IPP_BAD_REQUEST
,
6357 _("job-printer-uri attribute missing!"));
6361 httpSeparateURI(HTTP_URI_CODING_ALL
, attr
->values
[0].string
.text
, method
,
6362 sizeof(method
), username
, sizeof(username
), host
,
6363 sizeof(host
), &port
, resource
, sizeof(resource
));
6365 if (!cupsdValidateDest(host
, resource
, &dtype
, &dprinter
))
6371 send_ipp_status(con
, IPP_NOT_FOUND
,
6372 _("The printer or class was not found."));
6380 if ((status
= cupsdCheckPolicy(dprinter
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
6382 send_http_error(con
, status
);
6387 * See if we have a job URI or a printer URI...
6390 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
6391 sizeof(method
), username
, sizeof(username
), host
,
6392 sizeof(host
), &port
, resource
, sizeof(resource
));
6394 if (!strcmp(uri
->name
, "printer-uri"))
6397 * Got a printer URI; see if we also have a job-id attribute...
6400 if ((attr
= ippFindAttribute(con
->request
, "job-id",
6401 IPP_TAG_INTEGER
)) == NULL
)
6407 if ((src
= cupsdValidateDest(host
, resource
, &stype
, &sprinter
)) == NULL
)
6413 send_ipp_status(con
, IPP_NOT_FOUND
,
6414 _("The printer or class was not found."));
6423 * Otherwise, just move a single job...
6426 if ((job
= cupsdFindJob(attr
->values
[0].integer
)) == NULL
)
6429 * Nope - return a "not found" error...
6432 send_ipp_status(con
, IPP_NOT_FOUND
,
6433 _("Job #%d does not exist!"), attr
->values
[0].integer
);
6439 * Job found, initialize source pointers...
6450 * Got a job URI; parse it to get the job ID...
6453 if (strncmp(resource
, "/jobs/", 6))
6459 send_ipp_status(con
, IPP_BAD_REQUEST
,
6460 _("Bad job-uri attribute \"%s\"!"),
6461 uri
->values
[0].string
.text
);
6466 * See if the job exists...
6469 jobid
= atoi(resource
+ 6);
6471 if ((job
= cupsdFindJob(jobid
)) == NULL
)
6474 * Nope - return a "not found" error...
6477 send_ipp_status(con
, IPP_NOT_FOUND
,
6478 _("Job #%d does not exist!"), jobid
);
6484 * Job found, initialize source pointers...
6493 * Now move the job or jobs...
6499 * See if the job has been completed...
6502 if (job
->state_value
> IPP_JOB_STOPPED
)
6505 * Return a "not-possible" error...
6508 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
6509 _("Job #%d is finished and cannot be altered!"),
6515 * See if the job is owned by the requesting user...
6518 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6520 send_http_error(con
, HTTP_UNAUTHORIZED
);
6525 * Move the job to a different printer or class...
6528 cupsdMoveJob(job
, dprinter
);
6533 * Got the source printer, now look through the jobs...
6536 for (job
= (cupsd_job_t
*)cupsArrayFirst(Jobs
);
6538 job
= (cupsd_job_t
*)cupsArrayNext(Jobs
))
6541 * See if the job is pointing at the source printer or has not been
6545 if (strcasecmp(job
->dest
, src
) ||
6546 job
->state_value
> IPP_JOB_STOPPED
)
6550 * See if the job can be moved by the requesting user...
6553 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
6557 * Move the job to a different printer or class...
6560 cupsdMoveJob(job
, dprinter
);
6565 * Start jobs if possible...
6571 * Return with "everything is OK" status...
6574 con
->response
->request
.status
.status_code
= IPP_OK
;
6579 * 'ppd_add_default()' - Add a PPD default choice.
6582 static int /* O - Number of defaults */
6584 const char *option
, /* I - Option name */
6585 const char *choice
, /* I - Choice name */
6586 int num_defaults
, /* I - Number of defaults */
6587 ppd_default_t
**defaults
) /* IO - Defaults */
6589 int i
; /* Looping var */
6590 ppd_default_t
*temp
; /* Temporary defaults array */
6594 * First check if the option already has a default value; the PPD spec
6595 * says that the first one is used...
6598 for (i
= 0, temp
= *defaults
; i
< num_defaults
; i
++)
6599 if (!strcmp(option
, temp
[i
].option
))
6600 return (num_defaults
);
6603 * Now add the option...
6606 if (num_defaults
== 0)
6607 temp
= malloc(sizeof(ppd_default_t
));
6609 temp
= realloc(*defaults
, (num_defaults
+ 1) * sizeof(ppd_default_t
));
6613 cupsdLogMessage(CUPSD_LOG_ERROR
, "ppd_add_default: Unable to add default value for \"%s\" - %s",
6614 option
, strerror(errno
));
6615 return (num_defaults
);
6619 temp
+= num_defaults
;
6621 strlcpy(temp
->option
, option
, sizeof(temp
->option
));
6622 strlcpy(temp
->choice
, choice
, sizeof(temp
->choice
));
6624 return (num_defaults
+ 1);
6629 * 'ppd_parse_line()' - Parse a PPD default line.
6632 static int /* O - 0 on success, -1 on failure */
6633 ppd_parse_line(const char *line
, /* I - Line */
6634 char *option
, /* O - Option name */
6635 int olen
, /* I - Size of option name */
6636 char *choice
, /* O - Choice name */
6637 int clen
) /* I - Size of choice name */
6640 * Verify this is a default option line...
6643 if (strncmp(line
, "*Default", 8))
6647 * Read the option name...
6650 for (line
+= 8, olen
--; isalnum(*line
& 255); line
++)
6660 * Skip everything else up to the colon (:)...
6663 while (*line
&& *line
!= ':')
6672 * Now grab the option choice, skipping leading whitespace...
6675 while (isspace(*line
& 255))
6678 for (clen
--; isalnum(*line
& 255); line
++)
6688 * Return with no errors...
6696 * 'print_job()' - Print a file to a printer or class.
6700 print_job(cupsd_client_t
*con
, /* I - Client connection */
6701 ipp_attribute_t
*uri
) /* I - Printer URI */
6703 ipp_attribute_t
*attr
; /* Current attribute */
6704 ipp_attribute_t
*format
; /* Document-format attribute */
6705 cupsd_job_t
*job
; /* New job */
6706 char filename
[1024]; /* Job filename */
6707 mime_type_t
*filetype
; /* Type of file */
6708 char super
[MIME_MAX_SUPER
], /* Supertype of file */
6709 type
[MIME_MAX_TYPE
], /* Subtype of file */
6710 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
6711 /* Textual name of mime type */
6712 cupsd_printer_t
*printer
; /* Printer data */
6713 struct stat fileinfo
; /* File information */
6714 int kbytes
; /* Size of file */
6715 int compression
; /* Document compression */
6718 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "print_job(%p[%d], %s)", con
, con
->http
.fd
,
6719 uri
->values
[0].string
.text
);
6722 * Validate print file attributes, for now just document-format and
6723 * compression (CUPS only supports "none" and "gzip")...
6726 compression
= CUPS_FILE_NONE
;
6728 if ((attr
= ippFindAttribute(con
->request
, "compression",
6729 IPP_TAG_KEYWORD
)) != NULL
)
6731 if (strcmp(attr
->values
[0].string
.text
, "none")
6733 && strcmp(attr
->values
[0].string
.text
, "gzip")
6734 #endif /* HAVE_LIBZ */
6737 send_ipp_status(con
, IPP_ATTRIBUTES
,
6738 _("Unsupported compression \"%s\"!"),
6739 attr
->values
[0].string
.text
);
6740 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
6741 "compression", NULL
, attr
->values
[0].string
.text
);
6746 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
6747 compression
= CUPS_FILE_GZIP
;
6748 #endif /* HAVE_LIBZ */
6752 * Do we have a file to print?
6757 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
6762 * Is it a format we support?
6765 if ((format
= ippFindAttribute(con
->request
, "document-format",
6766 IPP_TAG_MIMETYPE
)) != NULL
)
6769 * Grab format from client...
6772 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
6774 send_ipp_status(con
, IPP_BAD_REQUEST
,
6775 _("Could not scan type \"%s\"!"),
6776 format
->values
[0].string
.text
);
6783 * No document format attribute? Auto-type it!
6786 strcpy(super
, "application");
6787 strcpy(type
, "octet-stream");
6790 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
6793 * Auto-type the file...
6796 ipp_attribute_t
*doc_name
; /* document-name attribute */
6799 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: auto-typing file...");
6801 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
6802 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
6803 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
6809 * Replace the document-format attribute value with the auto-typed one.
6812 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
6817 _cupsStrFree(format
->values
[0].string
.text
);
6819 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
6822 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
6823 "document-format", NULL
, mimetype
);
6826 filetype
= mimeType(MimeDatabase
, super
, type
);
6829 filetype
= mimeType(MimeDatabase
, super
, type
);
6833 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
6834 _("Unsupported format \'%s/%s\'!"), super
, type
);
6835 cupsdLogMessage(CUPSD_LOG_INFO
,
6836 "Hint: Do you have the raw file printing rules enabled?");
6839 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
6840 "document-format", NULL
, format
->values
[0].string
.text
);
6845 cupsdLogMessage(CUPSD_LOG_DEBUG
, "print_job: request file type is %s/%s.",
6846 filetype
->super
, filetype
->type
);
6849 * Read any embedded job ticket info from PS files...
6852 if (!strcasecmp(filetype
->super
, "application") &&
6853 !strcasecmp(filetype
->type
, "postscript"))
6854 read_ps_job_ticket(con
);
6857 * Create the job object...
6860 if ((job
= add_job(con
, uri
, &printer
, filetype
)) == NULL
)
6864 * Update quota data...
6867 if (stat(con
->filename
, &fileinfo
))
6870 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
6872 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
6874 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
6875 IPP_TAG_INTEGER
)) != NULL
)
6876 attr
->values
[0].integer
+= kbytes
;
6879 * Add the job file...
6882 if (add_file(con
, job
, filetype
, compression
))
6885 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
6887 rename(con
->filename
, filename
);
6888 cupsdClearString(&con
->filename
);
6891 * See if we need to add the ending sheet...
6894 attr
= ippFindAttribute(job
->attrs
, "job-sheets", IPP_TAG_NAME
);
6896 if (!(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
6897 attr
&& attr
->num_values
> 1)
6903 cupsdLogMessage(CUPSD_LOG_INFO
, "Adding end banner page \"%s\" to job %d.",
6904 attr
->values
[1].string
.text
, job
->id
);
6906 kbytes
= copy_banner(con
, job
, attr
->values
[1].string
.text
);
6908 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
6912 * Log and save the job...
6915 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d queued on \"%s\" by \"%s\".", job
->id
,
6916 job
->dest
, job
->username
);
6917 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Job %d hold_until = %d", job
->id
,
6918 (int)job
->hold_until
);
6923 * Start the job if possible...
6931 * 'read_ps_job_ticket()' - Reads a job ticket embedded in a PS file.
6933 * This function only gets called when printing a single PostScript
6934 * file using the Print-Job operation. It doesn't work for Create-Job +
6935 * Send-File, since the job attributes need to be set at job creation
6936 * time for banners to work. The embedded PS job ticket stuff is here
6937 * only to allow the Windows printer driver for CUPS to pass in JCL
6938 * options and IPP attributes which otherwise would be lost.
6940 * The format of a PS job ticket is simple:
6942 * %cupsJobTicket: attr1=value1 attr2=value2 ... attrN=valueN
6944 * %cupsJobTicket: attr1=value1
6945 * %cupsJobTicket: attr2=value2
6947 * %cupsJobTicket: attrN=valueN
6949 * Job ticket lines must appear immediately after the first line that
6950 * specifies PostScript format (%!PS-Adobe-3.0), and CUPS will stop
6951 * looking for job ticket info when it finds a line that does not begin
6952 * with "%cupsJobTicket:".
6954 * The maximum length of a job ticket line, including the prefix, is
6955 * 255 characters to conform with the Adobe DSC.
6957 * Read-only attributes are rejected with a notice to the error log in
6958 * case a malicious user tries anything. Since the job ticket is read
6959 * prior to attribute validation in print_job(), job ticket attributes
6960 * will go through the same validation as IPP attributes...
6964 read_ps_job_ticket(cupsd_client_t
*con
) /* I - Client connection */
6966 cups_file_t
*fp
; /* File to read from */
6967 char line
[256]; /* Line data */
6968 int num_options
; /* Number of options */
6969 cups_option_t
*options
; /* Options */
6970 ipp_t
*ticket
; /* New attributes */
6971 ipp_attribute_t
*attr
, /* Current attribute */
6972 *attr2
, /* Job attribute */
6973 *prev2
; /* Previous job attribute */
6977 * First open the print file...
6980 if ((fp
= cupsFileOpen(con
->filename
, "rb")) == NULL
)
6982 cupsdLogMessage(CUPSD_LOG_ERROR
,
6983 "read_ps_job_ticket: Unable to open PostScript print file "
6990 * Skip the first line...
6993 if (cupsFileGets(fp
, line
, sizeof(line
)) == NULL
)
6995 cupsdLogMessage(CUPSD_LOG_ERROR
,
6996 "read_ps_job_ticket: Unable to read from PostScript print "
7003 if (strncmp(line
, "%!PS-Adobe-", 11))
7006 * Not a DSC-compliant file, so no job ticket info will be available...
7014 * Read job ticket info from the file...
7020 while (cupsFileGets(fp
, line
, sizeof(line
)))
7023 * Stop at the first non-ticket line...
7026 if (strncmp(line
, "%cupsJobTicket:", 15))
7030 * Add the options to the option array...
7033 num_options
= cupsParseOptions(line
+ 15, num_options
, &options
);
7037 * Done with the file; see if we have any options...
7042 if (num_options
== 0)
7046 * OK, convert the options to an attribute list, and apply them to
7051 cupsEncodeOptions(ticket
, num_options
, options
);
7054 * See what the user wants to change.
7057 for (attr
= ticket
->attrs
; attr
; attr
= attr
->next
)
7059 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
7062 if (!strcmp(attr
->name
, "job-originating-host-name") ||
7063 !strcmp(attr
->name
, "job-originating-user-name") ||
7064 !strcmp(attr
->name
, "job-media-sheets-completed") ||
7065 !strcmp(attr
->name
, "job-k-octets") ||
7066 !strcmp(attr
->name
, "job-id") ||
7067 !strncmp(attr
->name
, "job-state", 9) ||
7068 !strncmp(attr
->name
, "time-at-", 8))
7069 continue; /* Read-only attrs */
7071 if ((attr2
= ippFindAttribute(con
->request
, attr
->name
,
7072 IPP_TAG_ZERO
)) != NULL
)
7075 * Some other value; first free the old value...
7078 if (con
->request
->attrs
== attr2
)
7080 con
->request
->attrs
= attr2
->next
;
7085 for (prev2
= con
->request
->attrs
; prev2
; prev2
= prev2
->next
)
7086 if (prev2
->next
== attr2
)
7088 prev2
->next
= attr2
->next
;
7093 if (con
->request
->last
== attr2
)
7094 con
->request
->last
= prev2
;
7096 _ippFreeAttr(attr2
);
7100 * Add new option by copying it...
7103 copy_attribute(con
->request
, attr
, 0);
7107 * Then free the attribute list and option array...
7111 cupsFreeOptions(num_options
, options
);
7116 * 'reject_jobs()' - Reject print jobs to a printer.
7120 reject_jobs(cupsd_client_t
*con
, /* I - Client connection */
7121 ipp_attribute_t
*uri
) /* I - Printer or class URI */
7123 http_status_t status
; /* Policy status */
7124 cups_ptype_t dtype
; /* Destination type (printer or class) */
7125 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7126 username
[HTTP_MAX_URI
], /* Username portion of URI */
7127 host
[HTTP_MAX_URI
], /* Host portion of URI */
7128 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7129 int port
; /* Port portion of URI */
7130 const char *name
; /* Printer name */
7131 cupsd_printer_t
*printer
; /* Printer data */
7132 ipp_attribute_t
*attr
; /* printer-state-message text */
7135 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "reject_jobs(%p[%d], %s)", con
,
7136 con
->http
.fd
, uri
->values
[0].string
.text
);
7139 * Is the destination valid?
7142 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7143 sizeof(method
), username
, sizeof(username
), host
,
7144 sizeof(host
), &port
, resource
, sizeof(resource
));
7146 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
7152 send_ipp_status(con
, IPP_NOT_FOUND
,
7153 _("The printer or class was not found."));
7161 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
7163 send_http_error(con
, status
);
7168 * Reject jobs sent to the printer...
7171 printer
->accepting
= 0;
7173 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
7174 IPP_TAG_TEXT
)) == NULL
)
7175 strcpy(printer
->state_message
, "Rejecting Jobs");
7177 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
7178 sizeof(printer
->state_message
));
7180 cupsdAddPrinterHistory(printer
);
7182 if (dtype
& CUPS_PRINTER_CLASS
)
7184 cupsdSaveAllClasses();
7186 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" rejecting jobs (\"%s\").",
7187 name
, get_username(con
));
7191 cupsdSaveAllPrinters();
7193 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" rejecting jobs (\"%s\").",
7194 name
, get_username(con
));
7198 * Everything was ok, so return OK status...
7201 con
->response
->request
.status
.status_code
= IPP_OK
;
7206 * 'release_job()' - Release a held print job.
7210 release_job(cupsd_client_t
*con
, /* I - Client connection */
7211 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7213 ipp_attribute_t
*attr
; /* Current attribute */
7214 int jobid
; /* Job ID */
7215 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7216 username
[HTTP_MAX_URI
], /* Username portion of URI */
7217 host
[HTTP_MAX_URI
], /* Host portion of URI */
7218 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7219 int port
; /* Port portion of URI */
7220 cupsd_job_t
*job
; /* Job information */
7223 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "release_job(%p[%d], %s)", con
,
7224 con
->http
.fd
, uri
->values
[0].string
.text
);
7227 * See if we have a job URI or a printer URI...
7230 if (!strcmp(uri
->name
, "printer-uri"))
7233 * Got a printer URI; see if we also have a job-id attribute...
7236 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7237 IPP_TAG_INTEGER
)) == NULL
)
7239 send_ipp_status(con
, IPP_BAD_REQUEST
,
7240 _("Got a printer-uri attribute but no job-id!"));
7244 jobid
= attr
->values
[0].integer
;
7249 * Got a job URI; parse it to get the job ID...
7252 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7253 sizeof(method
), username
, sizeof(username
), host
,
7254 sizeof(host
), &port
, resource
, sizeof(resource
));
7256 if (strncmp(resource
, "/jobs/", 6))
7262 send_ipp_status(con
, IPP_BAD_REQUEST
,
7263 _("Bad job-uri attribute \"%s\"!"),
7264 uri
->values
[0].string
.text
);
7268 jobid
= atoi(resource
+ 6);
7272 * See if the job exists...
7275 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7278 * Nope - return a "not found" error...
7281 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7286 * See if job is "held"...
7289 if (job
->state_value
!= IPP_JOB_HELD
)
7292 * Nope - return a "not possible" error...
7295 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not held!"), jobid
);
7300 * See if the job is owned by the requesting user...
7303 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7305 send_http_error(con
, HTTP_UNAUTHORIZED
);
7310 * Reset the job-hold-until value to "no-hold"...
7313 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7314 IPP_TAG_KEYWORD
)) == NULL
)
7315 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7319 _cupsStrFree(attr
->values
[0].string
.text
);
7321 attr
->value_tag
= IPP_TAG_KEYWORD
;
7322 attr
->values
[0].string
.text
= _cupsStrAlloc("no-hold");
7324 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
7325 "Job job-hold-until value changed by user.");
7329 * Release the job and return...
7332 cupsdReleaseJob(job
);
7334 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
7335 "Job released by user.");
7337 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was released by \"%s\".", jobid
,
7340 con
->response
->request
.status
.status_code
= IPP_OK
;
7345 * 'renew_subscription()' - Renew an existing subscription...
7350 cupsd_client_t
*con
, /* I - Client connection */
7351 int sub_id
) /* I - Subscription ID */
7353 http_status_t status
; /* Policy status */
7354 cupsd_subscription_t
*sub
; /* Subscription */
7355 ipp_attribute_t
*lease
; /* notify-lease-duration */
7358 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
7359 "renew_subscription(con=%p[%d], sub_id=%d)",
7360 con
, con
->http
.fd
, sub_id
);
7363 * Is the subscription ID valid?
7366 if ((sub
= cupsdFindSubscription(sub_id
)) == NULL
)
7369 * Bad subscription ID...
7372 send_ipp_status(con
, IPP_NOT_FOUND
,
7373 _("notify-subscription-id %d no good!"), sub_id
);
7380 * Job subscriptions cannot be renewed...
7383 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7384 _("Job subscriptions cannot be renewed!"));
7392 if ((status
= cupsdCheckPolicy(sub
->dest
? sub
->dest
->op_policy_ptr
:
7394 con
, sub
->owner
)) != HTTP_OK
)
7396 send_http_error(con
, status
);
7401 * Renew the subscription...
7404 lease
= ippFindAttribute(con
->request
, "notify-lease-duration",
7407 sub
->lease
= lease
? lease
->values
[0].integer
: DefaultLeaseDuration
;
7409 if (MaxLeaseDuration
&& (sub
->lease
== 0 || sub
->lease
> MaxLeaseDuration
))
7411 cupsdLogMessage(CUPSD_LOG_INFO
,
7412 "renew_subscription: Limiting notify-lease-duration to "
7415 sub
->lease
= MaxLeaseDuration
;
7418 sub
->expire
= sub
->lease
? time(NULL
) + sub
->lease
: 0;
7420 cupsdSaveAllSubscriptions();
7422 con
->response
->request
.status
.status_code
= IPP_OK
;
7427 * 'restart_job()' - Restart an old print job.
7431 restart_job(cupsd_client_t
*con
, /* I - Client connection */
7432 ipp_attribute_t
*uri
) /* I - Job or Printer URI */
7434 ipp_attribute_t
*attr
; /* Current attribute */
7435 int jobid
; /* Job ID */
7436 char method
[HTTP_MAX_URI
], /* Method portion of URI */
7437 username
[HTTP_MAX_URI
], /* Username portion of URI */
7438 host
[HTTP_MAX_URI
], /* Host portion of URI */
7439 resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
7440 int port
; /* Port portion of URI */
7441 cupsd_job_t
*job
; /* Job information */
7444 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "restart_job(%p[%d], %s)", con
,
7445 con
->http
.fd
, uri
->values
[0].string
.text
);
7448 * See if we have a job URI or a printer URI...
7451 if (!strcmp(uri
->name
, "printer-uri"))
7454 * Got a printer URI; see if we also have a job-id attribute...
7457 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7458 IPP_TAG_INTEGER
)) == NULL
)
7460 send_ipp_status(con
, IPP_BAD_REQUEST
,
7461 _("Got a printer-uri attribute but no job-id!"));
7465 jobid
= attr
->values
[0].integer
;
7470 * Got a job URI; parse it to get the job ID...
7473 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7474 sizeof(method
), username
, sizeof(username
), host
,
7475 sizeof(host
), &port
, resource
, sizeof(resource
));
7477 if (strncmp(resource
, "/jobs/", 6))
7483 send_ipp_status(con
, IPP_BAD_REQUEST
,
7484 _("Bad job-uri attribute \"%s\"!"),
7485 uri
->values
[0].string
.text
);
7489 jobid
= atoi(resource
+ 6);
7493 * See if the job exists...
7496 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7499 * Nope - return a "not found" error...
7502 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7507 * See if job is in any of the "completed" states...
7510 if (job
->state_value
<= IPP_JOB_PROCESSING
)
7513 * Nope - return a "not possible" error...
7516 send_ipp_status(con
, IPP_NOT_POSSIBLE
, _("Job #%d is not complete!"),
7522 * See if we have retained the job files...
7527 if (!job
->attrs
|| job
->num_files
== 0)
7530 * Nope - return a "not possible" error...
7533 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
7534 _("Job #%d cannot be restarted - no files!"), jobid
);
7539 * See if the job is owned by the requesting user...
7542 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7544 send_http_error(con
, HTTP_UNAUTHORIZED
);
7549 * Restart the job and return...
7552 cupsdRestartJob(job
);
7554 cupsdLogMessage(CUPSD_LOG_INFO
, "Job %d was restarted by \"%s\".", jobid
,
7557 con
->response
->request
.status
.status_code
= IPP_OK
;
7562 * 'save_auth_info()' - Save authentication information for a job.
7566 save_auth_info(cupsd_client_t
*con
, /* I - Client connection */
7567 cupsd_job_t
*job
) /* I - Job */
7569 int i
; /* Looping var */
7570 char filename
[1024]; /* Job authentication filename */
7571 cups_file_t
*fp
; /* Job authentication file */
7572 char line
[1024]; /* Line for file */
7576 * This function saves the in-memory authentication information for
7577 * a job so that it can be used to authenticate with a remote host.
7578 * The information is stored in a file that is readable only by the
7579 * root user. The username and password are Base-64 encoded, each
7580 * on a separate line, followed by random number (up to 1024) of
7581 * newlines to limit the amount of information that is exposed.
7583 * Because of the potential for exposing of authentication information,
7584 * this functionality is only enabled when running cupsd as root.
7586 * This caching only works for the Basic and BasicDigest authentication
7587 * types. Digest authentication cannot be cached this way, and in
7588 * the future Kerberos authentication may make all of this obsolete.
7590 * Authentication information is saved whenever an authenticated
7591 * Print-Job, Create-Job, or CUPS-Authenticate-Job operation is
7594 * This information is deleted after a job is completed or canceled,
7595 * so reprints may require subsequent re-authentication.
7602 * Create the authentication file and change permissions...
7605 snprintf(filename
, sizeof(filename
), "%s/a%05d", RequestRoot
, job
->id
);
7606 if ((fp
= cupsFileOpen(filename
, "w")) == NULL
)
7608 cupsdLogMessage(CUPSD_LOG_ERROR
,
7609 "Unable to save authentication info to \"%s\" - %s",
7610 filename
, strerror(errno
));
7614 fchown(cupsFileNumber(fp
), 0, 0);
7615 fchmod(cupsFileNumber(fp
), 0400);
7618 * Write the authenticated username...
7621 httpEncode64_2(line
, sizeof(line
), con
->username
, strlen(con
->username
));
7622 cupsFilePrintf(fp
, "%s\n", line
);
7625 * Write the authenticated password...
7628 httpEncode64_2(line
, sizeof(line
), con
->password
, strlen(con
->password
));
7629 cupsFilePrintf(fp
, "%s\n", line
);
7632 * Write a random number of newlines to the end of the file...
7635 for (i
= (rand() % 1024); i
>= 0; i
--)
7636 cupsFilePutChar(fp
, '\n');
7639 * Close the file and return...
7647 * 'send_document()' - Send a file to a printer or class.
7651 send_document(cupsd_client_t
*con
, /* I - Client connection */
7652 ipp_attribute_t
*uri
) /* I - Printer URI */
7654 ipp_attribute_t
*attr
; /* Current attribute */
7655 ipp_attribute_t
*format
; /* Document-format attribute */
7656 int jobid
; /* Job ID number */
7657 cupsd_job_t
*job
; /* Current job */
7658 char job_uri
[HTTP_MAX_URI
],
7660 method
[HTTP_MAX_URI
],
7661 /* Method portion of URI */
7662 username
[HTTP_MAX_URI
],
7663 /* Username portion of URI */
7665 /* Host portion of URI */
7666 resource
[HTTP_MAX_URI
];
7667 /* Resource portion of URI */
7668 int port
; /* Port portion of URI */
7669 mime_type_t
*filetype
; /* Type of file */
7670 char super
[MIME_MAX_SUPER
],
7671 /* Supertype of file */
7672 type
[MIME_MAX_TYPE
],
7673 /* Subtype of file */
7674 mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
7675 /* Textual name of mime type */
7676 char filename
[1024]; /* Job filename */
7677 cupsd_printer_t
*printer
; /* Current printer */
7678 struct stat fileinfo
; /* File information */
7679 int kbytes
; /* Size of file */
7680 int compression
; /* Type of compression */
7683 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "send_document(%p[%d], %s)", con
,
7684 con
->http
.fd
, uri
->values
[0].string
.text
);
7687 * See if we have a job URI or a printer URI...
7690 if (!strcmp(uri
->name
, "printer-uri"))
7693 * Got a printer URI; see if we also have a job-id attribute...
7696 if ((attr
= ippFindAttribute(con
->request
, "job-id",
7697 IPP_TAG_INTEGER
)) == NULL
)
7699 send_ipp_status(con
, IPP_BAD_REQUEST
,
7700 _("Got a printer-uri attribute but no job-id!"));
7704 jobid
= attr
->values
[0].integer
;
7709 * Got a job URI; parse it to get the job ID...
7712 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
7713 sizeof(method
), username
, sizeof(username
), host
,
7714 sizeof(host
), &port
, resource
, sizeof(resource
));
7716 if (strncmp(resource
, "/jobs/", 6))
7722 send_ipp_status(con
, IPP_BAD_REQUEST
,
7723 _("Bad job-uri attribute \"%s\"!"),
7724 uri
->values
[0].string
.text
);
7728 jobid
= atoi(resource
+ 6);
7732 * See if the job exists...
7735 if ((job
= cupsdFindJob(jobid
)) == NULL
)
7738 * Nope - return a "not found" error...
7741 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
7745 printer
= cupsdFindDest(job
->dest
);
7748 * See if the job is owned by the requesting user...
7751 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
7753 send_http_error(con
, HTTP_UNAUTHORIZED
);
7758 * OK, see if the client is sending the document compressed - CUPS
7759 * only supports "none" and "gzip".
7762 compression
= CUPS_FILE_NONE
;
7764 if ((attr
= ippFindAttribute(con
->request
, "compression",
7765 IPP_TAG_KEYWORD
)) != NULL
)
7767 if (strcmp(attr
->values
[0].string
.text
, "none")
7769 && strcmp(attr
->values
[0].string
.text
, "gzip")
7770 #endif /* HAVE_LIBZ */
7773 send_ipp_status(con
, IPP_ATTRIBUTES
, _("Unsupported compression \"%s\"!"),
7774 attr
->values
[0].string
.text
);
7775 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
7776 "compression", NULL
, attr
->values
[0].string
.text
);
7781 if (!strcmp(attr
->values
[0].string
.text
, "gzip"))
7782 compression
= CUPS_FILE_GZIP
;
7783 #endif /* HAVE_LIBZ */
7787 * Do we have a file to print?
7792 send_ipp_status(con
, IPP_BAD_REQUEST
, _("No file!?!"));
7797 * Is it a format we support?
7800 if ((format
= ippFindAttribute(con
->request
, "document-format",
7801 IPP_TAG_MIMETYPE
)) != NULL
)
7804 * Grab format from client...
7807 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
7809 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
7810 format
->values
[0].string
.text
);
7817 * No document format attribute? Auto-type it!
7820 strcpy(super
, "application");
7821 strcpy(type
, "octet-stream");
7824 if (!strcmp(super
, "application") && !strcmp(type
, "octet-stream"))
7827 * Auto-type the file...
7830 ipp_attribute_t
*doc_name
; /* document-name attribute */
7833 cupsdLogMessage(CUPSD_LOG_DEBUG
, "send_document: auto-typing file...");
7835 doc_name
= ippFindAttribute(con
->request
, "document-name", IPP_TAG_NAME
);
7836 filetype
= mimeFileType(MimeDatabase
, con
->filename
,
7837 doc_name
? doc_name
->values
[0].string
.text
: NULL
,
7843 * Replace the document-format attribute value with the auto-typed one.
7846 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
7851 _cupsStrFree(format
->values
[0].string
.text
);
7852 format
->values
[0].string
.text
= _cupsStrAlloc(mimetype
);
7855 ippAddString(con
->request
, IPP_TAG_JOB
, IPP_TAG_MIMETYPE
,
7856 "document-format", NULL
, mimetype
);
7859 filetype
= mimeType(MimeDatabase
, super
, type
);
7862 filetype
= mimeType(MimeDatabase
, super
, type
);
7866 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
7867 _("Unsupported format \'%s/%s\'!"), super
, type
);
7868 cupsdLogMessage(CUPSD_LOG_INFO
,
7869 "Hint: Do you have the raw file printing rules enabled?");
7872 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
7873 "document-format", NULL
, format
->values
[0].string
.text
);
7878 if (printer
->filetypes
&& !cupsArrayFind(printer
->filetypes
, filetype
))
7880 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", filetype
->super
,
7883 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
7884 _("Unsupported format \'%s\'!"), mimetype
);
7886 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
7887 "document-format", NULL
, mimetype
);
7892 cupsdLogMessage(CUPSD_LOG_DEBUG
,
7893 "send_document: request file type is %s/%s.",
7894 filetype
->super
, filetype
->type
);
7897 * Add the file to the job...
7902 if (add_file(con
, job
, filetype
, compression
))
7905 if (stat(con
->filename
, &fileinfo
))
7908 kbytes
= (fileinfo
.st_size
+ 1023) / 1024;
7910 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
7912 if ((attr
= ippFindAttribute(job
->attrs
, "job-k-octets",
7913 IPP_TAG_INTEGER
)) != NULL
)
7914 attr
->values
[0].integer
+= kbytes
;
7916 snprintf(filename
, sizeof(filename
), "%s/d%05d-%03d", RequestRoot
, job
->id
,
7918 rename(con
->filename
, filename
);
7920 cupsdClearString(&con
->filename
);
7922 cupsdLogMessage(CUPSD_LOG_INFO
,
7923 "File of type %s/%s queued in job #%d by \"%s\".",
7924 filetype
->super
, filetype
->type
, job
->id
, job
->username
);
7927 * Start the job if this is the last document...
7930 if ((attr
= ippFindAttribute(con
->request
, "last-document",
7931 IPP_TAG_BOOLEAN
)) != NULL
&&
7932 attr
->values
[0].boolean
)
7935 * See if we need to add the ending sheet...
7939 !(printer
->type
& (CUPS_PRINTER_REMOTE
| CUPS_PRINTER_IMPLICIT
)) &&
7940 (attr
= ippFindAttribute(job
->attrs
, "job-sheets",
7941 IPP_TAG_ZERO
)) != NULL
&&
7942 attr
->num_values
> 1)
7948 cupsdLogMessage(CUPSD_LOG_INFO
,
7949 "Adding end banner page \"%s\" to job %d.",
7950 attr
->values
[1].string
.text
, job
->id
);
7952 kbytes
= copy_banner(con
, job
, attr
->values
[1].string
.text
);
7954 cupsdUpdateQuota(printer
, job
->username
, 0, kbytes
);
7957 if (job
->state_value
== IPP_JOB_STOPPED
)
7959 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
7960 job
->state_value
= IPP_JOB_PENDING
;
7962 else if (job
->state_value
== IPP_JOB_HELD
)
7964 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7965 IPP_TAG_KEYWORD
)) == NULL
)
7966 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7968 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
7970 job
->state
->values
[0].integer
= IPP_JOB_PENDING
;
7971 job
->state_value
= IPP_JOB_PENDING
;
7978 * Start the job if possible... Since cupsdCheckJobs() can cancel a
7979 * job if it doesn't print, we need to re-find the job afterwards...
7986 job
= cupsdFindJob(jobid
);
7990 if ((attr
= ippFindAttribute(job
->attrs
, "job-hold-until",
7991 IPP_TAG_KEYWORD
)) == NULL
)
7992 attr
= ippFindAttribute(job
->attrs
, "job-hold-until", IPP_TAG_NAME
);
7994 if (!attr
|| !strcmp(attr
->values
[0].string
.text
, "no-hold"))
7996 job
->state
->values
[0].integer
= IPP_JOB_HELD
;
7997 job
->state_value
= IPP_JOB_HELD
;
7998 job
->hold_until
= time(NULL
) + 60;
8004 * Fill in the response info...
8007 snprintf(job_uri
, sizeof(job_uri
), "http://%s:%d/jobs/%d", ServerName
,
8010 ippAddString(con
->response
, IPP_TAG_JOB
, IPP_TAG_URI
, "job-uri", NULL
,
8013 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_INTEGER
, "job-id", jobid
);
8015 ippAddInteger(con
->response
, IPP_TAG_JOB
, IPP_TAG_ENUM
, "job-state",
8016 job
? job
->state_value
: IPP_JOB_CANCELED
);
8017 add_job_state_reasons(con
, job
);
8019 con
->response
->request
.status
.status_code
= IPP_OK
;
8024 * 'send_http_error()' - Send a HTTP error back to the IPP client.
8028 send_http_error(cupsd_client_t
*con
, /* I - Client connection */
8029 http_status_t status
) /* I - HTTP status code */
8031 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s",
8032 ippOpString(con
->request
->request
.op
.operation_id
),
8033 httpStatus(status
));
8035 cupsdSendError(con
, status
);
8037 ippDelete(con
->response
);
8038 con
->response
= NULL
;
8045 * 'send_ipp_status()' - Send a status back to the IPP client.
8049 send_ipp_status(cupsd_client_t
*con
, /* I - Client connection */
8050 ipp_status_t status
, /* I - IPP status code */
8051 const char *message
, /* I - Status message */
8052 ...) /* I - Additional args as needed */
8054 va_list ap
; /* Pointer to additional args */
8055 char formatted
[1024]; /* Formatted errror message */
8060 va_start(ap
, message
);
8061 vsnprintf(formatted
, sizeof(formatted
),
8062 _cupsLangString(con
->language
, message
), ap
);
8065 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s: %s",
8066 ippOpString(con
->request
->request
.op
.operation_id
),
8067 ippErrorString(status
), formatted
);
8070 cupsdLogMessage(CUPSD_LOG_DEBUG
, "%s %s",
8071 ippOpString(con
->request
->request
.op
.operation_id
),
8072 ippErrorString(status
));
8074 con
->response
->request
.status
.status_code
= status
;
8076 if (ippFindAttribute(con
->response
, "attributes-charset",
8077 IPP_TAG_ZERO
) == NULL
)
8078 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
8079 "attributes-charset", NULL
, DefaultCharset
);
8081 if (ippFindAttribute(con
->response
, "attributes-natural-language",
8082 IPP_TAG_ZERO
) == NULL
)
8083 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
8084 "attributes-natural-language", NULL
, DefaultLanguage
);
8087 ippAddString(con
->response
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
8088 "status-message", NULL
, formatted
);
8093 * 'set_default()' - Set the default destination...
8097 set_default(cupsd_client_t
*con
, /* I - Client connection */
8098 ipp_attribute_t
*uri
) /* I - Printer URI */
8100 http_status_t status
; /* Policy status */
8101 cups_ptype_t dtype
; /* Destination type (printer or class) */
8102 char method
[HTTP_MAX_URI
],
8103 /* Method portion of URI */
8104 username
[HTTP_MAX_URI
],
8105 /* Username portion of URI */
8107 /* Host portion of URI */
8108 resource
[HTTP_MAX_URI
];
8109 /* Resource portion of URI */
8110 int port
; /* Port portion of URI */
8111 const char *name
; /* Printer name */
8112 cupsd_printer_t
*printer
; /* Printer */
8115 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_default(%p[%d], %s)", con
,
8116 con
->http
.fd
, uri
->values
[0].string
.text
);
8119 * Is the destination valid?
8122 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8123 sizeof(method
), username
, sizeof(username
), host
,
8124 sizeof(host
), &port
, resource
, sizeof(resource
));
8126 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
8132 send_ipp_status(con
, IPP_NOT_FOUND
,
8133 _("The printer or class was not found."));
8141 if ((status
= cupsdCheckPolicy(DefaultPolicyPtr
, con
, NULL
)) != HTTP_OK
)
8143 send_http_error(con
, status
);
8148 * Set it as the default...
8151 DefaultPrinter
= printer
;
8153 cupsdSaveAllPrinters();
8154 cupsdSaveAllClasses();
8156 cupsdWritePrintcap();
8158 cupsdLogMessage(CUPSD_LOG_INFO
,
8159 "Default destination set to \"%s\" by \"%s\".", name
,
8163 * Everything was ok, so return OK status...
8166 con
->response
->request
.status
.status_code
= IPP_OK
;
8171 * 'set_job_attrs()' - Set job attributes.
8175 set_job_attrs(cupsd_client_t
*con
, /* I - Client connection */
8176 ipp_attribute_t
*uri
) /* I - Job URI */
8178 ipp_attribute_t
*attr
, /* Current attribute */
8179 *attr2
; /* Job attribute */
8180 int jobid
; /* Job ID */
8181 cupsd_job_t
*job
; /* Current job */
8182 char method
[HTTP_MAX_URI
],
8183 /* Method portion of URI */
8184 username
[HTTP_MAX_URI
],
8185 /* Username portion of URI */
8187 /* Host portion of URI */
8188 resource
[HTTP_MAX_URI
];
8189 /* Resource portion of URI */
8190 int port
; /* Port portion of URI */
8191 int event
; /* Events? */
8194 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_job_attrs(%p[%d], %s)", con
,
8195 con
->http
.fd
, uri
->values
[0].string
.text
);
8198 * Start with "everything is OK" status...
8201 con
->response
->request
.status
.status_code
= IPP_OK
;
8204 * See if we have a job URI or a printer URI...
8207 if (!strcmp(uri
->name
, "printer-uri"))
8210 * Got a printer URI; see if we also have a job-id attribute...
8213 if ((attr
= ippFindAttribute(con
->request
, "job-id",
8214 IPP_TAG_INTEGER
)) == NULL
)
8216 send_ipp_status(con
, IPP_BAD_REQUEST
,
8217 _("Got a printer-uri attribute but no job-id!"));
8221 jobid
= attr
->values
[0].integer
;
8226 * Got a job URI; parse it to get the job ID...
8229 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8230 sizeof(method
), username
, sizeof(username
), host
,
8231 sizeof(host
), &port
, resource
, sizeof(resource
));
8233 if (strncmp(resource
, "/jobs/", 6))
8239 send_ipp_status(con
, IPP_BAD_REQUEST
,
8240 _("Bad job-uri attribute \"%s\"!"),
8241 uri
->values
[0].string
.text
);
8245 jobid
= atoi(resource
+ 6);
8249 * See if the job exists...
8252 if ((job
= cupsdFindJob(jobid
)) == NULL
)
8255 * Nope - return a "not found" error...
8258 send_ipp_status(con
, IPP_NOT_FOUND
, _("Job #%d does not exist!"), jobid
);
8263 * See if the job has been completed...
8266 if (job
->state_value
> IPP_JOB_STOPPED
)
8269 * Return a "not-possible" error...
8272 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8273 _("Job #%d is finished and cannot be altered!"), jobid
);
8278 * See if the job is owned by the requesting user...
8281 if (!validate_user(job
, con
, job
->username
, username
, sizeof(username
)))
8283 send_http_error(con
, HTTP_UNAUTHORIZED
);
8288 * See what the user wants to change.
8295 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
8297 if (attr
->group_tag
!= IPP_TAG_JOB
|| !attr
->name
)
8300 if (!strcmp(attr
->name
, "attributes-charset") ||
8301 !strcmp(attr
->name
, "attributes-natural-language") ||
8302 !strcmp(attr
->name
, "document-compression") ||
8303 !strcmp(attr
->name
, "document-format") ||
8304 !strcmp(attr
->name
, "job-detailed-status-messages") ||
8305 !strcmp(attr
->name
, "job-document-access-errors") ||
8306 !strcmp(attr
->name
, "job-id") ||
8307 !strcmp(attr
->name
, "job-k-octets") ||
8308 !strcmp(attr
->name
, "job-originating-host-name") ||
8309 !strcmp(attr
->name
, "job-originating-user-name") ||
8310 !strcmp(attr
->name
, "job-printer-up-time") ||
8311 !strcmp(attr
->name
, "job-printer-uri") ||
8312 !strcmp(attr
->name
, "job-sheets") ||
8313 !strcmp(attr
->name
, "job-state-message") ||
8314 !strcmp(attr
->name
, "job-state-reasons") ||
8315 !strcmp(attr
->name
, "job-uri") ||
8316 !strcmp(attr
->name
, "number-of-documents") ||
8317 !strcmp(attr
->name
, "number-of-intervening-jobs") ||
8318 !strcmp(attr
->name
, "output-device-assigned") ||
8319 !strncmp(attr
->name
, "date-time-at-", 13) ||
8320 !strncmp(attr
->name
, "job-impressions", 15) ||
8321 !strncmp(attr
->name
, "job-k-octets", 12) ||
8322 !strncmp(attr
->name
, "job-media-sheets", 16) ||
8323 !strncmp(attr
->name
, "time-at-", 8))
8329 send_ipp_status(con
, IPP_ATTRIBUTES_NOT_SETTABLE
,
8330 _("%s cannot be changed."), attr
->name
);
8332 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8333 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8338 if (!strcmp(attr
->name
, "job-priority"))
8341 * Change the job priority...
8344 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8346 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-priority value!"));
8348 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8349 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8351 else if (job
->state_value
>= IPP_JOB_PROCESSING
)
8353 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8354 _("Job is completed and cannot be changed."));
8357 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8359 cupsdSetJobPriority(job
, attr
->values
[0].integer
);
8360 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8363 else if (!strcmp(attr
->name
, "job-state"))
8366 * Change the job state...
8369 if (attr
->value_tag
!= IPP_TAG_ENUM
)
8371 send_ipp_status(con
, IPP_REQUEST_VALUE
, _("Bad job-state value!"));
8373 if ((attr2
= copy_attribute(con
->response
, attr
, 0)) != NULL
)
8374 attr2
->group_tag
= IPP_TAG_UNSUPPORTED_GROUP
;
8378 switch (attr
->values
[0].integer
)
8380 case IPP_JOB_PENDING
:
8382 if (job
->state_value
> IPP_JOB_HELD
)
8384 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8385 _("Job state cannot be changed."));
8388 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8390 job
->state
->values
[0].integer
= attr
->values
[0].integer
;
8391 job
->state_value
= (ipp_jstate_t
)attr
->values
[0].integer
;
8393 event
|= CUPSD_EVENT_JOB_STATE
;
8397 case IPP_JOB_PROCESSING
:
8398 case IPP_JOB_STOPPED
:
8399 if (job
->state_value
!= attr
->values
[0].integer
)
8401 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8402 _("Job state cannot be changed."));
8407 case IPP_JOB_CANCELED
:
8408 case IPP_JOB_ABORTED
:
8409 case IPP_JOB_COMPLETED
:
8410 if (job
->state_value
> IPP_JOB_PROCESSING
)
8412 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8413 _("Job state cannot be changed."));
8416 else if (con
->response
->request
.status
.status_code
== IPP_OK
)
8417 cupsdCancelJob(job
, 0, (ipp_jstate_t
)attr
->values
[0].integer
);
8422 else if (con
->response
->request
.status
.status_code
!= IPP_OK
)
8424 else if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
8425 IPP_TAG_ZERO
)) != NULL
)
8428 * Some other value; first free the old value...
8431 if (job
->attrs
->prev
)
8432 job
->attrs
->prev
->next
= attr2
->next
;
8434 job
->attrs
->attrs
= attr2
->next
;
8436 if (job
->attrs
->last
== attr2
)
8437 job
->attrs
->last
= job
->attrs
->prev
;
8439 _ippFreeAttr(attr2
);
8442 * Then copy the attribute...
8445 copy_attribute(job
->attrs
, attr
, 0);
8448 * See if the job-name or job-hold-until is being changed.
8451 if (!strcmp(attr
->name
, "job-hold-until"))
8453 cupsdSetJobHoldUntil(job
, attr
->values
[0].string
.text
);
8455 if (!strcmp(attr
->values
[0].string
.text
, "no-hold"))
8456 cupsdReleaseJob(job
);
8460 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
| CUPSD_EVENT_JOB_STATE
;
8463 else if (attr
->value_tag
== IPP_TAG_DELETEATTR
)
8466 * Delete the attribute...
8469 if ((attr2
= ippFindAttribute(job
->attrs
, attr
->name
,
8470 IPP_TAG_ZERO
)) != NULL
)
8472 if (job
->attrs
->prev
)
8473 job
->attrs
->prev
->next
= attr2
->next
;
8475 job
->attrs
->attrs
= attr2
->next
;
8477 if (attr2
== job
->attrs
->last
)
8478 job
->attrs
->last
= job
->attrs
->prev
;
8480 _ippFreeAttr(attr2
);
8482 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8488 * Add new option by copying it...
8491 copy_attribute(job
->attrs
, attr
, 0);
8493 event
|= CUPSD_EVENT_JOB_CONFIG_CHANGED
;
8504 * Send events as needed...
8507 if (event
& CUPSD_EVENT_JOB_STATE
)
8508 cupsdAddEvent(CUPSD_EVENT_JOB_STATE
, job
->printer
, job
,
8509 job
->state_value
== IPP_JOB_HELD
?
8510 "Job held by user." : "Job restarted by user.");
8512 if (event
& CUPSD_EVENT_JOB_CONFIG_CHANGED
)
8513 cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED
, job
->printer
, job
,
8514 "Job options changed by user.");
8517 * Start jobs if possible...
8525 * 'set_printer_defaults()' - Set printer default options from a request.
8529 set_printer_defaults(
8530 cupsd_client_t
*con
, /* I - Client connection */
8531 cupsd_printer_t
*printer
) /* I - Printer */
8533 int i
; /* Looping var */
8534 ipp_attribute_t
*attr
; /* Current attribute */
8535 int namelen
; /* Length of attribute name */
8536 char name
[256], /* New attribute name */
8537 value
[256]; /* String version of integer attrs */
8540 for (attr
= con
->request
->attrs
; attr
; attr
= attr
->next
)
8543 * Skip non-printer attributes...
8546 if (attr
->group_tag
!= IPP_TAG_PRINTER
|| !attr
->name
)
8549 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "set_printer_defaults: %s", attr
->name
);
8551 if (!strcmp(attr
->name
, "job-sheets-default"))
8554 * Only allow keywords and names...
8557 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
8561 * Only allow job-sheets-default to be set when running without a
8562 * system high classification level...
8568 cupsdSetString(&printer
->job_sheets
[0], attr
->values
[0].string
.text
);
8570 if (attr
->num_values
> 1)
8571 cupsdSetString(&printer
->job_sheets
[1], attr
->values
[1].string
.text
);
8573 cupsdSetString(&printer
->job_sheets
[1], "none");
8575 else if (!strcmp(attr
->name
, "requesting-user-name-allowed"))
8577 cupsdFreePrinterUsers(printer
);
8579 printer
->deny_users
= 0;
8581 if (attr
->value_tag
== IPP_TAG_NAME
&&
8582 (attr
->num_values
> 1 ||
8583 strcmp(attr
->values
[0].string
.text
, "all")))
8585 for (i
= 0; i
< attr
->num_values
; i
++)
8586 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
8589 else if (!strcmp(attr
->name
, "requesting-user-name-denied"))
8591 cupsdFreePrinterUsers(printer
);
8593 printer
->deny_users
= 1;
8595 if (attr
->value_tag
== IPP_TAG_NAME
&&
8596 (attr
->num_values
> 1 ||
8597 strcmp(attr
->values
[0].string
.text
, "none")))
8599 for (i
= 0; i
< attr
->num_values
; i
++)
8600 cupsdAddPrinterUser(printer
, attr
->values
[i
].string
.text
);
8603 else if (!strcmp(attr
->name
, "job-quota-period"))
8605 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8608 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-quota-period to %d...",
8609 attr
->values
[0].integer
);
8610 cupsdFreeQuotas(printer
);
8612 printer
->quota_period
= attr
->values
[0].integer
;
8614 else if (!strcmp(attr
->name
, "job-k-limit"))
8616 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8619 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-k-limit to %d...",
8620 attr
->values
[0].integer
);
8621 cupsdFreeQuotas(printer
);
8623 printer
->k_limit
= attr
->values
[0].integer
;
8625 else if (!strcmp(attr
->name
, "job-page-limit"))
8627 if (attr
->value_tag
!= IPP_TAG_INTEGER
)
8630 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Setting job-page-limit to %d...",
8631 attr
->values
[0].integer
);
8632 cupsdFreeQuotas(printer
);
8634 printer
->page_limit
= attr
->values
[0].integer
;
8636 else if (!strcmp(attr
->name
, "printer-op-policy"))
8638 cupsd_policy_t
*p
; /* Policy */
8641 if (attr
->value_tag
!= IPP_TAG_NAME
)
8644 if ((p
= cupsdFindPolicy(attr
->values
[0].string
.text
)) != NULL
)
8646 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8647 "Setting printer-op-policy to \"%s\"...",
8648 attr
->values
[0].string
.text
);
8649 cupsdSetString(&printer
->op_policy
, attr
->values
[0].string
.text
);
8650 printer
->op_policy_ptr
= p
;
8654 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8655 _("Unknown printer-op-policy \"%s\"."),
8656 attr
->values
[0].string
.text
);
8660 else if (!strcmp(attr
->name
, "printer-error-policy"))
8662 if (attr
->value_tag
!= IPP_TAG_NAME
&& attr
->value_tag
!= IPP_TAG_KEYWORD
)
8665 if (strcmp(attr
->values
[0].string
.text
, "abort-job") &&
8666 strcmp(attr
->values
[0].string
.text
, "retry-job") &&
8667 strcmp(attr
->values
[0].string
.text
, "stop-printer"))
8669 send_ipp_status(con
, IPP_NOT_POSSIBLE
,
8670 _("Unknown printer-error-policy \"%s\"."),
8671 attr
->values
[0].string
.text
);
8675 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8676 "Setting printer-error-policy to \"%s\"...",
8677 attr
->values
[0].string
.text
);
8678 cupsdSetString(&printer
->error_policy
, attr
->values
[0].string
.text
);
8680 else if (!strcmp(attr
->name
, "document-format-default") ||
8681 !strcmp(attr
->name
, "notify-lease-duration-default") ||
8682 !strcmp(attr
->name
, "notify-events-default"))
8686 * Skip any other non-default attributes...
8689 namelen
= strlen(attr
->name
);
8690 if (namelen
< 9 || strcmp(attr
->name
+ namelen
- 8, "-default") ||
8691 namelen
> (sizeof(name
) - 1) || attr
->num_values
!= 1)
8695 * OK, anything else must be a user-defined default...
8698 strlcpy(name
, attr
->name
, sizeof(name
));
8699 name
[namelen
- 8] = '\0'; /* Strip "-default" */
8701 switch (attr
->value_tag
)
8703 case IPP_TAG_DELETEATTR
:
8704 printer
->num_options
= cupsRemoveOption(name
,
8705 printer
->num_options
,
8706 &(printer
->options
));
8707 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8708 "Deleting %s", attr
->name
);
8712 case IPP_TAG_KEYWORD
:
8714 printer
->num_options
= cupsAddOption(name
,
8715 attr
->values
[0].string
.text
,
8716 printer
->num_options
,
8717 &(printer
->options
));
8718 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8719 "Setting %s to \"%s\"...", attr
->name
,
8720 attr
->values
[0].string
.text
);
8723 case IPP_TAG_BOOLEAN
:
8724 printer
->num_options
= cupsAddOption(name
,
8725 attr
->values
[0].boolean
?
8727 printer
->num_options
,
8728 &(printer
->options
));
8729 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8730 "Setting %s to %s...", attr
->name
,
8731 attr
->values
[0].boolean
? "true" : "false");
8734 case IPP_TAG_INTEGER
:
8736 sprintf(value
, "%d", attr
->values
[0].integer
);
8737 printer
->num_options
= cupsAddOption(name
, value
,
8738 printer
->num_options
,
8739 &(printer
->options
));
8740 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8741 "Setting %s to %s...", attr
->name
, value
);
8744 case IPP_TAG_RANGE
:
8745 sprintf(value
, "%d-%d", attr
->values
[0].range
.lower
,
8746 attr
->values
[0].range
.upper
);
8747 printer
->num_options
= cupsAddOption(name
, value
,
8748 printer
->num_options
,
8749 &(printer
->options
));
8750 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8751 "Setting %s to %s...", attr
->name
, value
);
8754 case IPP_TAG_RESOLUTION
:
8755 sprintf(value
, "%dx%d%s", attr
->values
[0].resolution
.xres
,
8756 attr
->values
[0].resolution
.yres
,
8757 attr
->values
[0].resolution
.units
== IPP_RES_PER_INCH
?
8759 printer
->num_options
= cupsAddOption(name
, value
,
8760 printer
->num_options
,
8761 &(printer
->options
));
8762 cupsdLogMessage(CUPSD_LOG_DEBUG
,
8763 "Setting %s to %s...", attr
->name
, value
);
8767 /* Do nothing for other values */
8775 * 'start_printer()' - Start a printer.
8779 start_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 */
8797 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "start_printer(%p[%d], %s)", con
,
8798 con
->http
.fd
, uri
->values
[0].string
.text
);
8801 * Is the destination valid?
8804 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8805 sizeof(method
), username
, sizeof(username
), host
,
8806 sizeof(host
), &port
, resource
, sizeof(resource
));
8808 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
8814 send_ipp_status(con
, IPP_NOT_FOUND
,
8815 _("The printer or class was not found."));
8823 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8825 send_http_error(con
, status
);
8830 * Start the printer...
8833 printer
->state_message
[0] = '\0';
8835 cupsdStartPrinter(printer
, 1);
8837 if (dtype
& CUPS_PRINTER_CLASS
)
8838 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" started by \"%s\".", name
,
8841 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" started by \"%s\".", name
,
8847 * Everything was ok, so return OK status...
8850 con
->response
->request
.status
.status_code
= IPP_OK
;
8855 * 'stop_printer()' - Stop a printer.
8859 stop_printer(cupsd_client_t
*con
, /* I - Client connection */
8860 ipp_attribute_t
*uri
) /* I - Printer URI */
8862 http_status_t status
; /* Policy status */
8863 cups_ptype_t dtype
; /* Destination type (printer or class) */
8864 char method
[HTTP_MAX_URI
],
8865 /* Method portion of URI */
8866 username
[HTTP_MAX_URI
],
8867 /* Username portion of URI */
8869 /* Host portion of URI */
8870 resource
[HTTP_MAX_URI
];
8871 /* Resource portion of URI */
8872 int port
; /* Port portion of URI */
8873 const char *name
; /* Printer name */
8874 cupsd_printer_t
*printer
; /* Printer data */
8875 ipp_attribute_t
*attr
; /* printer-state-message attribute */
8878 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "stop_printer(%p[%d], %s)", con
,
8879 con
->http
.fd
, uri
->values
[0].string
.text
);
8882 * Is the destination valid?
8885 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
8886 sizeof(method
), username
, sizeof(username
), host
,
8887 sizeof(host
), &port
, resource
, sizeof(resource
));
8889 if ((name
= cupsdValidateDest(host
, resource
, &dtype
, &printer
)) == NULL
)
8895 send_ipp_status(con
, IPP_NOT_FOUND
,
8896 _("The printer or class was not found."));
8904 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
8906 send_http_error(con
, status
);
8911 * Stop the printer...
8914 if ((attr
= ippFindAttribute(con
->request
, "printer-state-message",
8915 IPP_TAG_TEXT
)) == NULL
)
8916 strcpy(printer
->state_message
, "Paused");
8919 strlcpy(printer
->state_message
, attr
->values
[0].string
.text
,
8920 sizeof(printer
->state_message
));
8923 cupsdStopPrinter(printer
, 1);
8925 if (dtype
& CUPS_PRINTER_CLASS
)
8926 cupsdLogMessage(CUPSD_LOG_INFO
, "Class \"%s\" stopped by \"%s\".", name
,
8929 cupsdLogMessage(CUPSD_LOG_INFO
, "Printer \"%s\" stopped by \"%s\".", name
,
8933 * Everything was ok, so return OK status...
8936 con
->response
->request
.status
.status_code
= IPP_OK
;
8941 * 'url_encode_attr()' - URL-encode a string attribute.
8945 url_encode_attr(ipp_attribute_t
*attr
, /* I - Attribute */
8946 char *buffer
,/* I - String buffer */
8947 int bufsize
)/* I - Size of buffer */
8949 int i
; /* Looping var */
8950 char *bufptr
, /* Pointer into buffer */
8951 *bufend
, /* End of buffer */
8952 *valptr
; /* Pointer into value */
8955 strlcpy(buffer
, attr
->name
, bufsize
);
8956 bufptr
= buffer
+ strlen(buffer
);
8957 bufend
= buffer
+ bufsize
- 1;
8959 for (i
= 0; i
< attr
->num_values
; i
++)
8961 if (bufptr
>= bufend
)
8969 if (bufptr
>= bufend
)
8974 for (valptr
= attr
->values
[i
].string
.text
;
8975 *valptr
&& bufptr
< bufend
;
8979 if (bufptr
>= (bufend
- 2))
8986 else if (*valptr
== '\'' || *valptr
== '\\')
8989 *bufptr
++ = *valptr
;
8992 *bufptr
++ = *valptr
;
8994 if (bufptr
>= bufend
)
9005 * 'user_allowed()' - See if a user is allowed to print to a queue.
9008 static int /* O - 0 if not allowed, 1 if allowed */
9009 user_allowed(cupsd_printer_t
*p
, /* I - Printer or class */
9010 const char *username
) /* I - Username */
9012 int i
; /* Looping var */
9013 struct passwd
*pw
; /* User password data */
9016 if (p
->num_users
== 0)
9019 if (!strcmp(username
, "root"))
9022 pw
= getpwnam(username
);
9025 for (i
= 0; i
< p
->num_users
; i
++)
9027 if (p
->users
[i
][0] == '@')
9030 * Check group membership...
9033 if (cupsdCheckGroup(username
, pw
, p
->users
[i
] + 1))
9036 else if (!strcasecmp(username
, p
->users
[i
]))
9040 return ((i
< p
->num_users
) != p
->deny_users
);
9045 * 'validate_job()' - Validate printer options and destination.
9049 validate_job(cupsd_client_t
*con
, /* I - Client connection */
9050 ipp_attribute_t
*uri
) /* I - Printer URI */
9052 http_status_t status
; /* Policy status */
9053 ipp_attribute_t
*attr
; /* Current attribute */
9054 ipp_attribute_t
*format
; /* Document-format attribute */
9055 cups_ptype_t dtype
; /* Destination type (printer or class) */
9056 char method
[HTTP_MAX_URI
],
9057 /* Method portion of URI */
9058 username
[HTTP_MAX_URI
],
9059 /* Username portion of URI */
9061 /* Host portion of URI */
9062 resource
[HTTP_MAX_URI
];
9063 /* Resource portion of URI */
9064 int port
; /* Port portion of URI */
9065 char super
[MIME_MAX_SUPER
],
9066 /* Supertype of file */
9067 type
[MIME_MAX_TYPE
];
9068 /* Subtype of file */
9069 cupsd_printer_t
*printer
; /* Printer */
9072 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "validate_job(%p[%d], %s)", con
,
9073 con
->http
.fd
, uri
->values
[0].string
.text
);
9076 * OK, see if the client is sending the document compressed - CUPS
9077 * doesn't support compression yet...
9080 if ((attr
= ippFindAttribute(con
->request
, "compression",
9081 IPP_TAG_KEYWORD
)) != NULL
&&
9082 !strcmp(attr
->values
[0].string
.text
, "none"))
9084 send_ipp_status(con
, IPP_ATTRIBUTES
,
9085 _("Unsupported compression attribute %s!"),
9086 attr
->values
[0].string
.text
);
9087 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_KEYWORD
,
9088 "compression", NULL
, attr
->values
[0].string
.text
);
9093 * Is it a format we support?
9096 if ((format
= ippFindAttribute(con
->request
, "document-format",
9097 IPP_TAG_MIMETYPE
)) != NULL
)
9099 if (sscanf(format
->values
[0].string
.text
, "%15[^/]/%31[^;]", super
, type
) != 2)
9101 send_ipp_status(con
, IPP_BAD_REQUEST
, _("Bad document-format \"%s\"!"),
9102 format
->values
[0].string
.text
);
9106 if ((strcmp(super
, "application") || strcmp(type
, "octet-stream")) &&
9107 !mimeType(MimeDatabase
, super
, type
))
9109 cupsdLogMessage(CUPSD_LOG_INFO
,
9110 "Hint: Do you have the raw file printing rules enabled?");
9111 send_ipp_status(con
, IPP_DOCUMENT_FORMAT
,
9112 _("Unsupported format \"%s\"!"),
9113 format
->values
[0].string
.text
);
9114 ippAddString(con
->response
, IPP_TAG_UNSUPPORTED_GROUP
, IPP_TAG_MIMETYPE
,
9115 "document-format", NULL
, format
->values
[0].string
.text
);
9121 * Is the destination valid?
9124 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
->values
[0].string
.text
, method
,
9125 sizeof(method
), username
, sizeof(username
), host
,
9126 sizeof(host
), &port
, resource
, sizeof(resource
));
9128 if (cupsdValidateDest(host
, resource
, &dtype
, &printer
) == NULL
)
9134 send_ipp_status(con
, IPP_NOT_FOUND
,
9135 _("The printer or class was not found."));
9143 if ((status
= cupsdCheckPolicy(printer
->op_policy_ptr
, con
, NULL
)) != HTTP_OK
)
9145 send_http_error(con
, status
);
9150 * Everything was ok, so return OK status...
9153 con
->response
->request
.status
.status_code
= IPP_OK
;
9158 * 'validate_name()' - Make sure the printer name only contains valid chars.
9161 static int /* O - 0 if name is no good, 1 if name is good */
9162 validate_name(const char *name
) /* I - Name to check */
9164 const char *ptr
; /* Pointer into name */
9168 * Scan the whole name...
9171 for (ptr
= name
; *ptr
; ptr
++)
9172 if ((*ptr
>= 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
9176 * All the characters are good; validate the length, too...
9179 return ((ptr
- name
) < 128);
9184 * 'validate_user()' - Validate the user for the request.
9187 static int /* O - 1 if permitted, 0 otherwise */
9188 validate_user(cupsd_job_t
*job
, /* I - Job */
9189 cupsd_client_t
*con
, /* I - Client connection */
9190 const char *owner
, /* I - Owner of job/resource */
9191 char *username
, /* O - Authenticated username */
9192 int userlen
) /* I - Length of username */
9194 cupsd_printer_t
*printer
; /* Printer for job */
9197 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
9198 "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
9200 job
? job
->id
: 0, con
->http
.fd
, owner
? owner
: "(null)",
9207 if (!con
|| !owner
|| !username
|| userlen
<= 0)
9211 * Get the best authenticated username that is available.
9214 strlcpy(username
, get_username(con
), userlen
);
9217 * Check the username against the owner...
9220 printer
= cupsdFindDest(job
->dest
);
9222 return (cupsdCheckPolicy(printer
? printer
->op_policy_ptr
: DefaultPolicyPtr
,
9223 con
, owner
) == HTTP_OK
);
9228 * End of "$Id: ipp.c 5970 2006-09-19 20:11:08Z mike $".