/*
- * "$Id$"
- *
* IPP routines for the CUPS scheduler.
*
* Copyright 2007-2016 by Apple Inc.
* 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/".
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
*/
/*
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, size_t bufsize);
int sub_id; /* Subscription ID */
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdProcessIPPRequest(%p[%d]): operation_id = %04x",
- con, con->number, 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...
pclass = cupsdAddClass(resource + 9);
modify = 0;
+
+ pclass->printer_id = NextPrinterId ++;
}
else if ((status = cupsdCheckPolicy(pclass->op_policy_ptr, con,
NULL)) != HTTP_OK)
*/
send_ipp_status(con, IPP_BAD_REQUEST, _("Cannot change printer-is-shared for remote queues."));
+ if (!modify)
+ cupsdDeletePrinter(pclass, 0);
+
return;
}
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)
return (NULL);
}
+ attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME);
+
+ if (attr && !ippValidateAttribute(attr))
+ {
+ send_ipp_status(con, IPP_ATTRIBUTES, _("Bad requesting-user-name value: %s"), cupsLastErrorString());
+ if ((attr = ippCopyAttribute(con->response, attr, 0)) != NULL)
+ attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
+ return (NULL);
+ }
+
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);
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...
printer = cupsdAddPrinter(resource + 10);
modify = 0;
+
+ printer->printer_id = NextPrinterId ++;
}
else if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con,
NULL)) != HTTP_OK)
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;
}
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Cannot share a remote Kerberized printer."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
*/
send_ipp_status(con, IPP_BAD_REQUEST, _("Cannot change printer-is-shared for remote queues."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
{
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)
if (strncmp(line, "*PPD-Adobe", 10))
{
send_ipp_status(con, IPP_STATUS_ERROR_DOCUMENT_FORMAT_NOT_SUPPORTED, _("Bad PPD file."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
if (copy_file(srcfile, dstfile, ConfigFilePerm))
{
send_ipp_status(con, IPP_INTERNAL_ERROR, _("Unable to copy PPD file - %s"), strerror(errno));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
else if (strstr(ppd_name, "../"))
{
send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("Invalid ppd-name value."));
+ if (!modify)
+ cupsdDeletePrinter(printer, 0);
+
return;
}
else
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;
}
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");
* Update the printer attributes and return...
*/
- cupsdSetPrinterAttrs(printer);
if (!printer->temporary)
+ {
+ if (!printer->printer_id)
+ printer->printer_id = NextPrinterId ++;
+
cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
+ }
+
+ cupsdSetPrinterAttrs(printer);
if (need_restart_job && printer->job)
{
*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);
}
/*
* 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;
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);
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: Get-Printer-Attributes returned %s", printer->name, ippErrorString(cupsLastError()));
+
// TODO: Grab printer icon file...
httpClose(http);
cupsdSetString(&printer->geo_location, ippGetString(attr, 0, NULL));
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);
}
cupsFileClose(from);
if (!cupsdCloseCreatedConfFile(to, toppd))
{
- printer->state = IPP_PSTATE_IDLE;
- printer->accepting = 1;
+ 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);
}
return;
}
+ printer->shared = 0;
+ printer->temporary = 1;
+
cupsdSetDeviceURI(printer, ippGetString(device_uri, 0, NULL));
if (printer_geo_location)
ipp_jstate_t job_state; /* job-state value */
int first_job_id = 1, /* First job ID */
first_index = 1, /* First index */
- current_index = 0; /* Current index */
- int limit = 0; /* Maximum number of jobs to return */
- int count; /* Number of jobs that match */
- int need_load_job = 0; /* Do we need to load the job? */
+ 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 */
}
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;
- current_index ++;
- if (current_index < first_index)
- continue;
-
if (need_load_job && !job->attrs)
{
cupsdLoadJob(job);
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 */
cups_ptype_t printer_type, /* printer-type attribute */
printer_mask; /* printer-type-mask attribute */
* 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 = (cups_ptype_t)attr->values[0].integer;
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 ||
"Printer \"%s\" now printing pending/new jobs (\"%s\").",
printer->name, get_username(con));
+ cupsdCheckJobs();
+
/*
* Everything was ok, so return OK status...
*/
* '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 */
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);
}
return (cupsdCheckPolicy(printer ? printer->op_policy_ptr : DefaultPolicyPtr,
con, owner) == HTTP_OK);
}
-
-
-/*
- * End of "$Id$".
- */