/*
- * "$Id$"
+ * IPP routines for the CUPS scheduler.
*
- * IPP routines for the CUPS scheduler.
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
- * Copyright 2007-2013 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * This file contains Kerberos support code, copyright 2006 by
+ * Jelmer Vernooij.
*
- * This file contains Kerberos support code, copyright 2006 by
- * Jelmer Vernooij.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- * cupsdProcessIPPRequest() - Process an incoming IPP request.
- * cupsdTimeoutJob() - Timeout a job waiting on job files.
- * accept_jobs() - Accept print jobs to a printer.
- * add_class() - Add a class to the system.
- * add_file() - Add a file to a job.
- * add_job() - Add a job to a print queue.
- * add_job_subscriptions() - Add any subscriptions for a job.
- * add_job_uuid() - Add job-uuid attribute to a job.
- * add_printer() - Add a printer to the system.
- * add_printer_state_reasons() - Add the "printer-state-reasons" attribute
- * based upon the printer state...
- * add_queued_job_count() - Add the "queued-job-count" attribute for the
- * specified printer or class.
- * apply_printer_defaults() - Apply printer default options to a job.
- * authenticate_job() - Set job authentication info.
- * cancel_all_jobs() - Cancel all or selected print jobs.
- * cancel_job() - Cancel a print job.
- * cancel_subscription() - Cancel a subscription.
- * check_rss_recipient() - Check that we do not have a duplicate RSS
- * feed URI.
- * check_quotas() - Check quotas for a printer and user.
- * close_job() - Close a multi-file job.
- * copy_attrs() - Copy attributes from one request to another.
- * copy_banner() - Copy a banner file to the requests directory
- * for the specified job.
- * copy_file() - Copy a PPD file or interface script...
- * copy_model() - Copy a PPD model file, substituting default
- * values as needed...
- * copy_job_attrs() - Copy job attributes.
- * copy_printer_attrs() - Copy printer attributes.
- * copy_subscription_attrs() - Copy subscription attributes.
- * create_job() - Print a file to a printer or class.
- * create_requested_array() - Create an array for the requested-attributes.
- * create_subscription() - Create a notification subscription.
- * delete_printer() - Remove a printer or class from the system.
- * get_default() - Get the default destination.
- * get_devices() - Get the list of available devices on the
- * local system.
- * get_document() - Get a copy of a job file.
- * get_job_attrs() - Get job attributes.
- * get_jobs() - Get a list of jobs for the specified printer.
- * get_notifications() - Get events for a subscription.
- * get_ppd() - Get a named PPD from the local system.
- * get_ppds() - Get the list of PPD files on the local
- * system.
- * get_printer_attrs() - Get printer attributes.
- * get_printer_supported() - Get printer supported values.
- * get_printers() - Get a list of printers or classes.
- * get_subscription_attrs() - Get subscription attributes.
- * get_subscriptions() - Get subscriptions.
- * get_username() - Get the username associated with a request.
- * hold_job() - Hold a print job.
- * hold_new_jobs() - Hold pending/new jobs on a printer or class.
- * move_job() - Move a job to a new destination.
- * ppd_parse_line() - Parse a PPD default line.
- * print_job() - Print a file to a printer or class.
- * read_job_ticket() - Read a job ticket embedded in a print file.
- * reject_jobs() - Reject print jobs to a printer.
- * release_held_new_jobs() - Release pending/new jobs on a printer or
- * class.
- * release_job() - Release a held print job.
- * renew_subscription() - Renew an existing subscription...
- * restart_job() - Restart an old print job.
- * save_auth_info() - Save authentication information for a job.
- * send_document() - Send a file to a printer or class.
- * send_http_error() - Send a HTTP error back to the IPP client.
- * send_ipp_status() - Send a status back to the IPP client.
- * set_default() - Set the default destination...
- * set_job_attrs() - Set job attributes.
- * set_printer_attrs() - Set printer attributes.
- * set_printer_defaults() - Set printer default options from a request.
- * start_printer() - Start a printer.
- * stop_printer() - Stop a printer.
- * url_encode_attr() - URL-encode a string attribute.
- * url_encode_string() - URL-encode a string.
- * user_allowed() - See if a user is allowed to print to a queue.
- * validate_job() - Validate printer options and destination.
- * validate_name() - Make sure the printer name only contains
- * valid chars.
- * validate_user() - Validate the user for the request.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*/
/*
cups_array_t *exclude);
static int copy_banner(cupsd_client_t *con, cupsd_job_t *job,
const char *name);
-static int copy_file(const char *from, const char *to);
+static int copy_file(const char *from, const char *to, mode_t mode);
static int copy_model(cupsd_client_t *con, const char *from,
const char *to);
static void copy_job_attrs(cupsd_client_t *con,
cups_array_t *ra,
cups_array_t *exclude);
static void create_job(cupsd_client_t *con, ipp_attribute_t *uri);
+static void create_local_printer(cupsd_client_t *con);
static cups_array_t *create_requested_array(ipp_t *request);
-static void create_subscription(cupsd_client_t *con, ipp_attribute_t *uri);
+static void create_subscriptions(cupsd_client_t *con, ipp_attribute_t *uri);
static void delete_printer(cupsd_client_t *con, ipp_attribute_t *uri);
static void get_default(cupsd_client_t *con);
static void get_devices(cupsd_client_t *con);
static void send_document(cupsd_client_t *con, ipp_attribute_t *uri);
static void send_http_error(cupsd_client_t *con, http_status_t status,
cupsd_printer_t *printer);
-static void send_ipp_status(cupsd_client_t *con, ipp_status_t status,
- const char *message, ...)
- __attribute__((__format__(__printf__, 3, 4)));
+static void send_ipp_status(cupsd_client_t *con, ipp_status_t status, const char *message, ...) _CUPS_FORMAT(3, 4);
static void set_default(cupsd_client_t *con, ipp_attribute_t *uri);
static void set_job_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
static void set_printer_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
-static void set_printer_defaults(cupsd_client_t *con,
- cupsd_printer_t *printer);
+static int set_printer_defaults(cupsd_client_t *con, cupsd_printer_t *printer);
static void start_printer(cupsd_client_t *con, ipp_attribute_t *uri);
static void stop_printer(cupsd_client_t *con, ipp_attribute_t *uri);
-static void url_encode_attr(ipp_attribute_t *attr, char *buffer,
- int bufsize);
-static char *url_encode_string(const char *s, char *buffer, int bufsize);
+static void url_encode_attr(ipp_attribute_t *attr, char *buffer, size_t bufsize);
+static char *url_encode_string(const char *s, char *buffer, size_t bufsize);
static int user_allowed(cupsd_printer_t *p, const char *username);
static void validate_job(cupsd_client_t *con, ipp_attribute_t *uri);
static int validate_name(const char *name);
-static int validate_user(cupsd_job_t *job, cupsd_client_t *con,
- const char *owner, char *username,
- int userlen);
+static int validate_user(cupsd_job_t *job, cupsd_client_t *con, const char *owner, char *username, size_t userlen);
/*
ipp_attribute_t *uri = NULL; /* Printer or job URI attribute */
ipp_attribute_t *username; /* requesting-user-name attr */
int sub_id; /* Subscription ID */
+ int valid = 1; /* Valid request? */
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
- con, con->http.fd, con->request->request.op.operation_id);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdProcessIPPRequest(%p[%d]): operation_id=%04x(%s)", con, con->number, con->request->request.op.operation_id, ippOpString(con->request->request.op.operation_id));
+
+ if (LogLevel >= CUPSD_LOG_DEBUG2)
+ {
+ for (group = IPP_TAG_ZERO, attr = ippFirstAttribute(con->request); attr; attr = ippNextAttribute(con->request))
+ {
+ const char *name; /* Attribute name */
+ char value[1024]; /* Attribute value */
+
+ if (group != ippGetGroupTag(attr))
+ {
+ group = ippGetGroupTag(attr);
+ if (group != IPP_TAG_ZERO)
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdProcessIPPRequest: %s", ippTagString(group));
+ }
+
+ if ((name = ippGetName(attr)) == NULL)
+ continue;
+
+ ippAttributeString(attr, value, sizeof(value));
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdProcessIPPRequest: %s %s%s '%s'", name, ippGetCount(attr) > 1 ? "1setOf " : "", ippTagString(ippGetValueTag(attr)), value);
+ }
+ }
/*
* First build an empty response message for this request...
con->response = ippNew();
- con->response->request.status.version[0] =
- con->request->request.op.version[0];
- con->response->request.status.version[1] =
- con->request->request.op.version[1];
- con->response->request.status.request_id =
- con->request->request.op.request_id;
+ con->response->request.status.version[0] = con->request->request.op.version[0];
+ con->response->request.status.version[1] = con->request->request.op.version[1];
+ con->response->request.status.request_id = con->request->request.op.request_id;
/*
* Then validate the request header and required attributes...
*/
- if (con->request->request.any.version[0] != 1 &&
- con->request->request.any.version[0] != 2)
+ if (con->request->request.any.version[0] != 1 && con->request->request.any.version[0] != 2)
{
/*
* Return an error, since we only support IPP 1.x and 2.x.
*/
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s Bad request version number %d.%d",
- IPP_VERSION_NOT_SUPPORTED, con->http.hostname,
- con->request->request.any.version[0],
- con->request->request.any.version[1]);
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s Bad request version number %d.%d.", IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED, con->http->hostname, con->request->request.any.version[0], con->request->request.any.version[1]);
- send_ipp_status(con, IPP_VERSION_NOT_SUPPORTED,
- _("Bad request version number %d.%d."),
- con->request->request.any.version[0],
- con->request->request.any.version[1]);
+ send_ipp_status(con, IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED, _("Bad request version number %d.%d."), con->request->request.any.version[0], con->request->request.any.version[1]);
}
else if (con->request->request.any.request_id < 1)
{
* Return an error, since request IDs must be between 1 and 2^31-1
*/
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s Bad request ID %d",
- IPP_BAD_REQUEST, con->http.hostname,
- con->request->request.any.request_id);
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s Bad request ID %d.", IPP_STATUS_ERROR_BAD_REQUEST, con->http->hostname, con->request->request.any.request_id);
- send_ipp_status(con, IPP_BAD_REQUEST, _("Bad request ID %d."),
- con->request->request.any.request_id);
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("Bad request ID %d."), con->request->request.any.request_id);
}
else if (!con->request->attrs)
{
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s No attributes in request",
- IPP_BAD_REQUEST, con->http.hostname);
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s No attributes in request.", IPP_STATUS_ERROR_BAD_REQUEST, con->http->hostname);
- send_ipp_status(con, IPP_BAD_REQUEST, _("No attributes in request."));
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("No attributes in request."));
}
else
{
* Out of order; return an error...
*/
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s Attribute groups are out of order",
- IPP_BAD_REQUEST, con->http.hostname);
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s Attribute groups are out of order", IPP_STATUS_ERROR_BAD_REQUEST, con->http->hostname);
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("Attribute groups are out of order (%x < %x)."),
- attr->group_tag, group);
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("Attribute groups are out of order (%x < %x)."), attr->group_tag, group);
break;
}
else
*/
attr = con->request->attrs;
- if (attr && attr->name &&
- !strcmp(attr->name, "attributes-charset") &&
- (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_CHARSET)
+ if (attr && attr->name && !strcmp(attr->name, "attributes-charset") && (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_CHARSET && attr->group_tag == IPP_TAG_OPERATION)
charset = attr;
else
charset = NULL;
if (attr)
attr = attr->next;
- if (attr && attr->name &&
- !strcmp(attr->name, "attributes-natural-language") &&
- (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_LANGUAGE)
+ if (attr && attr->name && !strcmp(attr->name, "attributes-natural-language") && (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_LANGUAGE && attr->group_tag == IPP_TAG_OPERATION)
{
language = attr;
else
language = NULL;
- if ((attr = ippFindAttribute(con->request, "printer-uri",
- IPP_TAG_URI)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-uri", IPP_TAG_URI)) != NULL && attr->group_tag == IPP_TAG_OPERATION)
uri = attr;
- else if ((attr = ippFindAttribute(con->request, "job-uri",
- IPP_TAG_URI)) != NULL)
+ else if ((attr = ippFindAttribute(con->request, "job-uri", IPP_TAG_URI)) != NULL && attr->group_tag == IPP_TAG_OPERATION)
uri = attr;
- else if (con->request->request.op.operation_id == CUPS_GET_PPD)
- uri = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME);
+ else if (con->request->request.op.operation_id == CUPS_GET_PPD && (attr = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME)) != NULL && attr->group_tag == IPP_TAG_OPERATION)
+ uri = attr;
else
uri = NULL;
if (charset)
- ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL,
- charset->values[0].string.text);
+ ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, charset->values[0].string.text);
else
- ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL, "utf-8");
+ ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, "utf-8");
if (language)
- ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL,
- language->values[0].string.text);
+ ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, language->values[0].string.text);
else
- ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL, DefaultLanguage);
+ ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, DefaultLanguage);
- if (charset &&
- _cups_strcasecmp(charset->values[0].string.text, "us-ascii") &&
- _cups_strcasecmp(charset->values[0].string.text, "utf-8"))
+ if (charset && _cups_strcasecmp(charset->values[0].string.text, "us-ascii") && _cups_strcasecmp(charset->values[0].string.text, "utf-8"))
{
/*
* Bad character set...
cupsdLogMessage(CUPSD_LOG_ERROR, "Unsupported character set \"%s\"",
charset->values[0].string.text);
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s Unsupported attributes-charset value \"%s\"",
- IPP_CHARSET, con->http.hostname,
- charset->values[0].string.text);
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("Unsupported character set \"%s\"."),
- charset->values[0].string.text);
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s Unsupported attributes-charset value \"%s\".", IPP_STATUS_ERROR_CHARSET, con->http->hostname, charset->values[0].string.text);
+ send_ipp_status(con, IPP_STATUS_ERROR_CHARSET, _("Unsupported character set \"%s\"."), charset->values[0].string.text);
}
else if (!charset || !language ||
(!uri &&
if (!charset)
{
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Missing attributes-charset attribute");
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Missing attributes-charset attribute.");
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s Missing attributes-charset attribute",
- IPP_BAD_REQUEST, con->http.hostname);
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s Missing attributes-charset attribute.", IPP_STATUS_ERROR_BAD_REQUEST, con->http->hostname);
}
if (!language)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
- "Missing attributes-natural-language attribute");
+ "Missing attributes-natural-language attribute.");
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s Missing attributes-natural-language attribute",
- IPP_BAD_REQUEST, con->http.hostname);
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s Missing attributes-natural-language attribute.", IPP_STATUS_ERROR_BAD_REQUEST, con->http->hostname);
}
if (!uri)
{
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Missing printer-uri, job-uri, or ppd-name "
- "attribute");
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Missing printer-uri, job-uri, or ppd-name attribute.");
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s Missing printer-uri, job-uri, or ppd-name "
- "attribute", IPP_BAD_REQUEST, con->http.hostname);
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s Missing printer-uri, job-uri, or ppd-name attribute.", IPP_STATUS_ERROR_BAD_REQUEST, con->http->hostname);
}
cupsdLogMessage(CUPSD_LOG_DEBUG, "Request attributes follow...");
else
{
/*
- * OK, all the checks pass so far; make sure requesting-user-name is
- * not "root" from a remote host...
+ * OK, all the checks pass so far; validate "requesting-user-name"
+ * attribute value...
*/
- if ((username = ippFindAttribute(con->request, "requesting-user-name",
- IPP_TAG_NAME)) != NULL)
- {
- /*
- * Check for root user...
- */
-
- if (!strcmp(username->values[0].string.text, "root") &&
- _cups_strcasecmp(con->http.hostname, "localhost") &&
- strcmp(con->username, "root"))
+ if ((username = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_ZERO)) != NULL)
+ {
+ /*
+ * Validate "requesting-user-name"...
+ */
+
+ if (username->group_tag != IPP_TAG_OPERATION && StrictConformance)
+ {
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s \"requesting-user-name\" attribute in wrong group.", IPP_STATUS_ERROR_BAD_REQUEST, con->http->hostname);
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("\"requesting-user-name\" attribute in wrong group."));
+ valid = 0;
+ }
+ else if (username->value_tag != IPP_TAG_NAME && username->value_tag != IPP_TAG_NAMELANG)
+ {
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s \"requesting-user-name\" attribute with wrong syntax.", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, con->http->hostname);
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("\"requesting-user-name\" attribute with wrong syntax."));
+ if ((attr = ippCopyAttribute(con->response, username, 0)) != NULL)
+ attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
+ valid = 0;
+ }
+ else if (!ippValidateAttribute(username))
+ {
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s \"requesting-user-name\" attribute with bad value.", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, con->http->hostname);
+
+ if (StrictConformance)
+ {
+ /*
+ * Throw an error...
+ */
+
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("\"requesting-user-name\" attribute with wrong syntax."));
+ if ((attr = ippCopyAttribute(con->response, username, 0)) != NULL)
+ attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
+ valid = 0;
+ }
+ else
+ {
+ /*
+ * Map bad "requesting-user-name" to 'anonymous'...
+ */
+
+ ippSetString(con->request, &username, 0, "anonymous");
+ }
+ }
+ else if (!strcmp(username->values[0].string.text, "root") && _cups_strcasecmp(con->http->hostname, "localhost") && strcmp(con->username, "root"))
{
/*
* Remote unauthenticated user masquerading as local root...
*/
- _cupsStrFree(username->values[0].string.text);
- username->values[0].string.text = _cupsStrAlloc(RemoteRoot);
+ ippSetString(con->request, &username, 0, RemoteRoot);
}
}
- if ((attr = ippFindAttribute(con->request, "notify-subscription-id",
- IPP_TAG_INTEGER)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "notify-subscription-id", IPP_TAG_INTEGER)) != NULL)
sub_id = attr->values[0].integer;
else
sub_id = 0;
- /*
- * Then try processing the operation...
- */
-
- if (uri)
- cupsdLogMessage(CUPSD_LOG_DEBUG, "%s %s",
- ippOpString(con->request->request.op.operation_id),
- uri->values[0].string.text);
- else
- cupsdLogMessage(CUPSD_LOG_DEBUG, "%s",
- ippOpString(con->request->request.op.operation_id));
-
- switch (con->request->request.op.operation_id)
- {
- case IPP_PRINT_JOB :
- print_job(con, uri);
- break;
-
- case IPP_VALIDATE_JOB :
- validate_job(con, uri);
- break;
-
- case IPP_CREATE_JOB :
- create_job(con, uri);
- break;
-
- case IPP_SEND_DOCUMENT :
- send_document(con, uri);
- break;
-
- case IPP_CANCEL_JOB :
- cancel_job(con, uri);
- break;
-
- case IPP_GET_JOB_ATTRIBUTES :
- get_job_attrs(con, uri);
- break;
-
- case IPP_GET_JOBS :
- get_jobs(con, uri);
- break;
-
- case IPP_GET_PRINTER_ATTRIBUTES :
- get_printer_attrs(con, uri);
- break;
-
- case IPP_GET_PRINTER_SUPPORTED_VALUES :
- get_printer_supported(con, uri);
- break;
-
- case IPP_HOLD_JOB :
- hold_job(con, uri);
- break;
-
- case IPP_RELEASE_JOB :
- release_job(con, uri);
- break;
-
- case IPP_RESTART_JOB :
- restart_job(con, uri);
- break;
-
- case IPP_PAUSE_PRINTER :
- stop_printer(con, uri);
- break;
-
- case IPP_RESUME_PRINTER :
- start_printer(con, uri);
- break;
-
- case IPP_PURGE_JOBS :
- case IPP_CANCEL_JOBS :
- case IPP_CANCEL_MY_JOBS :
- cancel_all_jobs(con, uri);
- break;
-
- case IPP_SET_JOB_ATTRIBUTES :
- set_job_attrs(con, uri);
- break;
-
- case IPP_SET_PRINTER_ATTRIBUTES :
- set_printer_attrs(con, uri);
- break;
-
- case IPP_HOLD_NEW_JOBS :
- hold_new_jobs(con, uri);
- break;
-
- case IPP_RELEASE_HELD_NEW_JOBS :
- release_held_new_jobs(con, uri);
- break;
-
- case IPP_CLOSE_JOB :
- close_job(con, uri);
- break;
-
- case CUPS_GET_DEFAULT :
- get_default(con);
- break;
-
- case CUPS_GET_PRINTERS :
- get_printers(con, 0);
- break;
-
- case CUPS_GET_CLASSES :
- get_printers(con, CUPS_PRINTER_CLASS);
- break;
-
- case CUPS_ADD_PRINTER :
- add_printer(con, uri);
- break;
-
- case CUPS_DELETE_PRINTER :
- delete_printer(con, uri);
- break;
-
- case CUPS_ADD_CLASS :
- add_class(con, uri);
- break;
+ if (valid)
+ {
+ /*
+ * Try processing the operation...
+ */
- case CUPS_DELETE_CLASS :
- delete_printer(con, uri);
- break;
+ if (uri)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "%s %s", ippOpString(con->request->request.op.operation_id), uri->values[0].string.text);
+ else
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "%s", ippOpString(con->request->request.op.operation_id));
- case CUPS_ACCEPT_JOBS :
- case IPP_ENABLE_PRINTER :
- accept_jobs(con, uri);
- break;
+ switch (con->request->request.op.operation_id)
+ {
+ case IPP_OP_PRINT_JOB :
+ print_job(con, uri);
+ break;
+
+ case IPP_OP_VALIDATE_JOB :
+ validate_job(con, uri);
+ break;
+
+ case IPP_OP_CREATE_JOB :
+ create_job(con, uri);
+ break;
+
+ case IPP_OP_SEND_DOCUMENT :
+ send_document(con, uri);
+ break;
+
+ case IPP_OP_CANCEL_JOB :
+ cancel_job(con, uri);
+ break;
+
+ case IPP_OP_GET_JOB_ATTRIBUTES :
+ get_job_attrs(con, uri);
+ break;
+
+ case IPP_OP_GET_JOBS :
+ get_jobs(con, uri);
+ break;
+
+ case IPP_OP_GET_PRINTER_ATTRIBUTES :
+ get_printer_attrs(con, uri);
+ break;
+
+ case IPP_OP_GET_PRINTER_SUPPORTED_VALUES :
+ get_printer_supported(con, uri);
+ break;
+
+ case IPP_OP_HOLD_JOB :
+ hold_job(con, uri);
+ break;
+
+ case IPP_OP_RELEASE_JOB :
+ release_job(con, uri);
+ break;
+
+ case IPP_OP_RESTART_JOB :
+ restart_job(con, uri);
+ break;
+
+ case IPP_OP_PAUSE_PRINTER :
+ stop_printer(con, uri);
+ break;
+
+ case IPP_OP_RESUME_PRINTER :
+ start_printer(con, uri);
+ break;
+
+ case IPP_OP_PURGE_JOBS :
+ case IPP_OP_CANCEL_JOBS :
+ case IPP_OP_CANCEL_MY_JOBS :
+ cancel_all_jobs(con, uri);
+ break;
+
+ case IPP_OP_SET_JOB_ATTRIBUTES :
+ set_job_attrs(con, uri);
+ break;
+
+ case IPP_OP_SET_PRINTER_ATTRIBUTES :
+ set_printer_attrs(con, uri);
+ break;
+
+ case IPP_OP_HOLD_NEW_JOBS :
+ hold_new_jobs(con, uri);
+ break;
+
+ case IPP_OP_RELEASE_HELD_NEW_JOBS :
+ release_held_new_jobs(con, uri);
+ break;
+
+ case IPP_OP_CLOSE_JOB :
+ close_job(con, uri);
+ break;
+
+ case IPP_OP_CUPS_GET_DEFAULT :
+ get_default(con);
+ break;
+
+ case IPP_OP_CUPS_GET_PRINTERS :
+ get_printers(con, 0);
+ break;
+
+ case IPP_OP_CUPS_GET_CLASSES :
+ get_printers(con, CUPS_PRINTER_CLASS);
+ break;
+
+ case IPP_OP_CUPS_ADD_MODIFY_PRINTER :
+ add_printer(con, uri);
+ break;
+
+ case IPP_OP_CUPS_DELETE_PRINTER :
+ delete_printer(con, uri);
+ break;
+
+ case IPP_OP_CUPS_ADD_MODIFY_CLASS :
+ add_class(con, uri);
+ break;
+
+ case IPP_OP_CUPS_DELETE_CLASS :
+ delete_printer(con, uri);
+ break;
+
+ case IPP_OP_CUPS_ACCEPT_JOBS :
+ case IPP_OP_ENABLE_PRINTER :
+ accept_jobs(con, uri);
+ break;
+
+ case IPP_OP_CUPS_REJECT_JOBS :
+ case IPP_OP_DISABLE_PRINTER :
+ reject_jobs(con, uri);
+ break;
- case CUPS_REJECT_JOBS :
- case IPP_DISABLE_PRINTER :
- reject_jobs(con, uri);
- break;
+ case IPP_OP_CUPS_SET_DEFAULT :
+ set_default(con, uri);
+ break;
- case CUPS_SET_DEFAULT :
- set_default(con, uri);
- break;
+ case IPP_OP_CUPS_GET_DEVICES :
+ get_devices(con);
+ break;
- case CUPS_GET_DEVICES :
- get_devices(con);
- break;
+ case IPP_OP_CUPS_GET_DOCUMENT :
+ get_document(con, uri);
+ break;
- case CUPS_GET_DOCUMENT :
- get_document(con, uri);
- break;
+ case IPP_OP_CUPS_GET_PPD :
+ get_ppd(con, uri);
+ break;
- case CUPS_GET_PPD :
- get_ppd(con, uri);
- break;
+ case IPP_OP_CUPS_GET_PPDS :
+ get_ppds(con);
+ break;
- case CUPS_GET_PPDS :
- get_ppds(con);
- break;
+ case IPP_OP_CUPS_MOVE_JOB :
+ move_job(con, uri);
+ break;
- case CUPS_MOVE_JOB :
- move_job(con, uri);
- break;
+ case IPP_OP_CUPS_AUTHENTICATE_JOB :
+ authenticate_job(con, uri);
+ break;
- case CUPS_AUTHENTICATE_JOB :
- authenticate_job(con, uri);
- break;
+ case IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS :
+ case IPP_OP_CREATE_JOB_SUBSCRIPTIONS :
+ create_subscriptions(con, uri);
+ break;
+
+ case IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES :
+ get_subscription_attrs(con, sub_id);
+ break;
+
+ case IPP_OP_GET_SUBSCRIPTIONS :
+ get_subscriptions(con, uri);
+ break;
- case IPP_CREATE_PRINTER_SUBSCRIPTION :
- case IPP_CREATE_JOB_SUBSCRIPTION :
- create_subscription(con, uri);
- break;
+ case IPP_OP_RENEW_SUBSCRIPTION :
+ renew_subscription(con, sub_id);
+ break;
- case IPP_GET_SUBSCRIPTION_ATTRIBUTES :
- get_subscription_attrs(con, sub_id);
- break;
+ case IPP_OP_CANCEL_SUBSCRIPTION :
+ cancel_subscription(con, sub_id);
+ break;
- case IPP_GET_SUBSCRIPTIONS :
- get_subscriptions(con, uri);
- break;
+ case IPP_OP_GET_NOTIFICATIONS :
+ get_notifications(con);
+ break;
- case IPP_RENEW_SUBSCRIPTION :
- renew_subscription(con, sub_id);
- break;
+ case IPP_OP_CUPS_CREATE_LOCAL_PRINTER :
+ create_local_printer(con);
+ break;
- case IPP_CANCEL_SUBSCRIPTION :
- cancel_subscription(con, sub_id);
- break;
+ default :
+ cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s Operation %04X (%s) not supported.", IPP_STATUS_ERROR_OPERATION_NOT_SUPPORTED, con->http->hostname, con->request->request.op.operation_id, ippOpString(con->request->request.op.operation_id));
- case IPP_GET_NOTIFICATIONS :
- get_notifications(con);
- break;
-
- default :
- cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
- "%04X %s Operation %04X (%s) not supported",
- IPP_OPERATION_NOT_SUPPORTED, con->http.hostname,
- con->request->request.op.operation_id,
- ippOpString(con->request->request.op.operation_id));
-
- send_ipp_status(con, IPP_OPERATION_NOT_SUPPORTED,
- _("%s not supported."),
- ippOpString(
- con->request->request.op.operation_id));
- break;
+ send_ipp_status(con, IPP_STATUS_ERROR_OPERATION_NOT_SUPPORTED, _("%s not supported."), ippOpString(con->request->request.op.operation_id));
+ break;
+ }
}
}
}
* Sending data from the scheduler...
*/
- cupsdLogMessage(con->response->request.status.status_code
- >= IPP_BAD_REQUEST &&
- con->response->request.status.status_code
- != IPP_NOT_FOUND ? CUPSD_LOG_ERROR : CUPSD_LOG_DEBUG,
- "[Client %d] Returning IPP %s for %s (%s) from %s",
- con->http.fd,
- ippErrorString(con->response->request.status.status_code),
- ippOpString(con->request->request.op.operation_id),
- uri ? uri->values[0].string.text : "no URI",
- con->http.hostname);
-
- if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE))
- {
-#ifdef CUPSD_USE_CHUNKING
- /*
- * Because older versions of CUPS (1.1.17 and older) and some IPP
- * clients do not implement chunking properly, we cannot use
- * chunking by default. This may become the default in future
- * CUPS releases, or we might add a configuration directive for
- * it.
- */
-
- if (con->http.version == HTTP_1_1)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "[Client %d] Transfer-Encoding: chunked",
- con->http.fd);
+ cupsdLogClient(con, con->response->request.status.status_code >= IPP_STATUS_ERROR_BAD_REQUEST && con->response->request.status.status_code != IPP_STATUS_ERROR_NOT_FOUND ? CUPSD_LOG_ERROR : CUPSD_LOG_DEBUG, "Returning IPP %s for %s (%s) from %s.", ippErrorString(con->response->request.status.status_code), ippOpString(con->request->request.op.operation_id), uri ? uri->values[0].string.text : "no URI", con->http->hostname);
- if (httpPrintf(HTTP(con), "Transfer-Encoding: chunked\r\n\r\n") < 0)
- return (0);
+ httpClearFields(con->http);
- if (cupsdFlushHeader(con) < 0)
- return (0);
+#ifdef CUPSD_USE_CHUNKING
+ /*
+ * Because older versions of CUPS (1.1.17 and older) and some IPP
+ * clients do not implement chunking properly, we cannot use
+ * chunking by default. This may become the default in future
+ * CUPS releases, or we might add a configuration directive for
+ * it.
+ */
- con->http.data_encoding = HTTP_ENCODE_CHUNKED;
- }
- else
+ if (con->http->version == HTTP_1_1)
+ {
+ cupsdLogClient(con, CUPSD_LOG_DEBUG, "Transfer-Encoding: chunked");
+ cupsdSetLength(con->http, 0);
+ }
+ else
#endif /* CUPSD_USE_CHUNKING */
- {
- size_t length; /* Length of response */
-
-
- length = ippLength(con->response);
-
- if (con->file >= 0 && !con->pipe_pid)
- {
- struct stat fileinfo; /* File information */
-
- if (!fstat(con->file, &fileinfo))
- length += fileinfo.st_size;
- }
+ {
+ size_t length; /* Length of response */
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "[Client %d] Content-Length: " CUPS_LLFMT,
- con->http.fd, CUPS_LLCAST length);
- if (httpPrintf(HTTP(con), "Content-Length: " CUPS_LLFMT "\r\n\r\n",
- CUPS_LLCAST length) < 0)
- return (0);
- if (cupsdFlushHeader(con) < 0)
- return (0);
+ length = ippLength(con->response);
- con->http.data_encoding = HTTP_ENCODE_LENGTH;
- con->http.data_remaining = length;
+ if (con->file >= 0 && !con->pipe_pid)
+ {
+ struct stat fileinfo; /* File information */
- if (con->http.data_remaining <= INT_MAX)
- con->http._data_remaining = con->http.data_remaining;
- else
- con->http._data_remaining = INT_MAX;
+ if (!fstat(con->file, &fileinfo))
+ length += (size_t)fileinfo.st_size;
}
- cupsdAddSelect(con->http.fd, (cupsd_selfunc_t)cupsdReadClient,
- (cupsd_selfunc_t)cupsdWriteClient, con);
+ cupsdLogClient(con, CUPSD_LOG_DEBUG, "Content-Length: " CUPS_LLFMT, CUPS_LLCAST length);
+ httpSetLength(con->http, length);
+ }
+ if (cupsdSendHeader(con, HTTP_OK, "application/ipp", CUPSD_AUTH_NONE))
+ {
/*
* Tell the caller the response header was sent successfully...
*/
+ cupsdAddSelect(httpGetFd(con->http), (cupsd_selfunc_t)cupsdReadClient, (cupsd_selfunc_t)cupsdWriteClient, con);
+
return (1);
}
else
cupsdLogMessage(CUPSD_LOG_DEBUG2, "accept_jobs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_class(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Do we have a valid URI?
pclass = cupsdAddClass(resource + 9);
modify = 0;
+
+ pclass->printer_id = NextPrinterId ++;
}
else if ((status = cupsdCheckPolicy(pclass->op_policy_ptr, con,
NULL)) != HTTP_OK)
need_restart_job = 0;
- if ((attr = ippFindAttribute(con->request, "printer-location",
- IPP_TAG_TEXT)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL)
cupsdSetString(&pclass->location, attr->values[0].string.text);
+ if ((attr = ippFindAttribute(con->request, "printer-geo-location", IPP_TAG_URI)) != NULL && !strncmp(attr->values[0].string.text, "geo:", 4))
+ cupsdSetString(&pclass->geo_location, attr->values[0].string.text);
+
+ if ((attr = ippFindAttribute(con->request, "printer-organization", IPP_TAG_TEXT)) != NULL)
+ cupsdSetString(&pclass->organization, attr->values[0].string.text);
+
+ if ((attr = ippFindAttribute(con->request, "printer-organizational-unit", IPP_TAG_TEXT)) != NULL)
+ cupsdSetString(&pclass->organizational_unit, attr->values[0].string.text);
+
if ((attr = ippFindAttribute(con->request, "printer-info",
IPP_TAG_TEXT)) != NULL)
cupsdSetString(&pclass->info, attr->values[0].string.text);
pclass->accepting ? "Now" : "No longer");
}
- if ((attr = ippFindAttribute(con->request, "printer-is-shared",
- IPP_TAG_BOOLEAN)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-is-shared", IPP_TAG_BOOLEAN)) != NULL)
{
- if (pclass->shared && !attr->values[0].boolean)
+ if (pclass->type & CUPS_PRINTER_REMOTE)
+ {
+ /*
+ * Cannot re-share remote printers.
+ */
+
+ send_ipp_status(con, IPP_BAD_REQUEST, _("Cannot change printer-is-shared for remote queues."));
+ if (!modify)
+ cupsdDeletePrinter(pclass, 0);
+
+ return;
+ }
+
+ if (pclass->shared && !ippGetBoolean(attr, 0))
cupsdDeregisterPrinter(pclass, 1);
cupsdLogMessage(CUPSD_LOG_INFO,
"Setting %s printer-is-shared to %d (was %d.)",
pclass->name, attr->values[0].boolean, pclass->shared);
- pclass->shared = attr->values[0].boolean;
+ pclass->shared = ippGetBoolean(attr, 0);
}
if ((attr = ippFindAttribute(con->request, "printer-state",
send_ipp_status(con, IPP_BAD_REQUEST,
_("Attempt to set %s printer-state to bad value %d."),
pclass->name, attr->values[0].integer);
+ if (!modify)
+ cupsdDeletePrinter(pclass, 0);
+
return;
}
send_ipp_status(con, IPP_NOT_FOUND,
_("The printer or class does not exist."));
+ if (!modify)
+ cupsdDeletePrinter(pclass, 0);
+
return;
}
else if (dtype & CUPS_PRINTER_CLASS)
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Nested classes are not allowed."));
+ if (!modify)
+ cupsdDeletePrinter(pclass, 0);
+
return;
}
}
}
- set_printer_defaults(con, pclass);
+ if (!set_printer_defaults(con, pclass))
+ {
+ if (!modify)
+ cupsdDeletePrinter(pclass, 0);
+
+ return;
+ }
if ((attr = ippFindAttribute(con->request, "auth-info-required",
IPP_TAG_KEYWORD)) != NULL)
cupsdSetAuthInfoRequired(pclass, NULL, attr);
+ pclass->config_time = time(NULL);
+
/*
* Update the printer class attributes and return...
*/
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"add_file(con=%p[%d], job=%d, filetype=%s/%s, "
- "compression=%d)", con, con ? con->http.fd : -1, job->id,
+ "compression=%d)", con, con ? con->number : -1, job->id,
filetype->super, filetype->type, compression);
/*
else
{
compressions = (int *)realloc(job->compressions,
- (job->num_files + 1) * sizeof(int));
+ (size_t)(job->num_files + 1) * sizeof(int));
filetypes = (mime_type_t **)realloc(job->filetypes,
- (job->num_files + 1) *
+ (size_t)(job->num_files + 1) *
sizeof(mime_type_t *));
}
ipp_t *unsup_col; /* media-col in unsupported response */
static const char * const readonly[] =/* List of read-only attributes */
{
+ "date-time-at-completed",
+ "date-time-at-creation",
+ "date-time-at-processing",
+ "job-detailed-status-messages",
+ "job-document-access-errors",
"job-id",
- "job-k-octets-completed",
"job-impressions-completed",
+ "job-k-octets-completed",
"job-media-sheets-completed",
+ "job-pages-completed",
+ "job-printer-up-time",
+ "job-printer-uri",
"job-state",
"job-state-message",
"job-state-reasons",
+ "job-uri",
+ "number-of-documents",
+ "number-of-intervening-jobs",
+ "output-device-assigned",
"time-at-completed",
"time-at-creation",
"time-at-processing"
cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %p(%s), %p(%s/%s))",
- con, con->http.fd, printer, printer->name,
+ con, con->number, printer, printer->name,
filetype, filetype ? filetype->super : "none",
filetype ? filetype->type : "none");
*/
if (!printer->shared &&
- _cups_strcasecmp(con->http.hostname, "localhost") &&
- _cups_strcasecmp(con->http.hostname, ServerName))
+ _cups_strcasecmp(con->http->hostname, "localhost") &&
+ _cups_strcasecmp(con->http->hostname, ServerName))
{
send_ipp_status(con, IPP_NOT_AUTHORIZED,
_("The printer or class is not shared."));
return (NULL);
}
#ifdef HAVE_SSL
- else if (auth_info && !con->http.tls &&
- !httpAddrLocalhost(con->http.hostaddr))
+ else if (auth_info && !con->http->tls &&
+ !httpAddrLocalhost(con->http->hostaddr))
{
/*
* Require encryption of auth-info over non-local connections...
for (i = 0; i < (int)(sizeof(readonly) / sizeof(readonly[0])); i ++)
{
- if ((attr = ippFindAttribute(con->request, readonly[i],
- IPP_TAG_ZERO)) != NULL)
+ if ((attr = ippFindAttribute(con->request, readonly[i], IPP_TAG_ZERO)) != NULL)
{
ippDeleteAttribute(con->request, attr);
if (StrictConformance)
{
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("The '%s' Job Description attribute cannot be "
- "supplied in a job creation request."), readonly[i]);
+ send_ipp_status(con, IPP_BAD_REQUEST, _("The '%s' Job Status attribute cannot be supplied in a job creation request."), readonly[i]);
return (NULL);
}
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Unexpected '%s' Job Description attribute in a job "
- "creation request.", readonly[i]);
+ cupsdLogMessage(CUPSD_LOG_INFO, "Unexpected '%s' Job Status attribute in a job creation request.", readonly[i]);
}
}
}
if ((attr = ippFindAttribute(con->request, "job-name", IPP_TAG_ZERO)) == NULL)
- ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
- "Untitled");
+ ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, "Untitled");
else if ((attr->value_tag != IPP_TAG_NAME &&
attr->value_tag != IPP_TAG_NAMELANG) ||
attr->num_values != 1)
_("Bad job-name value: Wrong type or count."));
if ((attr = ippCopyAttribute(con->response, attr, 0)) != NULL)
attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
- return (NULL);
+
+ if (StrictConformance)
+ return (NULL);
+
+ /* Don't use invalid attribute */
+ ippDeleteAttribute(con->request, attr);
+
+ ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, "Untitled");
}
else if (!ippValidateAttribute(attr))
{
send_ipp_status(con, IPP_ATTRIBUTES, _("Bad job-name value: %s"),
cupsLastErrorString());
+
if ((attr = ippCopyAttribute(con->response, attr, 0)) != NULL)
attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
- return (NULL);
+
+ if (StrictConformance)
+ return (NULL);
+
+ /* Don't use invalid attribute */
+ ippDeleteAttribute(con->request, attr);
+
+ ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, "Untitled");
}
+ attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME);
+
if ((job = cupsdAddJob(priority, printer->name)) == NULL)
{
send_ipp_status(con, IPP_INTERNAL_ERROR,
add_job_uuid(job);
apply_printer_defaults(printer, job);
- attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
-
if (con->username[0])
{
cupsdSetString(&job->username, con->username);
if (attr)
- cupsdSetString(&attr->values[0].string.text, con->username);
+ ippSetString(job->attrs, &attr, 0, con->username);
}
else if (attr)
{
"job-originating-user-name", NULL, job->username);
else
{
- attr->group_tag = IPP_TAG_JOB;
- _cupsStrFree(attr->name);
- attr->name = _cupsStrAlloc("job-originating-user-name");
+ ippSetGroupTag(job->attrs, &attr, IPP_TAG_JOB);
+ ippSetName(job->attrs, &attr, "job-originating-user-name");
}
if (con->username[0] || auth_info)
ippDeleteAttribute(job->attrs, auth_info);
}
+ if ((attr = ippFindAttribute(con->request, "job-name", IPP_TAG_NAME)) != NULL)
+ cupsdSetString(&(job->name), attr->values[0].string.text);
+
if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
IPP_TAG_ZERO)) != NULL)
{
if (attr->value_tag != IPP_TAG_NAME ||
attr->num_values != 1 ||
- strcmp(con->http.hostname, "localhost"))
+ strcmp(con->http->hostname, "localhost"))
{
/*
* Can't override the value if we aren't connected via localhost.
* Also, we can only have 1 value and it must be a name value.
*/
- switch (attr->value_tag)
- {
- case IPP_TAG_STRING :
- case IPP_TAG_TEXTLANG :
- case IPP_TAG_NAMELANG :
- case IPP_TAG_TEXT :
- case IPP_TAG_NAME :
- case IPP_TAG_KEYWORD :
- case IPP_TAG_URI :
- case IPP_TAG_URISCHEME :
- case IPP_TAG_CHARSET :
- case IPP_TAG_LANGUAGE :
- case IPP_TAG_MIMETYPE :
- /*
- * Free old strings...
- */
-
- for (i = 0; i < attr->num_values; i ++)
- {
- _cupsStrFree(attr->values[i].string.text);
- attr->values[i].string.text = NULL;
- if (attr->values[i].string.language)
- {
- _cupsStrFree(attr->values[i].string.language);
- attr->values[i].string.language = NULL;
- }
- }
-
- default :
- break;
- }
-
- /*
- * Use the default connection hostname instead...
- */
-
- attr->value_tag = IPP_TAG_NAME;
- attr->num_values = 1;
- attr->values[0].string.text = _cupsStrAlloc(con->http.hostname);
+ ippDeleteAttribute(job->attrs, attr);
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-originating-host-name", NULL, con->http->hostname);
}
-
- attr->group_tag = IPP_TAG_JOB;
+ else
+ ippSetGroupTag(job->attrs, &attr, IPP_TAG_JOB);
}
else
{
*/
ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
- "job-originating-host-name", NULL, con->http.hostname);
+ "job-originating-host-name", NULL, con->http->hostname);
}
- ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation",
- time(NULL));
- attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
- "time-at-processing", 0);
- attr->value_tag = IPP_TAG_NOVALUE;
- attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
- "time-at-completed", 0);
- attr->value_tag = IPP_TAG_NOVALUE;
+ ippAddOutOfBand(job->attrs, IPP_TAG_JOB, IPP_TAG_NOVALUE, "date-time-at-completed");
+ ippAddDate(job->attrs, IPP_TAG_JOB, "date-time-at-creation", ippTimeToDate(time(NULL)));
+ ippAddOutOfBand(job->attrs, IPP_TAG_JOB, IPP_TAG_NOVALUE, "date-time-at-processing");
+ ippAddOutOfBand(job->attrs, IPP_TAG_JOB, IPP_TAG_NOVALUE, "time-at-completed");
+ ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation", time(NULL));
+ ippAddOutOfBand(job->attrs, IPP_TAG_JOB, IPP_TAG_NOVALUE, "time-at-processing");
/*
* Add remaining job attributes...
job->state_value = (ipp_jstate_t)job->state->values[0].integer;
job->reasons = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
"job-state-reasons", NULL, "job-incoming");
+ job->impressions = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-impressions-completed", 0);
job->sheets = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
"job-media-sheets-completed", 0);
ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", NULL,
printer->uri);
- if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
- IPP_TAG_INTEGER)) != NULL)
+ if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
attr->values[0].integer = 0;
else
ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-k-octets", 0);
attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
"job-hold-until", NULL, val);
}
- if (attr && strcmp(attr->values[0].string.text, "no-hold"))
+
+ if (printer->holding_new_jobs)
+ {
+ /*
+ * Hold all new jobs on this printer...
+ */
+
+ if (attr && strcmp(attr->values[0].string.text, "no-hold"))
+ cupsdSetJobHoldUntil(job, ippGetString(attr, 0, NULL), 0);
+ else
+ cupsdSetJobHoldUntil(job, "indefinite", 0);
+
+ job->state->values[0].integer = IPP_JOB_HELD;
+ job->state_value = IPP_JOB_HELD;
+
+ ippSetString(job->attrs, &job->reasons, 0, "job-held-on-create");
+ }
+ else if (attr && strcmp(attr->values[0].string.text, "no-hold"))
{
/*
* Hold job until specified time...
attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets",
2, NULL, NULL);
- attr->values[0].string.text = _cupsStrRetain(printer->job_sheets[0]);
- attr->values[1].string.text = _cupsStrRetain(printer->job_sheets[1]);
+ ippSetString(job->attrs, &attr, 0, printer->job_sheets[0]);
+ ippSetString(job->attrs, &attr, 1, printer->job_sheets[1]);
}
job->job_sheets = attr;
* Force the leading banner to have the classification on it...
*/
- cupsdSetString(&attr->values[0].string.text, Classification);
+ ippSetString(job->attrs, &attr, 0, Classification);
cupsdLogJob(job, CUPSD_LOG_NOTICE, "CLASSIFICATION FORCED "
"job-sheets=\"%s,none\", "
* Can't put two different security markings on the same document!
*/
- cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text);
+ ippSetString(job->attrs, &attr, 1, attr->values[0].string.text);
cupsdLogJob(job, CUPSD_LOG_NOTICE, "CLASSIFICATION FORCED "
"job-sheets=\"%s,%s\", "
if (attr->num_values > 1 &&
!strcmp(attr->values[0].string.text, attr->values[1].string.text))
{
- cupsdSetString(&(attr->values[0].string.text), Classification);
- cupsdSetString(&(attr->values[1].string.text), Classification);
+ ippSetString(job->attrs, &attr, 0, Classification);
+ ippSetString(job->attrs, &attr, 1, Classification);
}
else
{
if (attr->num_values == 1 ||
strcmp(attr->values[0].string.text, "none"))
- cupsdSetString(&(attr->values[0].string.text), Classification);
+ ippSetString(job->attrs, &attr, 0, Classification);
if (attr->num_values > 1 &&
strcmp(attr->values[1].string.text, "none"))
- cupsdSetString(&(attr->values[1].string.text), Classification);
+ ippSetString(job->attrs, &attr, 1, Classification);
}
if (attr->num_values > 1)
ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
job->state_value);
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_TEXT, "job-state-message", NULL, "");
ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons",
NULL, job->reasons->values[0].string.text);
host[HTTP_MAX_URI], /* Host portion of URI */
resource[HTTP_MAX_URI]; /* Resource portion of URI */
int port; /* Port portion of URI */
-
+ struct stat info; /* File information */
recipient = attr->values[0].string.text;
return;
}
- snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin,
- scheme);
- if (access(notifier, X_OK))
+ snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin, scheme);
+ if (access(notifier, X_OK) || stat(notifier, &info) || !S_ISREG(info.st_mode))
{
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("notify-recipient-uri URI \"%s\" uses unknown "
{
sub->user_data_len = user_data->values[0].unknown.length;
memcpy(sub->user_data, user_data->values[0].unknown.data,
- sub->user_data_len);
+ (size_t)sub->user_data_len);
}
ippAddSeparator(con->response);
if (!ippFindAttribute(job->attrs, "job-uuid", IPP_TAG_URI))
ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-uuid", NULL,
- _httpAssembleUUID(ServerName, RemotePort, job->dest, job->id,
- uuid, sizeof(uuid)));
+ httpAssembleUUID(ServerName, RemotePort, job->dest, job->id,
+ uuid, sizeof(uuid)));
}
char srcfile[1024], /* Source Script/PPD file */
dstfile[1024]; /* Destination Script/PPD file */
int modify; /* Non-zero if we are modifying */
- int changed_driver, /* Changed the PPD/interface script? */
+ int changed_driver, /* Changed the PPD? */
need_restart_job, /* Need to restart job? */
set_device_uri, /* Did we set the device URI? */
set_port_monitor; /* Did we set the port monitor? */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Do we have a valid URI?
printer = cupsdAddPrinter(resource + 10);
modify = 0;
+
+ printer->printer_id = NextPrinterId ++;
}
else if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
NULL)) != HTTP_OK)
changed_driver = 0;
need_restart_job = 0;
+ if ((attr = ippFindAttribute(con->request, "printer-is-temporary", IPP_TAG_BOOLEAN)) != NULL)
+ printer->temporary = ippGetBoolean(attr, 0);
+
if ((attr = ippFindAttribute(con->request, "printer-location",
IPP_TAG_TEXT)) != NULL)
cupsdSetString(&printer->location, attr->values[0].string.text);
+ if ((attr = ippFindAttribute(con->request, "printer-geo-location", IPP_TAG_URI)) != NULL && !strncmp(attr->values[0].string.text, "geo:", 4))
+ cupsdSetString(&printer->geo_location, attr->values[0].string.text);
+
+ if ((attr = ippFindAttribute(con->request, "printer-organization", IPP_TAG_TEXT)) != NULL)
+ cupsdSetString(&printer->organization, attr->values[0].string.text);
+
+ if ((attr = ippFindAttribute(con->request, "printer-organizational-unit", IPP_TAG_TEXT)) != NULL)
+ cupsdSetString(&printer->organizational_unit, attr->values[0].string.text);
+
if ((attr = ippFindAttribute(con->request, "printer-info",
IPP_TAG_TEXT)) != NULL)
cupsdSetString(&printer->info, attr->values[0].string.text);
http_uri_status_t uri_status; /* URI separation status */
char old_device_uri[1024];
/* Old device URI */
- static const char * const uri_status_strings[] =
- {
- "URI too large.",
- "Bad arguments to function.",
- "Bad resource path.",
- "Bad port number.",
- "Bad hostname/address.",
- "Bad username/password.",
- "Bad URI scheme.",
- "Bad URI.",
- "OK",
- "Missing URI scheme.",
- "Unknown URI scheme",
- "Missing resource path."
- };
-
need_restart_job = 1;
host, sizeof(host), &port,
resource, sizeof(resource));
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "%s device-uri: %s", printer->name,
- uri_status_strings[uri_status - HTTP_URI_STATUS_OVERFLOW]);
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "%s device-uri: %s", printer->name, httpURIStatusString(uri_status));
if (uri_status < HTTP_URI_OK)
{
send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"."),
attr->values[0].string.text);
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
"To enable, see the FileDevice directive in "
"\"%s/cups-files.conf\"."),
ServerRoot);
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
}
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("Bad device-uri scheme \"%s\"."), scheme);
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
}
{
send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"."),
attr->values[0].string.text);
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
printer->accepting ? "Now" : "No longer");
}
- if ((attr = ippFindAttribute(con->request, "printer-is-shared",
- IPP_TAG_BOOLEAN)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-is-shared", IPP_TAG_BOOLEAN)) != NULL)
{
- if (attr->values[0].boolean &&
+ if (ippGetBoolean(attr, 0) &&
printer->num_auth_info_required == 1 &&
!strcmp(printer->auth_info_required[0], "negotiate"))
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Cannot share a remote Kerberized printer."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
+ return;
+ }
+
+ if (printer->type & CUPS_PRINTER_REMOTE)
+ {
+ /*
+ * Cannot re-share remote printers.
+ */
+
+ send_ipp_status(con, IPP_BAD_REQUEST, _("Cannot change printer-is-shared for remote queues."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
- if (printer->shared && !attr->values[0].boolean)
+ if (printer->shared && !ippGetBoolean(attr, 0))
cupsdDeregisterPrinter(printer, 1);
cupsdLogMessage(CUPSD_LOG_INFO,
"Setting %s printer-is-shared to %d (was %d.)",
printer->name, attr->values[0].boolean, printer->shared);
- printer->shared = attr->values[0].boolean;
+ printer->shared = ippGetBoolean(attr, 0);
+ if (printer->shared && printer->temporary)
+ printer->temporary = 0;
}
if ((attr = ippFindAttribute(con->request, "printer-state",
{
send_ipp_status(con, IPP_BAD_REQUEST, _("Bad printer-state value %d."),
attr->values[0].integer);
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
attr->num_values,
(int)(sizeof(printer->reasons) /
sizeof(printer->reasons[0])));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
"Printer \"%s\" state changed.", printer->name);
}
- set_printer_defaults(con, printer);
+ if (!set_printer_defaults(con, printer))
+ {
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
+ return;
+ }
if ((attr = ippFindAttribute(con->request, "auth-info-required",
IPP_TAG_KEYWORD)) != NULL)
cupsdSetString(&printer->device_uri, "file:///dev/null");
/*
- * See if we have an interface script or PPD file attached to the request...
+ * See if we have a PPD file attached to the request...
*/
if (con->filename)
* Then see what kind of file it is...
*/
- snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
- printer->name);
-
- if (!strncmp(line, "*PPD-Adobe", 10))
+ if (strncmp(line, "*PPD-Adobe", 10))
{
- /*
- * The new file is a PPD file, so remove any old interface script
- * that might be lying around...
- */
+ send_ipp_status(con, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED, _("Bad PPD file."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
- unlink(dstfile);
- }
- else
- {
- /*
- * This must be an interface script, so move the file over to the
- * interfaces directory and make it executable...
- */
-
- if (copy_file(srcfile, dstfile))
- {
- send_ipp_status(con, IPP_INTERNAL_ERROR,
- _("Unable to copy interface script - %s"),
- strerror(errno));
- return;
- }
-
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "Copied interface script successfully");
- chmod(dstfile, 0755);
+ return;
}
snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
printer->name);
- if (!strncmp(line, "*PPD-Adobe", 10))
- {
- /*
- * The new file is a PPD file, so move the file over to the
- * ppd directory and make it readable by all...
- */
-
- if (copy_file(srcfile, dstfile))
- {
- send_ipp_status(con, IPP_INTERNAL_ERROR,
- _("Unable to copy PPD file - %s"),
- strerror(errno));
- return;
- }
+ /*
+ * The new file is a PPD file, so move the file over to the ppd
+ * directory...
+ */
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "Copied PPD file successfully");
- chmod(dstfile, 0644);
- }
- else
+ if (copy_file(srcfile, dstfile, ConfigFilePerm))
{
- /*
- * This must be an interface script, so remove any old PPD file that
- * may be lying around...
- */
+ send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file - %s"), strerror(errno));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
- unlink(dstfile);
+ return;
}
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Copied PPD file successfully");
}
}
- else if ((attr = ippFindAttribute(con->request, "ppd-name",
- IPP_TAG_NAME)) != NULL)
+ else if ((attr = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME)) != NULL)
{
+ const char *ppd_name = ippGetString(attr, 0, NULL);
+ /* ppd-name value */
+
need_restart_job = 1;
changed_driver = 1;
- if (!strcmp(attr->values[0].string.text, "raw"))
+ if (!strcmp(ppd_name, "raw"))
{
/*
- * Raw driver, remove any existing PPD or interface script files.
+ * Raw driver, remove any existing PPD file.
*/
- snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
- printer->name);
+ snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot, printer->name);
unlink(dstfile);
+ }
+ else if (strstr(ppd_name, "../"))
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Invalid ppd-name value."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
- snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
- printer->name);
- unlink(dstfile);
+ return;
}
else
{
* PPD model file...
*/
- snprintf(dstfile, sizeof(dstfile), "%s/interfaces/%s", ServerRoot,
- printer->name);
- unlink(dstfile);
-
- snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot,
- printer->name);
+ snprintf(dstfile, sizeof(dstfile), "%s/ppd/%s.ppd", ServerRoot, printer->name);
- if (copy_model(con, attr->values[0].string.text, dstfile))
+ if (copy_model(con, ppd_name, dstfile))
{
send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "Copied PPD file successfully");
- chmod(dstfile, 0644);
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Copied PPD file successfully");
}
}
if (changed_driver)
{
/*
- * If we changed the PPD/interface script, then remove the printer's cache
- * file and clear the printer-state-reasons...
+ * If we changed the PPD, then remove the printer's cache file and clear the
+ * printer-state-reasons...
*/
char cache_name[1024]; /* Cache filename for printer attrs */
- snprintf(cache_name, sizeof(cache_name), "%s/%s.data", CacheDir,
- printer->name);
+ snprintf(cache_name, sizeof(cache_name), "%s/%s.data", CacheDir, printer->name);
unlink(cache_name);
cupsdSetPrinterReasons(printer, "none");
}
}
+ printer->config_time = time(NULL);
+
/*
* Update the printer attributes and return...
*/
+ if (!printer->temporary)
+ {
+ if (!printer->printer_id)
+ printer->printer_id = NextPrinterId ++;
+
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
+ }
+
cupsdSetPrinterAttrs(printer);
- cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
if (need_restart_job && printer->job)
{
{
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"add_printer_state_reasons(%p[%d], %p[%s])",
- con, con->http.fd, p, p->name);
+ con, con->number, p, p->name);
if (p->num_reasons == 0)
ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_queued_job_count(%p[%d], %p[%s])",
- con, con->http.fd, p, p->name);
+ con, con->number, p, p->name);
count = cupsdGetPrinterJobCount(p->name);
*option; /* Current option */
+ cupsdLogJob(job, CUPSD_LOG_DEBUG, "Applying default options...");
+
/*
* Collect all of the default options and add the missing ones to the
* job object...
i --, option ++)
if (!ippFindAttribute(job->attrs, option->name, IPP_TAG_ZERO))
{
- num_options = cupsAddOption(option->name, option->value, num_options,
- &options);
+ if (!strcmp(option->name, "print-quality") && ippFindAttribute(job->attrs, "cupsPrintQuality", IPP_TAG_NAME))
+ continue; /* Don't override cupsPrintQuality */
+
+ cupsdLogJob(job, CUPSD_LOG_DEBUG, "Adding default %s=%s", option->name, option->value);
+
+ num_options = cupsAddOption(option->name, option->value, num_options, &options);
}
/*
cupsdLogMessage(CUPSD_LOG_DEBUG2, "authenticate_job(%p[%d], %s)",
- con, con->http.fd, uri->values[0].string.text);
+ con, con->number, uri->values[0].string.text);
/*
* Start with "everything is OK" status...
if (attr)
{
- attr->value_tag = IPP_TAG_KEYWORD;
- cupsdSetString(&(attr->values[0].string.text), "no-hold");
+ ippSetValueTag(job->attrs, &attr, IPP_TAG_KEYWORD);
+ ippSetString(job->attrs, &attr, 0, "no-hold");
}
/*
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_all_jobs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Get the jobs to cancel/purge...
}
con->response->request.status.status_code = IPP_OK;
+
+ cupsdCheckJobs();
}
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cancel_job(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* See if we have a job URI or a printer URI...
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"cancel_subscription(con=%p[%d], sub_id=%d)",
- con, con->http.fd, sub_id);
+ con, con->number, sub_id);
/*
* Is the subscription ID valid?
cupsdLogMessage(CUPSD_LOG_DEBUG2, "check_quotas(%p[%d], %p[%s])",
- con, con->http.fd, p, p->name);
+ con, con->number, p, p->name);
/*
* Figure out who is printing...
cupsdLogMessage(CUPSD_LOG_DEBUG2, "close_job(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* See if we have a job URI or a printer URI...
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"copy_banner(con=%p[%d], job=%p[%d], name=\"%s\")",
- con, con ? con->http.fd : -1, job, job->id,
+ con, con ? con->number : -1, job, job->id,
name ? name : "(null)");
/*
*/
attrname[2] = '_';
- attrname[3] = toupper(attrname[3] & 255);
- attrname[4] = toupper(attrname[4] & 255);
+ attrname[3] = (char)toupper(attrname[3] & 255);
+ attrname[4] = (char)toupper(attrname[4] & 255);
}
snprintf(filename, sizeof(filename), "%s/banners/%s/%s", DataDir,
if (!isalpha(ch & 255) && ch != '-' && ch != '?')
break;
else if (s < (attrname + sizeof(attrname) - 1))
- *s++ = ch;
+ *s++ = (char)ch;
else
break;
kbytes = (cupsFileTell(out) + 1023) / 1024;
- if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
- IPP_TAG_INTEGER)) != NULL)
+ job->koctets += kbytes;
+
+ if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
attr->values[0].integer += kbytes;
cupsFileClose(out);
/*
- * 'copy_file()' - Copy a PPD file or interface script...
+ * 'copy_file()' - Copy a PPD file...
*/
static int /* O - 0 = success, -1 = error */
copy_file(const char *from, /* I - Source file */
- const char *to) /* I - Destination file */
+ const char *to, /* I - Destination file */
+ mode_t mode) /* I - Permissions */
{
cups_file_t *src, /* Source file */
*dst; /* Destination file */
if ((src = cupsFileOpen(from, "rb")) == NULL)
return (-1);
- if ((dst = cupsFileOpen(to, "wb")) == NULL)
+ if ((dst = cupsdCreateConfFile(to, mode)) == NULL)
{
cupsFileClose(src);
return (-1);
*/
while ((bytes = cupsFileRead(src, buffer, sizeof(buffer))) > 0)
- if (cupsFileWrite(dst, buffer, bytes) < bytes)
+ if (cupsFileWrite(dst, buffer, (size_t)bytes) < bytes)
{
cupsFileClose(src);
cupsFileClose(dst);
cupsFileClose(src);
- return (cupsFileClose(dst));
+ return (cupsdCloseCreatedConfFile(dst, to));
}
/* cupsProtocol attribute */
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "copy_model(con=%p, from=\"%s\", to=\"%s\")",
- con, from, to);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_model(con=%p, from=\"%s\", to=\"%s\")", con, from, to);
/*
* Run cups-driverd to get the PPD file...
cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
snprintf(buffer, sizeof(buffer), "%s/daemon/cups-driverd", ServerBin);
- snprintf(tempfile, sizeof(tempfile), "%s/%d.ppd", TempDir, con->http.fd);
+ snprintf(tempfile, sizeof(tempfile), "%s/%d.ppd", TempDir, con->number);
tempfd = open(tempfile, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (tempfd < 0 || cupsdOpenPipe(temppipe))
return (-1);
if ((bytes = read(temppipe[0], buffer, sizeof(buffer))) > 0)
{
- if (write(tempfd, buffer, bytes) < bytes)
+ if (write(tempfd, buffer, (size_t)bytes) < bytes)
break;
total += bytes;
* Open the destination file for a copy...
*/
- if ((dst = cupsFileOpen(to, "wb")) == NULL)
+ if ((dst = cupsdCreateConfFile(to, ConfigFilePerm)) == NULL)
{
cupsFreeOptions(num_defaults, defaults);
cupsFileClose(src);
unlink(tempfile);
- return (cupsFileClose(dst));
+ return (cupsdCloseCreatedConfFile(dst, to));
}
"job-uri", NULL, job_uri);
}
- copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0, exclude);
+ if (job->attrs)
+ {
+ copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0, exclude);
+ }
+ else
+ {
+ /*
+ * Generate attributes from the job structure...
+ */
+
+ if (job->completed_time && (!ra || cupsArrayFind(ra, "date-time-at-completed")))
+ ippAddDate(con->response, IPP_TAG_JOB, "date-time-at-completed", ippTimeToDate(job->completed_time));
+
+ if (job->creation_time && (!ra || cupsArrayFind(ra, "date-time-at-creation")))
+ ippAddDate(con->response, IPP_TAG_JOB, "date-time-at-creation", ippTimeToDate(job->creation_time));
+
+ if (!ra || cupsArrayFind(ra, "job-id"))
+ ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
+
+ if (!ra || cupsArrayFind(ra, "job-k-octets"))
+ ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-k-octets", job->koctets);
+
+ if (job->name && (!ra || cupsArrayFind(ra, "job-name")))
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, job->name);
+
+ if (job->username && (!ra || cupsArrayFind(ra, "job-originating-user-name")))
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_NAME, "job-originating-user-name", NULL, job->username);
+
+ if (!ra || cupsArrayFind(ra, "job-state"))
+ ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state", (int)job->state_value);
+
+ if (!ra || cupsArrayFind(ra, "job-state-reasons"))
+ {
+ switch (job->state_value)
+ {
+ default : /* Should never get here for processing, pending, held, or stopped jobs since they don't get unloaded... */
+ break;
+ case IPP_JSTATE_ABORTED :
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-aborted-by-system");
+ break;
+ case IPP_JSTATE_CANCELED :
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-canceled-by-user");
+ break;
+ case IPP_JSTATE_COMPLETED :
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, "job-completed-successfully");
+ break;
+ }
+ }
+
+ if (job->completed_time && (!ra || cupsArrayFind(ra, "time-at-completed")))
+ ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-completed", (int)job->completed_time);
+
+ if (job->creation_time && (!ra || cupsArrayFind(ra, "time-at-creation")))
+ ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation", (int)job->creation_time);
+ }
}
cupsd_printer_t *printer, /* I - Printer */
cups_array_t *ra) /* I - Requested attributes array */
{
- char printer_uri[HTTP_MAX_URI];
- /* Printer URI */
- char printer_icons[HTTP_MAX_URI];
- /* Printer icons */
- time_t curtime; /* Current time */
- int i; /* Looping var */
+ char uri[HTTP_MAX_URI]; /* URI value */
+ time_t curtime; /* Current time */
+ int i; /* Looping var */
+ int is_encrypted = httpIsEncrypted(con->http);
+ /* Is the connection encrypted? */
/*
* and document-format attributes that may be provided by the client.
*/
+ _cupsRWLockRead(&printer->lock);
+
curtime = time(NULL);
if (!ra || cupsArrayFind(ra, "marker-change-time"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "marker-change-time", printer->marker_time);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "marker-change-time", printer->marker_time);
- if (printer->num_printers > 0 &&
- (!ra || cupsArrayFind(ra, "member-uris")))
+ if (printer->num_printers > 0 && (!ra || cupsArrayFind(ra, "member-uris")))
{
ipp_attribute_t *member_uris; /* member-uris attribute */
cupsd_printer_t *p2; /* Printer in class */
ipp_attribute_t *p2_uri; /* printer-uri-supported for class printer */
- if ((member_uris = ippAddStrings(con->response, IPP_TAG_PRINTER,
- IPP_TAG_URI, "member-uris",
- printer->num_printers, NULL,
- NULL)) != NULL)
+ if ((member_uris = ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "member-uris", printer->num_printers, NULL, NULL)) != NULL)
{
for (i = 0; i < printer->num_printers; i ++)
{
p2 = printer->printers[i];
- if ((p2_uri = ippFindAttribute(p2->attrs, "printer-uri-supported",
- IPP_TAG_URI)) != NULL)
- member_uris->values[i].string.text =
- _cupsStrRetain(p2_uri->values[0].string.text);
+ if ((p2_uri = ippFindAttribute(p2->attrs, "printer-uri-supported", IPP_TAG_URI)) != NULL)
+ {
+ member_uris->values[i].string.text = _cupsStrRetain(p2_uri->values[0].string.text);
+ }
else
{
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri,
- sizeof(printer_uri), "ipp", NULL, con->clientname,
- con->clientport,
- (p2->type & CUPS_PRINTER_CLASS) ?
- "/classes/%s" : "/printers/%s", p2->name);
- member_uris->values[i].string.text = _cupsStrAlloc(printer_uri);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "ipps" : "ipp", NULL, con->clientname, con->clientport, (p2->type & CUPS_PRINTER_CLASS) ? "/classes/%s" : "/printers/%s", p2->name);
+ member_uris->values[i].string.text = _cupsStrAlloc(uri);
}
}
}
}
if (printer->alert && (!ra || cupsArrayFind(ra, "printer-alert")))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_STRING,
- "printer-alert", NULL, printer->alert);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_STRING, "printer-alert", NULL, printer->alert);
+
+ if (printer->alert_description && (!ra || cupsArrayFind(ra, "printer-alert-description")))
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-alert-description", NULL, printer->alert_description);
+
+ if (!ra || cupsArrayFind(ra, "printer-config-change-date-time"))
+ ippAddDate(con->response, IPP_TAG_PRINTER, "printer-config-change-date-time", ippTimeToDate(printer->config_time));
- if (printer->alert_description &&
- (!ra || cupsArrayFind(ra, "printer-alert-description")))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-alert-description", NULL,
- printer->alert_description);
+ if (!ra || cupsArrayFind(ra, "printer-config-change-time"))
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "printer-config-change-time", printer->config_time);
if (!ra || cupsArrayFind(ra, "printer-current-time"))
- ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
- ippTimeToDate(curtime));
+ ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time", ippTimeToDate(curtime));
#if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
if (!ra || cupsArrayFind(ra, "printer-dns-sd-name"))
{
if (printer->reg_name)
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-dns-sd-name", NULL, printer->reg_name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-dns-sd-name", NULL, printer->reg_name);
else
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE,
- "printer-dns-sd-name", 0);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_NOVALUE, "printer-dns-sd-name", 0);
}
#endif /* HAVE_DNSSD || HAVE_AVAHI */
if (!ra || cupsArrayFind(ra, "printer-error-policy"))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-error-policy", NULL, printer->error_policy);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-error-policy", NULL, printer->error_policy);
if (!ra || cupsArrayFind(ra, "printer-error-policy-supported"))
{
static const char * const errors[] =/* printer-error-policy-supported values */
- {
- "abort-job",
- "retry-current-job",
- "retry-job",
- "stop-printer"
- };
+ {
+ "abort-job",
+ "retry-current-job",
+ "retry-job",
+ "stop-printer"
+ };
if (printer->type & CUPS_PRINTER_CLASS)
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
- "printer-error-policy-supported", NULL, "retry-current-job");
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_NAME), "printer-error-policy-supported", NULL, "retry-current-job");
else
- ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
- "printer-error-policy-supported",
- sizeof(errors) / sizeof(errors[0]), NULL, errors);
+ ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_NAME), "printer-error-policy-supported", sizeof(errors) / sizeof(errors[0]), NULL, errors);
}
if (!ra || cupsArrayFind(ra, "printer-icons"))
{
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_icons, sizeof(printer_icons),
- "http", NULL, con->clientname, con->clientport,
- "/icons/%s.png", printer->name);
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-icons",
- NULL, printer_icons);
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-icons=\"%s\"", printer_icons);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "https" : "http", NULL, con->clientname, con->clientport, "/icons/%s.png", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-icons", NULL, uri);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-icons=\"%s\"", uri);
}
if (!ra || cupsArrayFind(ra, "printer-is-accepting-jobs"))
- ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
- printer->accepting);
+ ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs", (char)printer->accepting);
if (!ra || cupsArrayFind(ra, "printer-is-shared"))
- ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared",
- printer->shared);
+ ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared", (char)printer->shared);
+
+ if (!ra || cupsArrayFind(ra, "printer-is-temporary"))
+ ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-temporary", (char)printer->temporary);
if (!ra || cupsArrayFind(ra, "printer-more-info"))
{
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
- "http", NULL, con->clientname, con->clientport,
- (printer->type & CUPS_PRINTER_CLASS) ?
- "/classes/%s" : "/printers/%s", printer->name);
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI,
- "printer-more-info", NULL, printer_uri);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "https" : "http", NULL, con->clientname, con->clientport, (printer->type & CUPS_PRINTER_CLASS) ? "/classes/%s" : "/printers/%s", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info", NULL, uri);
}
if (!ra || cupsArrayFind(ra, "printer-op-policy"))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-op-policy", NULL, printer->op_policy);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-op-policy", NULL, printer->op_policy);
if (!ra || cupsArrayFind(ra, "printer-state"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
- printer->state);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", printer->state);
+
+ if (!ra || cupsArrayFind(ra, "printer-state-change-date-time"))
+ ippAddDate(con->response, IPP_TAG_PRINTER, "printer-state-change-date-time", ippTimeToDate(printer->state_time));
if (!ra || cupsArrayFind(ra, "printer-state-change-time"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-state-change-time", printer->state_time);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "printer-state-change-time", printer->state_time);
if (!ra || cupsArrayFind(ra, "printer-state-message"))
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-state-message", NULL, printer->state_message);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-state-message", NULL, printer->state_message);
if (!ra || cupsArrayFind(ra, "printer-state-reasons"))
add_printer_state_reasons(con, printer);
+ if (!ra || cupsArrayFind(ra, "printer-strings-uri"))
+ {
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "https" : "http", NULL, con->clientname, con->clientport, "/strings/%s.strings", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-strings-uri", NULL, uri);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-strings-uri=\"%s\"", uri);
+ }
+
if (!ra || cupsArrayFind(ra, "printer-type"))
{
- int type; /* printer-type value */
+ cups_ptype_t type; /* printer-type value */
/*
* Add the CUPS-specific printer-type attribute...
if (!printer->shared)
type |= CUPS_PRINTER_NOT_SHARED;
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type",
- type);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type", (int)type);
}
if (!ra || cupsArrayFind(ra, "printer-up-time"))
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-up-time", curtime);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "printer-up-time", curtime);
if (!ra || cupsArrayFind(ra, "printer-uri-supported"))
{
- httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
- "ipp", NULL, con->clientname, con->clientport,
- (printer->type & CUPS_PRINTER_CLASS) ?
- "/classes/%s" : "/printers/%s", printer->name);
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI,
- "printer-uri-supported", NULL, printer_uri);
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-uri-supported=\"%s\"",
- printer_uri);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), is_encrypted ? "ipps" : "ipp", NULL, con->clientname, con->clientport, (printer->type & CUPS_PRINTER_CLASS) ? "/classes/%s" : "/printers/%s", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uri-supported", NULL, uri);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "printer-uri-supported=\"%s\"", uri);
}
if (!ra || cupsArrayFind(ra, "queued-job-count"))
if (printer->ppd_attrs)
copy_attrs(con->response, printer->ppd_attrs, ra, IPP_TAG_ZERO, 0, NULL);
copy_attrs(con->response, CommonData, ra, IPP_TAG_ZERO, IPP_TAG_COPY, NULL);
+
+ _cupsRWUnlock(&printer->lock);
}
* Simple event list...
*/
- ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
- (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
- "notify-events", NULL, name);
+ ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_CONST_TAG(IPP_TAG_KEYWORD), "notify-events", NULL, name);
}
else
{
if (sub->mask & mask)
count ++;
- attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
- (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
- "notify-events", count, NULL, NULL);
+ attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION, IPP_CONST_TAG(IPP_TAG_KEYWORD), "notify-events", count, NULL, NULL);
for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
if (sub->mask & mask)
{
- attr->values[count].string.text =
- (char *)cupsdEventName((cupsd_eventmask_t)mask);
+ attr->values[count].string.text = (char *)cupsdEventName((cupsd_eventmask_t)mask);
count ++;
}
cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
* Save and log the job...
*/
- cupsdLogJob(job, CUPSD_LOG_INFO, "Queued on \"%s\" by \"%s\".",
- job->dest, job->username);
+ cupsdLogJob(job, CUPSD_LOG_INFO, "Queued on \"%s\" by \"%s\".",
+ job->dest, job->username);
+}
+
+
+/*
+ * 'create_local_bg_thread()' - Background thread for creating a local print queue.
+ */
+
+static void * /* O - Exit status */
+create_local_bg_thread(
+ cupsd_printer_t *printer) /* I - Printer */
+{
+ cups_file_t *from, /* Source file */
+ *to; /* Destination file */
+ char fromppd[1024], /* Source PPD */
+ toppd[1024], /* Destination PPD */
+ scheme[32], /* URI scheme */
+ userpass[256], /* User:pass */
+ host[256], /* Hostname */
+ resource[1024], /* Resource path */
+ line[1024]; /* Line from PPD */
+ int port; /* Port number */
+ http_encryption_t encryption; /* Type of encryption to use */
+ http_t *http; /* Connection to printer */
+ ipp_t *request, /* Request to printer */
+ *response; /* Response from printer */
+ ipp_attribute_t *attr; /* Attribute in response */
+ ipp_status_t status; /* Status code */
+
+
+ /*
+ * Try connecting to the printer...
+ */
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Generating PPD file from \"%s\"...", printer->name, printer->device_uri);
+
+ if (httpSeparateURI(HTTP_URI_CODING_ALL, printer->device_uri, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Bad device URI \"%s\".", printer->name, printer->device_uri);
+ return (NULL);
+ }
+
+ if (!strcmp(scheme, "ipps") || port == 443)
+ encryption = HTTP_ENCRYPTION_ALWAYS;
+ else
+ encryption = HTTP_ENCRYPTION_IF_REQUESTED;
+
+ if ((http = httpConnect2(host, port, NULL, AF_UNSPEC, encryption, 1, 30000, NULL)) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Unable to connect to %s:%d: %s", printer->name, host, port, cupsLastErrorString());
+ return (NULL);
+ }
+
+ /*
+ * Query the printer for its capabilities...
+ */
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer->name, host, port);
+
+ request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
+ ippSetVersion(request, 2, 0);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer->device_uri);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "all");
+
+ response = cupsDoRequest(http, request, resource);
+ status = cupsLastError();
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Get-Printer-Attributes returned %s (%s)", printer->name, ippErrorString(cupsLastError()), cupsLastErrorString());
+
+ if (status == IPP_STATUS_ERROR_BAD_REQUEST || status == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
+ {
+ /*
+ * Try request using IPP/1.1, in case we are talking to an old CUPS server or
+ * printer...
+ */
+
+ ippDelete(response);
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Re-sending Get-Printer-Attributes request using IPP/1.1...", printer->name);
+
+ request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
+ ippSetVersion(request, 1, 1);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer->device_uri);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "all");
+
+ response = cupsDoRequest(http, request, resource);
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: IPP/1.1 Get-Printer-Attributes returned %s (%s)", printer->name, ippErrorString(cupsLastError()), cupsLastErrorString());
+ }
+
+ // TODO: Grab printer icon file...
+ httpClose(http);
+
+ /*
+ * Write the PPD for the queue...
+ */
+
+ if (_ppdCreateFromIPP(fromppd, sizeof(fromppd), response))
+ {
+ _cupsRWLockWrite(&printer->lock);
+
+ if ((!printer->info || !*(printer->info)) && (attr = ippFindAttribute(response, "printer-info", IPP_TAG_TEXT)) != NULL)
+ cupsdSetString(&printer->info, ippGetString(attr, 0, NULL));
+
+ if ((!printer->location || !*(printer->location)) && (attr = ippFindAttribute(response, "printer-location", IPP_TAG_TEXT)) != NULL)
+ cupsdSetString(&printer->location, ippGetString(attr, 0, NULL));
+
+ if ((!printer->geo_location || !*(printer->geo_location)) && (attr = ippFindAttribute(response, "printer-geo-location", IPP_TAG_URI)) != NULL)
+ cupsdSetString(&printer->geo_location, ippGetString(attr, 0, NULL));
+
+ _cupsRWUnlock(&printer->lock);
+
+ if ((from = cupsFileOpen(fromppd, "r")) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Unable to read generated PPD: %s", printer->name, strerror(errno));
+ return (NULL);
+ }
+
+ snprintf(toppd, sizeof(toppd), "%s/ppd/%s.ppd", ServerRoot, printer->name);
+ if ((to = cupsdCreateConfFile(toppd, ConfigFilePerm)) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Unable to create PPD for printer: %s", printer->name, strerror(errno));
+ cupsFileClose(from);
+ return (NULL);
+ }
+
+ while (cupsFileGets(from, line, sizeof(line)))
+ cupsFilePrintf(to, "%s\n", line);
+
+ cupsFileClose(from);
+ if (!cupsdCloseCreatedConfFile(to, toppd))
+ {
+ printer->config_time = time(NULL);
+ printer->state = IPP_PSTATE_IDLE;
+ printer->accepting = 1;
+
+ cupsdSetPrinterAttrs(printer);
+
+ cupsdAddEvent(CUPSD_EVENT_PRINTER_CONFIG, printer, NULL, "Printer \"%s\" is now available.", printer->name);
+ cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" is now available.", printer->name);
+ }
+ }
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s: PPD creation failed: %s", printer->name, cupsLastErrorString());
+
+ return (NULL);
+}
+
+
+/*
+ * 'create_local_printer()' - Create a local (temporary) print queue.
+ */
+
+static void
+create_local_printer(
+ cupsd_client_t *con) /* I - Client connection */
+{
+ ipp_attribute_t *device_uri, /* device-uri attribute */
+ *printer_geo_location, /* printer-geo-location attribute */
+ *printer_info, /* printer-info attribute */
+ *printer_location, /* printer-location attribute */
+ *printer_name; /* printer-name attribute */
+ cupsd_printer_t *printer; /* New printer */
+ http_status_t status; /* Policy status */
+ char name[128], /* Sanitized printer name */
+ *nameptr, /* Pointer into name */
+ uri[1024]; /* printer-uri-supported value */
+ const char *ptr; /* Pointer into attribute value */
+
+
+ /*
+ * Require local access to create a local printer...
+ */
+
+ if (!httpAddrLocalhost(httpGetAddress(con->http)))
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_FORBIDDEN, _("Only local users can create a local printer."));
+ return;
+ }
+
+ /*
+ * Check any other policy limits...
+ */
+
+ if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+ {
+ send_http_error(con, status, NULL);
+ return;
+ }
+
+ /*
+ * Grab needed attributes...
+ */
+
+ if ((printer_name = ippFindAttribute(con->request, "printer-name", IPP_TAG_ZERO)) == NULL || ippGetGroupTag(printer_name) != IPP_TAG_PRINTER || ippGetValueTag(printer_name) != IPP_TAG_NAME)
+ {
+ if (!printer_name)
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("Missing required attribute \"%s\"."), "printer-name");
+ else if (ippGetGroupTag(printer_name) != IPP_TAG_PRINTER)
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("Attribute \"%s\" is in the wrong group."), "printer-name");
+ else
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("Attribute \"%s\" is the wrong value type."), "printer-name");
+
+ return;
+ }
+
+ for (nameptr = name, ptr = ippGetString(printer_name, 0, NULL); *ptr && nameptr < (name + sizeof(name) - 1); ptr ++)
+ {
+ /*
+ * Sanitize the printer name...
+ */
+
+ if (_cups_isalnum(*ptr))
+ *nameptr++ = *ptr;
+ else if (nameptr == name || nameptr[-1] != '_')
+ *nameptr++ = '_';
+ }
+
+ *nameptr = '\0';
+
+ if ((device_uri = ippFindAttribute(con->request, "device-uri", IPP_TAG_ZERO)) == NULL || ippGetGroupTag(device_uri) != IPP_TAG_PRINTER || ippGetValueTag(device_uri) != IPP_TAG_URI)
+ {
+ if (!device_uri)
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("Missing required attribute \"%s\"."), "device-uri");
+ else if (ippGetGroupTag(device_uri) != IPP_TAG_PRINTER)
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("Attribute \"%s\" is in the wrong group."), "device-uri");
+ else
+ send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("Attribute \"%s\" is the wrong value type."), "device-uri");
+
+ return;
+ }
+
+ printer_geo_location = ippFindAttribute(con->request, "printer-geo-location", IPP_TAG_URI);
+ printer_info = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT);
+ printer_location = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT);
+
+ /*
+ * See if the printer already exists...
+ */
+
+ if ((printer = cupsdFindDest(name)) != NULL)
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_NOT_POSSIBLE, _("Printer \"%s\" already exists."), name);
+ goto add_printer_attributes;
+ }
+
+ /*
+ * Create the printer...
+ */
+
+ if ((printer = cupsdAddPrinter(name)) == NULL)
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_INTERNAL, _("Unable to create printer."));
+ return;
+ }
+
+ printer->shared = 0;
+ printer->temporary = 1;
+
+ cupsdSetDeviceURI(printer, ippGetString(device_uri, 0, NULL));
+
+ if (printer_geo_location)
+ cupsdSetString(&printer->geo_location, ippGetString(printer_geo_location, 0, NULL));
+ if (printer_info)
+ cupsdSetString(&printer->info, ippGetString(printer_info, 0, NULL));
+ if (printer_location)
+ cupsdSetString(&printer->location, ippGetString(printer_location, 0, NULL));
+
+ cupsdSetPrinterAttrs(printer);
+
+ /*
+ * Run a background thread to create the PPD...
+ */
+
+ _cupsThreadCreate((_cups_thread_func_t)create_local_bg_thread, printer);
+
+ /*
+ * Return printer attributes...
+ */
+
+ send_ipp_status(con, IPP_STATUS_OK, _("Local printer created."));
+
+ add_printer_attributes:
+
+ ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs", (char)printer->accepting);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", printer->state);
+ add_printer_state_reasons(con, printer);
+
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), httpIsEncrypted(con->http) ? "ipps" : "ipp", NULL, con->clientname, con->clientport, "/printers/%s", printer->name);
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-uri-supported", NULL, uri);
}
/*
- * 'create_subscription()' - Create a notification subscription.
+ * 'create_subscriptions()' - Create one or more notification subscriptions.
*/
static void
-create_subscription(
+create_subscriptions(
cupsd_client_t *con, /* I - Client connection */
ipp_attribute_t *uri) /* I - Printer URI */
{
* Is the destination valid?
*/
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
- con, con->http.fd, uri->values[0].string.text);
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "create_subscriptions(con=%p(%d), uri=\"%s\")", con, con->number, uri->values[0].string.text);
httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, scheme,
sizeof(scheme), userpass, sizeof(userpass), host,
snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin,
scheme);
- if (access(notifier, X_OK))
+ if (access(notifier, X_OK) || !strcmp(scheme, ".") || !strcmp(scheme, ".."))
{
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("notify-recipient-uri URI \"%s\" uses unknown "
}
if (recipient)
+ {
cupsdLogMessage(CUPSD_LOG_DEBUG, "recipient=\"%s\"", recipient);
+
+
+ if (!strncmp(recipient, "mailto:", 7) && user_data)
+ {
+ char temp[64]; /* Temporary string */
+
+ memcpy(temp, user_data->values[0].unknown.data, user_data->values[0].unknown.length);
+ temp[user_data->values[0].unknown.length] = '\0';
+
+ if (httpSeparateURI(HTTP_URI_CODING_ALL, temp, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_OK)
+ {
+ send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad notify-user-data \"%s\"."), temp);
+ ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_ENUM, "notify-status-code", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES);
+ return;
+ }
+ }
+ }
+
if (pullmethod)
cupsdLogMessage(CUPSD_LOG_DEBUG, "pullmethod=\"%s\"", pullmethod);
cupsdLogMessage(CUPSD_LOG_DEBUG, "notify-lease-duration=%d", lease);
if (MaxLeaseDuration && (lease == 0 || lease > MaxLeaseDuration))
{
cupsdLogMessage(CUPSD_LOG_INFO,
- "create_subscription: Limiting notify-lease-duration to "
+ "create_subscriptions: Limiting notify-lease-duration to "
"%d seconds.",
MaxLeaseDuration);
lease = MaxLeaseDuration;
{
sub->user_data_len = user_data->values[0].unknown.length;
memcpy(sub->user_data, user_data->values[0].unknown.data,
- sub->user_data_len);
+ (size_t)sub->user_data_len);
}
ippAddSeparator(con->response);
cups_ptype_t dtype; /* Destination type (printer/class) */
cupsd_printer_t *printer; /* Printer/class */
char filename[1024]; /* Script/PPD filename */
+ int temporary; /* Temporary queue? */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "delete_printer(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Do we have a valid URI?
* Remove any old PPD or script files...
*/
- snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
+ snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
printer->name);
unlink(filename);
-
- snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
+ snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd.O", ServerRoot,
printer->name);
unlink(filename);
cupsdUnregisterColor(printer);
+ temporary = printer->temporary;
+
if (dtype & CUPS_PRINTER_CLASS)
{
cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" deleted by \"%s\".",
printer->name, get_username(con));
cupsdDeletePrinter(printer, 0);
- cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
+ if (!temporary)
+ cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
}
else
{
cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" deleted by \"%s\".",
printer->name, get_username(con));
- if (cupsdDeletePrinter(printer, 0))
+ if (cupsdDeletePrinter(printer, 0) && !temporary)
cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
- cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
+ if (!temporary)
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
}
- cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
+ if (!temporary)
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
/*
* Return with no errors...
cups_array_t *ra; /* Requested attributes array */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_default(%p[%d])", con, con->http.fd);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_default(%p[%d])", con, con->number);
/*
* Check policy...
/* String for included schemes */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_devices(%p[%d])", con, con->http.fd);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_devices(%p[%d])", con, con->number);
/*
* Check policy...
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_document(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* See if we have a job URI or a printer URI...
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_job_attrs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* See if we have a job URI or a printer URI...
int port; /* Port portion of URI */
int job_comparison; /* Job comparison */
ipp_jstate_t job_state; /* job-state value */
- int first_job_id; /* First job ID */
- int limit; /* Maximum number of jobs to return */
- int count; /* Number of jobs that match */
+ int first_job_id = 1, /* First job ID */
+ first_index = 1, /* First index */
+ limit = 0, /* Maximum number of jobs to return */
+ count, /* Number of jobs that match */
+ need_load_job = 0; /* Do we need to load the job? */
+ const char *job_attr; /* Job attribute requested */
ipp_attribute_t *job_ids; /* job-ids attribute */
cupsd_job_t *job; /* Current job pointer */
cupsd_printer_t *printer; /* Printer */
cups_array_t *list; /* Which job list... */
+ int delete_list = 0; /* Delete the list afterwards? */
cups_array_t *ra, /* Requested attributes array */
*exclude; /* Private attributes array */
cupsd_policy_t *policy; /* Current policy */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs(%p[%d], %s)", con, con->http.fd,
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs(%p[%d], %s)", con, con->number,
uri->values[0].string.text);
/*
{
job_comparison = -1;
job_state = IPP_JOB_STOPPED;
- list = Jobs;
+ list = ActiveJobs;
}
else if (!strcmp(attr->values[0].string.text, "completed"))
{
job_comparison = 1;
job_state = IPP_JOB_CANCELED;
- list = Jobs;
+ list = cupsdGetCompletedJobs(printer);
+ delete_list = 1;
}
else if (!strcmp(attr->values[0].string.text, "aborted"))
{
job_comparison = 0;
job_state = IPP_JOB_ABORTED;
- list = Jobs;
+ list = cupsdGetCompletedJobs(printer);
+ delete_list = 1;
}
else if (!strcmp(attr->values[0].string.text, "all"))
{
{
job_comparison = 0;
job_state = IPP_JOB_CANCELED;
- list = Jobs;
+ list = cupsdGetCompletedJobs(printer);
+ delete_list = 1;
}
else if (!strcmp(attr->values[0].string.text, "pending"))
{
* See if they want to limit the number of jobs reported...
*/
- if ((attr = ippFindAttribute(con->request, "limit",
- IPP_TAG_INTEGER)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER)) != NULL)
{
if (job_ids)
{
limit = attr->values[0].integer;
}
- else
- limit = 0;
- if ((attr = ippFindAttribute(con->request, "first-job-id",
- IPP_TAG_INTEGER)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "first-index", IPP_TAG_INTEGER)) != NULL)
+ {
+ if (job_ids)
+ {
+ send_ipp_status(con, IPP_CONFLICT,
+ _("The %s attribute cannot be provided with job-ids."),
+ "first-index");
+ return;
+ }
+
+ first_index = attr->values[0].integer;
+ }
+ else if ((attr = ippFindAttribute(con->request, "first-job-id", IPP_TAG_INTEGER)) != NULL)
{
if (job_ids)
{
first_job_id = attr->values[0].integer;
}
- else
- first_job_id = 1;
/*
* See if we only want to see jobs for a specific user...
*/
- if ((attr = ippFindAttribute(con->request, "my-jobs",
- IPP_TAG_BOOLEAN)) != NULL && job_ids)
+ if ((attr = ippFindAttribute(con->request, "my-jobs", IPP_TAG_BOOLEAN)) != NULL && job_ids)
{
send_ipp_status(con, IPP_CONFLICT,
_("The %s attribute cannot be provided with job-ids."),
username[0] = '\0';
ra = create_requested_array(con->request);
+ for (job_attr = (char *)cupsArrayFirst(ra); job_attr; job_attr = (char *)cupsArrayNext(ra))
+ if (strcmp(job_attr, "job-id") &&
+ strcmp(job_attr, "job-k-octets") &&
+ strcmp(job_attr, "job-media-progress") &&
+ strcmp(job_attr, "job-more-info") &&
+ strcmp(job_attr, "job-name") &&
+ strcmp(job_attr, "job-originating-user-name") &&
+ strcmp(job_attr, "job-preserved") &&
+ strcmp(job_attr, "job-printer-up-time") &&
+ strcmp(job_attr, "job-printer-uri") &&
+ strcmp(job_attr, "job-state") &&
+ strcmp(job_attr, "job-state-reasons") &&
+ strcmp(job_attr, "job-uri") &&
+ strcmp(job_attr, "time-at-completed") &&
+ strcmp(job_attr, "time-at-creation") &&
+ strcmp(job_attr, "number-of-documents"))
+ {
+ need_load_job = 1;
+ break;
+ }
+
+ if (need_load_job && (limit == 0 || limit > 500) && (list == Jobs || delete_list))
+ {
+ /*
+ * Limit expensive Get-Jobs for job history to 500 jobs...
+ */
+
+ ippAddInteger(con->response, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "limit", 500);
+
+ if (limit)
+ ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER, "limit", limit);
+
+ limit = 500;
+
+ cupsdLogClient(con, CUPSD_LOG_INFO, "Limiting Get-Jobs response to %d jobs.", limit);
+ }
/*
* OK, build a list of jobs for this printer...
{
job = cupsdFindJob(job_ids->values[i].integer);
- cupsdLoadJob(job);
-
- if (!job->attrs)
+ if (need_load_job && !job->attrs)
{
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: No attributes for job %d",
- job->id);
- continue;
+ cupsdLoadJob(job);
+
+ if (!job->attrs)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: No attributes for job %d", job->id);
+ continue;
+ }
}
if (i > 0)
}
else
{
- for (count = 0, job = (cupsd_job_t *)cupsArrayFirst(list);
- (limit <= 0 || count < limit) && job;
- job = (cupsd_job_t *)cupsArrayNext(list))
+ if (first_index > 1)
+ job = (cupsd_job_t *)cupsArrayIndex(list, first_index - 1);
+ else
+ job = (cupsd_job_t *)cupsArrayFirst(list);
+
+ for (count = 0; (limit <= 0 || count < limit) && job; job = (cupsd_job_t *)cupsArrayNext(list))
{
/*
* Filter out jobs that don't match...
if (job->id < first_job_id)
continue;
- cupsdLoadJob(job);
-
- if (!job->attrs)
+ if (need_load_job && !job->attrs)
{
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: No attributes for job %d",
- job->id);
- continue;
+ cupsdLoadJob(job);
+
+ if (!job->attrs)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: No attributes for job %d", job->id);
+ continue;
+ }
}
if (username[0] && _cups_strcasecmp(username, job->username))
cupsArrayDelete(ra);
+ if (delete_list)
+ cupsArrayDelete(list);
+
con->response->request.status.status_code = IPP_OK;
}
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_notifications(con=%p[%d])",
- con, con->http.fd);
+ con, con->number);
/*
* Get subscription attributes...
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppd(%p[%d], %p[%s=%s])", con,
- con->http.fd, uri, uri->name, uri->values[0].string.text);
+ con->number, uri, uri->name, uri->values[0].string.text);
- if (!strcmp(uri->name, "ppd-name"))
+ if (!strcmp(ippGetName(uri), "ppd-name"))
{
/*
* Return a PPD file from cups-driverd...
*/
- char command[1024], /* cups-driverd command */
- options[1024], /* Options to pass to command */
- ppd_name[1024]; /* ppd-name */
-
+ const char *ppd_name = ippGetString(uri, 0, NULL);
+ /* ppd-name value */
+ char command[1024], /* cups-driverd command */
+ options[1024], /* Options to pass to command */
+ oppd_name[1024]; /* Escaped ppd-name */
/*
* Check policy...
return;
}
+ /*
+ * Check ppd-name value...
+ */
+
+ if (strstr(ppd_name, "../"))
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Invalid ppd-name value."));
+ return;
+ }
+
/*
* Run cups-driverd command with the given options...
*/
snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin);
- url_encode_string(uri->values[0].string.text, ppd_name, sizeof(ppd_name));
- snprintf(options, sizeof(options), "get+%d+%s",
- con->request->request.op.request_id, ppd_name);
+ url_encode_string(ppd_name, oppd_name, sizeof(oppd_name));
+ snprintf(options, sizeof(options), "get+%d+%s", ippGetRequestId(con->request), oppd_name);
if (cupsdSendCommand(con, command, options, 0))
{
* went wrong...
*/
- send_ipp_status(con, IPP_INTERNAL_ERROR,
- _("cups-driverd failed to execute."));
+ send_ipp_status(con, IPP_INTERNAL_ERROR, _("cups-driverd failed to execute."));
}
}
- else if (!strcmp(uri->name, "printer-uri") &&
- cupsdValidateDest(uri->values[0].string.text, &dtype, &dest))
+ else if (!strcmp(ippGetName(uri), "printer-uri") && cupsdValidateDest(ippGetString(uri, 0, NULL), &dtype, &dest))
{
int i; /* Looping var */
char filename[1024]; /* PPD filename */
-
/*
* Check policy...
*/
* See if we need the PPD for a class or remote printer...
*/
- snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
- dest->name);
+ snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, dest->name);
if ((dtype & CUPS_PRINTER_REMOTE) && access(filename, 0))
{
- con->response->request.status.status_code = CUPS_SEE_OTHER;
- ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, dest->uri);
+ send_ipp_status(con, IPP_STATUS_CUPS_SEE_OTHER, _("See remote printer."));
+ ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, dest->uri);
return;
}
else if (dtype & CUPS_PRINTER_CLASS)
for (i = 0; i < dest->num_printers; i ++)
if (!(dest->printers[i]->type & CUPS_PRINTER_CLASS))
{
- snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
- dest->printers[i]->name);
+ snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, dest->printers[i]->name);
if (!access(filename, 0))
break;
dest = dest->printers[i];
else
{
- con->response->request.status.status_code = CUPS_SEE_OTHER;
- ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, dest->printers[0]->uri);
+ send_ipp_status(con, IPP_STATUS_CUPS_SEE_OTHER, _("See remote printer."));
+ ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, dest->printers[0]->uri);
return;
}
}
if ((con->file = open(filename, O_RDONLY)) < 0)
{
- send_ipp_status(con, IPP_NOT_FOUND,
- _("The PPD file \"%s\" could not be opened: %s"),
- uri->values[0].string.text, strerror(errno));
+ send_ipp_status(con, IPP_STATUS_ERROR_NOT_FOUND, _("The PPD file \"%s\" could not be opened: %s"), ippGetString(uri, 0, NULL), strerror(errno));
return;
}
con->pipe_pid = 0;
- con->response->request.status.status_code = IPP_OK;
+ ippSetStatusCode(con->response, IPP_STATUS_OK);
}
else
- send_ipp_status(con, IPP_NOT_FOUND,
- _("The PPD file \"%s\" could not be found."),
- uri->values[0].string.text);
+ send_ipp_status(con, IPP_STATUS_ERROR_NOT_FOUND, _("The PPD file \"%s\" could not be found."), ippGetString(uri, 0, NULL));
}
/* String for included schemes */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppds(%p[%d])", con, con->http.fd);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_ppds(%p[%d])", con, con->number);
/*
* Check policy...
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printer_attrs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printer_supported(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
* Return a list of attributes that can be set via Set-Printer-Attributes.
*/
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ADMINDEFINE,
+ "printer-geo-location", 0);
ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ADMINDEFINE,
"printer-info", 0);
ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ADMINDEFINE,
"printer-location", 0);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ADMINDEFINE,
+ "printer-organization", 0);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ADMINDEFINE,
+ "printer-organizational-unit", 0);
con->response->request.status.status_code = IPP_OK;
}
ipp_attribute_t *attr; /* Current attribute */
int limit; /* Max number of printers to return */
int count; /* Number of printers that match */
+ int printer_id; /* Printer we are interested in */
cupsd_printer_t *printer; /* Current printer pointer */
- int printer_type, /* printer-type attribute */
+ cups_ptype_t printer_type, /* printer-type attribute */
printer_mask; /* printer-type-mask attribute */
char *location; /* Location string */
const char *username; /* Current user */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printers(%p[%d], %x)", con,
- con->http.fd, type);
+ con->number, type);
/*
* Check policy...
* Support filtering...
*/
+ if ((attr = ippFindAttribute(con->request, "printer-id", IPP_TAG_INTEGER)) != NULL)
+ {
+ if ((printer_id = ippGetInteger(attr, 0)) <= 0)
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Bad \"printer-id\" value %d."), printer_id);
+ return;
+ }
+ }
+ else
+ printer_id = 0;
+
if ((attr = ippFindAttribute(con->request, "printer-type",
IPP_TAG_ENUM)) != NULL)
- printer_type = attr->values[0].integer;
+ printer_type = (cups_ptype_t)attr->values[0].integer;
else
- printer_type = 0;
+ printer_type = (cups_ptype_t)0;
if ((attr = ippFindAttribute(con->request, "printer-type-mask",
IPP_TAG_ENUM)) != NULL)
- printer_mask = attr->values[0].integer;
+ printer_mask = (cups_ptype_t)attr->values[0].integer;
else
- printer_mask = 0;
+ printer_mask = (cups_ptype_t)0;
local = httpAddrLocalhost(&(con->clientaddr));
if (!local && !printer->shared)
continue;
+ if (printer_id && printer->printer_id != printer_id)
+ continue;
+
if ((!type || (printer->type & CUPS_PRINTER_CLASS) == type) &&
(printer->type & printer_mask) == printer_type &&
(!location ||
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"get_subscription_attrs(con=%p[%d], sub_id=%d)",
- con, con->http.fd, sub_id);
+ con, con->number, sub_id);
+
+ /*
+ * Expire subscriptions as needed...
+ */
+
+ cupsdExpireSubscriptions(NULL, NULL);
/*
* Is the subscription ID valid?
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"get_subscriptions(con=%p[%d], uri=%s)",
- con, con->http.fd, uri->values[0].string.text);
+ con, con->number, uri->values[0].string.text);
/*
* Is the destination valid?
return;
}
+ /*
+ * Expire subscriptions as needed...
+ */
+
+ cupsdExpireSubscriptions(NULL, NULL);
+
/*
* Copy the subscription attributes to the response using the
* requested-attributes attribute that may be provided by the client.
cupsd_job_t *job; /* Job information */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "hold_job(%p[%d], %s)", con, con->http.fd,
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "hold_job(%p[%d], %s)", con, con->number,
uri->values[0].string.text);
/*
* Hold the job and return...
*/
- if ((attr = ippFindAttribute(con->request, "job-hold-until",
- IPP_TAG_KEYWORD)) == NULL)
- attr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_NAME);
-
- if (attr)
+ if ((attr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_ZERO)) != NULL)
{
- when = attr->values[0].string.text;
+ if ((ippGetValueTag(attr) != IPP_TAG_KEYWORD && ippGetValueTag(attr) != IPP_TAG_NAME && ippGetValueTag(attr) != IPP_TAG_NAMELANG) || ippGetCount(attr) != 1 || !ippValidateAttribute(attr))
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Unsupported 'job-hold-until' value."));
+ ippCopyAttribute(con->response, attr, 0);
+ return;
+ }
+
+ when = ippGetString(attr, 0, NULL);
cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, cupsdFindDest(job->dest), job,
"Job job-hold-until value changed by user.");
cupsdLogMessage(CUPSD_LOG_DEBUG2, "hold_new_jobs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
*dprinter; /* Destination printer */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "move_job(%p[%d], %s)", con, con->http.fd,
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "move_job(%p[%d], %s)", con, con->number,
uri->values[0].string.text);
/*
ipp_attribute_t *uri) /* I - Printer URI */
{
ipp_attribute_t *attr; /* Current attribute */
+ ipp_attribute_t *doc_name; /* document-name attribute */
ipp_attribute_t *format; /* Document-format attribute */
const char *default_format; /* document-format-default value */
cupsd_job_t *job; /* New job */
int compression; /* Document compression */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "print_job(%p[%d], %s)", con, con->http.fd,
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "print_job(%p[%d], %s)", con, con->number,
uri->values[0].string.text);
/*
* Is it a format we support?
*/
+ doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME);
+ if (doc_name)
+ ippSetName(con->request, &doc_name, "document-name-supplied");
+
if ((format = ippFindAttribute(con->request, "document-format",
IPP_TAG_MIMETYPE)) != NULL)
{
format->values[0].string.text);
return;
}
+
+ ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format-supplied", NULL, ippGetString(format, 0, NULL));
}
else if ((default_format = cupsGetOption("document-format",
printer->num_options,
* Auto-type the file...
*/
- ipp_attribute_t *doc_name; /* document-name attribute */
-
-
cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job ???] Auto-typing file...");
- doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME);
+
filetype = mimeFileType(MimeDatabase, con->filename,
doc_name ? doc_name->values[0].string.text : NULL,
&compression);
cupsdLogMessage(CUPSD_LOG_INFO, "[Job ???] Request file type is %s/%s.",
filetype->super, filetype->type);
+
+ snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super, filetype->type);
+ ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format-detected", NULL, mimetype);
}
else
filetype = mimeType(MimeDatabase, super, type);
filetype->type);
if (format)
- {
- _cupsStrFree(format->values[0].string.text);
-
- format->values[0].string.text = _cupsStrAlloc(mimetype);
- }
+ ippSetString(con->request, &format, 0, mimetype);
else
ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
"document-format", NULL, mimetype);
cupsdUpdateQuota(printer, job->username, 0, kbytes);
- if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
- IPP_TAG_INTEGER)) != NULL)
+ job->koctets += kbytes;
+
+ if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
attr->values[0].integer += kbytes;
/*
if (add_file(con, job, filetype, compression))
return;
- snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
- job->num_files);
- rename(con->filename, filename);
+ snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id, job->num_files);
+ if (rename(con->filename, filename))
+ {
+ cupsdLogJob(job, CUPSD_LOG_ERROR, "Unable to rename job document file \"%s\": %s", filename, strerror(errno));
+
+ send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to rename job document file."));
+ return;
+ }
+
cupsdClearString(&con->filename);
/*
if (attr->group_tag != IPP_TAG_JOB || !attr->name)
continue;
- if (!strcmp(attr->name, "job-originating-host-name") ||
- !strcmp(attr->name, "job-originating-user-name") ||
+ if (!strncmp(attr->name, "date-time-at-", 13) ||
+ !strcmp(attr->name, "job-impressions-completed") ||
!strcmp(attr->name, "job-media-sheets-completed") ||
- !strcmp(attr->name, "job-k-octets") ||
+ !strncmp(attr->name, "job-k-octets", 12) ||
!strcmp(attr->name, "job-id") ||
+ !strcmp(attr->name, "job-originating-host-name") ||
+ !strcmp(attr->name, "job-originating-user-name") ||
+ !strcmp(attr->name, "job-pages-completed") ||
+ !strcmp(attr->name, "job-printer-uri") ||
!strncmp(attr->name, "job-state", 9) ||
+ !strcmp(attr->name, "job-uri") ||
!strncmp(attr->name, "time-at-", 8))
continue; /* Read-only attrs */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "reject_jobs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
cupsdLogMessage(CUPSD_LOG_DEBUG2, "release_held_new_jobs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
"Printer \"%s\" now printing pending/new jobs (\"%s\").",
printer->name, get_username(con));
+ cupsdCheckJobs();
+
/*
* Everything was ok, so return OK status...
*/
cupsdLogMessage(CUPSD_LOG_DEBUG2, "release_job(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* See if we have a job URI or a printer URI...
if (attr)
{
- _cupsStrFree(attr->values[0].string.text);
-
- attr->value_tag = IPP_TAG_KEYWORD;
- attr->values[0].string.text = _cupsStrAlloc("no-hold");
+ ippSetValueTag(job->attrs, &attr, IPP_TAG_KEYWORD);
+ ippSetString(job->attrs, &attr, 0, "no-hold");
cupsdAddEvent(CUPSD_EVENT_JOB_CONFIG_CHANGED, cupsdFindDest(job->dest), job,
"Job job-hold-until value changed by user.");
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"renew_subscription(con=%p[%d], sub_id=%d)",
- con, con->http.fd, sub_id);
+ con, con->number, sub_id);
/*
* Is the subscription ID valid?
cupsdLogMessage(CUPSD_LOG_DEBUG2, "restart_job(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* See if we have a job URI or a printer URI...
{
if (strcmp(dest->auth_info_required[i], "negotiate"))
{
- httpEncode64_2(line, sizeof(line), auth_info->values[i].string.text,
- strlen(auth_info->values[i].string.text));
+ httpEncode64_2(line, sizeof(line), auth_info->values[i].string.text, (int)strlen(auth_info->values[i].string.text));
cupsFilePutConf(fp, dest->auth_info_required[i], line);
}
else
* Allow fallback to username+password for Kerberized queues...
*/
- httpEncode64_2(line, sizeof(line), auth_info->values[0].string.text,
- strlen(auth_info->values[0].string.text));
+ httpEncode64_2(line, sizeof(line), auth_info->values[0].string.text, (int)strlen(auth_info->values[0].string.text));
cupsFilePutConf(fp, "username", line);
cupsdSetStringf(job->auth_env + 0, "AUTH_USERNAME=%s",
auth_info->values[0].string.text);
- httpEncode64_2(line, sizeof(line), auth_info->values[1].string.text,
- strlen(auth_info->values[1].string.text));
+ httpEncode64_2(line, sizeof(line), auth_info->values[1].string.text, (int)strlen(auth_info->values[1].string.text));
cupsFilePutConf(fp, "password", line);
cupsdSetStringf(job->auth_env + 1, "AUTH_PASSWORD=%s",
* Write the authenticated username...
*/
- httpEncode64_2(line, sizeof(line), con->username, strlen(con->username));
+ httpEncode64_2(line, sizeof(line), con->username, (int)strlen(con->username));
cupsFilePutConf(fp, "username", line);
cupsdSetStringf(job->auth_env + 0, "AUTH_USERNAME=%s", con->username);
* Write the authenticated password...
*/
- httpEncode64_2(line, sizeof(line), con->password, strlen(con->password));
+ httpEncode64_2(line, sizeof(line), con->password, (int)strlen(con->password));
cupsFilePutConf(fp, "password", line);
cupsdSetStringf(job->auth_env + 1, "AUTH_PASSWORD=%s", con->password);
cupsdLogMessage(CUPSD_LOG_DEBUG2, "send_document(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* See if we have a job URI or a printer URI...
* Is it a format we support?
*/
+ cupsdLoadJob(job);
+
if ((format = ippFindAttribute(con->request, "document-format",
IPP_TAG_MIMETYPE)) != NULL)
{
format->values[0].string.text);
return;
}
+
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format-supplied", NULL, ippGetString(format, 0, NULL));
}
else if ((default_format = cupsGetOption("document-format",
printer->num_options,
if (filetype)
cupsdLogJob(job, CUPSD_LOG_DEBUG, "Request file type is %s/%s.",
filetype->super, filetype->type);
+
+ snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super, filetype->type);
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format-detected", NULL, mimetype);
}
else
filetype = mimeType(MimeDatabase, super, type);
if ((jformat = ippFindAttribute(job->attrs, "document-format",
IPP_TAG_MIMETYPE)) != NULL)
- {
- _cupsStrFree(jformat->values[0].string.text);
-
- jformat->values[0].string.text = _cupsStrAlloc(mimetype);
- }
+ ippSetString(job->attrs, &jformat, 0, mimetype);
else
ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
"document-format", NULL, mimetype);
* Add the file to the job...
*/
- cupsdLoadJob(job);
-
if (add_file(con, job, filetype, compression))
return;
+ if ((attr = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME)) != NULL)
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "document-name-supplied", NULL, ippGetString(attr, 0, NULL));
+
if (stat(con->filename, &fileinfo))
kbytes = 0;
else
cupsdUpdateQuota(printer, job->username, 0, kbytes);
- if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
- IPP_TAG_INTEGER)) != NULL)
+ job->koctets += kbytes;
+
+ if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
attr->values[0].integer += kbytes;
- snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
- job->num_files);
- rename(con->filename, filename);
+ snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id, job->num_files);
+ if (rename(con->filename, filename))
+ {
+ cupsdLogJob(job, CUPSD_LOG_ERROR, "Unable to rename job document file \"%s\": %s", filename, strerror(errno));
+
+ send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to rename job document file."));
+ return;
+ }
cupsdClearString(&con->filename);
cupsdLogMessage(status == HTTP_FORBIDDEN ? CUPSD_LOG_ERROR : CUPSD_LOG_DEBUG,
"[Client %d] Returning HTTP %s for %s (%s) from %s",
- con->http.fd, httpStatus(status),
+ con->number, httpStatus(status),
con->request ?
ippOpString(con->request->request.op.operation_id) :
"no operation-id",
uri ? uri->values[0].string.text : "no URI",
- con->http.hostname);
+ con->http->hostname);
if (printer)
{
cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_default(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_job_attrs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Start with "everything is OK" status...
if (!strcmp(attr->name, "attributes-charset") ||
!strcmp(attr->name, "attributes-natural-language") ||
- !strcmp(attr->name, "document-compression") ||
- !strcmp(attr->name, "document-format") ||
+ !strncmp(attr->name, "date-time-at-", 13) ||
+ !strncmp(attr->name, "document-compression", 20) ||
+ !strncmp(attr->name, "document-format", 15) ||
!strcmp(attr->name, "job-detailed-status-messages") ||
!strcmp(attr->name, "job-document-access-errors") ||
!strcmp(attr->name, "job-id") ||
!strcmp(attr->name, "job-impressions-completed") ||
- !strcmp(attr->name, "job-k-octets") ||
+ !strcmp(attr->name, "job-k-octets-completed") ||
+ !strcmp(attr->name, "job-media-sheets-completed") ||
!strcmp(attr->name, "job-originating-host-name") ||
!strcmp(attr->name, "job-originating-user-name") ||
+ !strcmp(attr->name, "job-pages-completed") ||
!strcmp(attr->name, "job-printer-up-time") ||
!strcmp(attr->name, "job-printer-uri") ||
!strcmp(attr->name, "job-sheets") ||
!strcmp(attr->name, "number-of-documents") ||
!strcmp(attr->name, "number-of-intervening-jobs") ||
!strcmp(attr->name, "output-device-assigned") ||
- !strncmp(attr->name, "date-time-at-", 13) ||
- !strncmp(attr->name, "job-k-octets", 12) ||
- !strncmp(attr->name, "job-media-sheets", 16) ||
!strncmp(attr->name, "time-at-", 8))
{
/*
continue;
}
- if (!strcmp(attr->name, "job-priority"))
+ if (!ippValidateAttribute(attr))
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Bad '%s' value."), attr->name);
+ ippCopyAttribute(con->response, attr, 0);
+ return;
+ }
+
+ if (!strcmp(attr->name, "job-hold-until"))
+ {
+ const char *when = ippGetString(attr, 0, NULL);
+ /* job-hold-until value */
+
+ if ((ippGetValueTag(attr) != IPP_TAG_KEYWORD && ippGetValueTag(attr) != IPP_TAG_NAME && ippGetValueTag(attr) != IPP_TAG_NAMELANG) || ippGetCount(attr) != 1)
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Unsupported 'job-hold-until' value."));
+ ippCopyAttribute(con->response, attr, 0);
+ return;
+ }
+
+ cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-hold-until to %s", when);
+ cupsdSetJobHoldUntil(job, when, 0);
+
+ if (!strcmp(when, "no-hold"))
+ {
+ cupsdReleaseJob(job);
+ check_jobs = 1;
+ }
+ else
+ cupsdSetJobState(job, IPP_JOB_HELD, CUPSD_JOB_DEFAULT, "Job held by \"%s\".", username);
+
+ event |= CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE;
+ }
+ else if (!strcmp(attr->name, "job-priority"))
{
/*
* Change the job priority...
{
cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-state to %d",
attr->values[0].integer);
- cupsdSetJobState(job, attr->values[0].integer,
- CUPSD_JOB_DEFAULT,
- "Job state changed by \"%s\"", username);
+ cupsdSetJobState(job, (ipp_jstate_t)attr->values[0].integer, CUPSD_JOB_DEFAULT, "Job state changed by \"%s\"", username);
check_jobs = 1;
}
break;
*/
ippCopyAttribute(job->attrs, attr, 0);
-
- /*
- * See if the job-name or job-hold-until is being changed.
- */
-
- if (!strcmp(attr->name, "job-hold-until"))
- {
- cupsdLogJob(job, CUPSD_LOG_DEBUG, "Setting job-hold-until to %s",
- attr->values[0].string.text);
- cupsdSetJobHoldUntil(job, attr->values[0].string.text, 0);
-
- if (!strcmp(attr->values[0].string.text, "no-hold"))
- {
- cupsdReleaseJob(job);
- check_jobs = 1;
- }
- else
- cupsdSetJobState(job, IPP_JOB_HELD, CUPSD_JOB_DEFAULT,
- "Job held by \"%s\".", username);
-
- event |= CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_STATE;
- }
}
else if (attr->value_tag == IPP_TAG_DELETEATTR)
{
cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_printer_attrs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
changed = 1;
}
+ if ((attr = ippFindAttribute(con->request, "printer-geo-location", IPP_TAG_URI)) != NULL && !strncmp(attr->values[0].string.text, "geo:", 4))
+ {
+ cupsdSetString(&printer->geo_location, attr->values[0].string.text);
+ changed = 1;
+ }
+
+ if ((attr = ippFindAttribute(con->request, "printer-organization", IPP_TAG_TEXT)) != NULL)
+ {
+ cupsdSetString(&printer->organization, attr->values[0].string.text);
+ changed = 1;
+ }
+
+ if ((attr = ippFindAttribute(con->request, "printer-organizational-unit", IPP_TAG_TEXT)) != NULL)
+ {
+ cupsdSetString(&printer->organizational_unit, attr->values[0].string.text);
+ changed = 1;
+ }
+
if ((attr = ippFindAttribute(con->request, "printer-info",
IPP_TAG_TEXT)) != NULL)
{
if (changed)
{
+ printer->config_time = time(NULL);
+
cupsdSetPrinterAttrs(printer);
cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
* 'set_printer_defaults()' - Set printer default options from a request.
*/
-static void
+static int /* O - 1 on success, 0 on failure */
set_printer_defaults(
cupsd_client_t *con, /* I - Client connection */
cupsd_printer_t *printer) /* I - Printer */
{
int i; /* Looping var */
ipp_attribute_t *attr; /* Current attribute */
- int namelen; /* Length of attribute name */
+ size_t namelen; /* Length of attribute name */
char name[256], /* New attribute name */
value[256]; /* String version of integer attrs */
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("Unknown printer-op-policy \"%s\"."),
attr->values[0].string.text);
- return;
+ return (0);
}
}
else if (!strcmp(attr->name, "printer-error-policy"))
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("Unknown printer-error-policy \"%s\"."),
attr->values[0].string.text);
- return;
+ return (0);
}
cupsdLogMessage(CUPSD_LOG_DEBUG,
break;
}
}
+
+ return (1);
}
cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_printer(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
cupsdLogMessage(CUPSD_LOG_DEBUG2, "stop_printer(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* Is the destination valid?
static void
url_encode_attr(ipp_attribute_t *attr, /* I - Attribute */
char *buffer,/* I - String buffer */
- int bufsize)/* I - Size of buffer */
+ size_t bufsize)/* I - Size of buffer */
{
int i; /* Looping var */
char *bufptr, /* Pointer into buffer */
*bufptr++ = '\'';
- bufptr = url_encode_string(attr->values[i].string.text,
- bufptr, bufend - bufptr + 1);
+ bufptr = url_encode_string(attr->values[i].string.text, bufptr, (size_t)(bufend - bufptr + 1));
if (bufptr >= bufend)
break;
static char * /* O - End of string */
url_encode_string(const char *s, /* I - String */
char *buffer, /* I - String buffer */
- int bufsize) /* I - Size of buffer */
+ size_t bufsize) /* I - Size of buffer */
{
char *bufptr, /* Pointer into buffer */
*bufend; /* End of buffer */
ipp_attribute_t *uri) /* I - Printer URI */
{
http_status_t status; /* Policy status */
- ipp_attribute_t *attr, /* Current attribute */
- *auth_info; /* auth-info attribute */
+ ipp_attribute_t *attr; /* Current attribute */
+#ifdef HAVE_SSL
+ ipp_attribute_t *auth_info; /* auth-info attribute */
+#endif /* HAVE_SSL */
ipp_attribute_t *format, /* Document-format attribute */
*name; /* Job-name attribute */
cups_ptype_t dtype; /* Destination type (printer/class) */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "validate_job(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ con->number, uri->values[0].string.text);
/*
* OK, see if the client is sending the document compressed - CUPS
}
}
+ /*
+ * Is the job-hold-until value valid?
+ */
+
+ if ((attr = ippFindAttribute(con->request, "job-hold-until", IPP_TAG_ZERO)) != NULL && ((ippGetValueTag(attr) != IPP_TAG_KEYWORD && ippGetValueTag(attr) != IPP_TAG_NAME && ippGetValueTag(attr) != IPP_TAG_NAMELANG) || ippGetCount(attr) != 1 || !ippValidateAttribute(attr)))
+ {
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Unsupported 'job-hold-until' value."));
+ ippCopyAttribute(con->response, attr, 0);
+ return;
+ }
+
/*
* Is the job-name valid?
*/
if ((name = ippFindAttribute(con->request, "job-name", IPP_TAG_ZERO)) != NULL)
{
- int bad_name = 0; /* Is the job-name value bad? */
-
if ((name->value_tag != IPP_TAG_NAME && name->value_tag != IPP_TAG_NAMELANG) ||
- name->num_values != 1)
- {
- bad_name = 1;
- }
- else
- {
- /*
- * Validate that job-name conforms to RFC 5198 (Network Unicode) and
- * IPP Everywhere requirements for "name" values...
- */
-
- const unsigned char *nameptr; /* Pointer into "job-name" attribute */
-
- for (nameptr = (unsigned char *)name->values[0].string.text;
- *nameptr;
- nameptr ++)
- {
- if (*nameptr < ' ' && *nameptr != '\t')
- break;
- else if (*nameptr == 0x7f)
- break;
- else if ((*nameptr & 0xe0) == 0xc0)
- {
- if ((nameptr[1] & 0xc0) != 0x80)
- break;
-
- nameptr ++;
- }
- else if ((*nameptr & 0xf0) == 0xe0)
- {
- if ((nameptr[1] & 0xc0) != 0x80 ||
- (nameptr[2] & 0xc0) != 0x80)
- break;
-
- nameptr += 2;
- }
- else if ((*nameptr & 0xf8) == 0xf0)
- {
- if ((nameptr[1] & 0xc0) != 0x80 ||
- (nameptr[2] & 0xc0) != 0x80 ||
- (nameptr[3] & 0xc0) != 0x80)
- break;
-
- nameptr += 3;
- }
- else if (*nameptr & 0x80)
- break;
- }
-
- if (*nameptr)
- bad_name = 1;
- }
-
- if (bad_name)
+ name->num_values != 1 || !ippValidateAttribute(name))
{
if (StrictConformance)
{
- send_ipp_status(con, IPP_ATTRIBUTES,
- _("Unsupported 'job-name' value."));
+ send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Unsupported 'job-name' value."));
ippCopyAttribute(con->response, name, 0);
return;
}
else
{
- cupsdLogMessage(CUPSD_LOG_WARN,
- "Unsupported 'job-name' value, deleting from request.");
+ cupsdLogMessage(CUPSD_LOG_WARN, "Unsupported 'job-name' value, deleting from request.");
ippDeleteAttribute(con->request, name);
}
}
* Check policy...
*/
+#ifdef HAVE_SSL
auth_info = ippFindAttribute(con->request, "auth-info", IPP_TAG_TEXT);
+#endif /* HAVE_SSL */
if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
{
return;
}
#ifdef HAVE_SSL
- else if (auth_info && !con->http.tls &&
- !httpAddrLocalhost(con->http.hostaddr))
+ else if (auth_info && !con->http->tls &&
+ !httpAddrLocalhost(con->http->hostaddr))
{
/*
* Require encryption of auth-info over non-local connections...
cupsd_client_t *con, /* I - Client connection */
const char *owner, /* I - Owner of job/resource */
char *username, /* O - Authenticated username */
- int userlen) /* I - Length of username */
+ size_t userlen) /* I - Length of username */
{
cupsd_printer_t *printer; /* Printer for job */
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, "
- "userlen=%d)",
- job->id, con ? con->http.fd : 0,
- owner ? owner : "(null)", username, userlen);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "validate_user(job=%d, con=%d, owner=\"%s\", username=%p, userlen=" CUPS_LLFMT ")", job->id, con ? con->number : 0, owner ? owner : "(null)", username, CUPS_LLCAST userlen);
/*
* Validate input...
return (cupsdCheckPolicy(printer ? printer->op_policy_ptr : DefaultPolicyPtr,
con, owner) == HTTP_OK);
}
-
-
-/*
- * End of "$Id$".
- */