/*
- * "$Id: ipp.c 4906 2006-01-10 20:53:28Z mike $"
+ * "$Id: ipp.c 5232 2006-03-05 17:59:19Z mike $"
*
* IPP routines for the Common UNIX Printing System (CUPS) scheduler.
*
* 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_state_reasons() - Add the "job-state-reasons" attribute based
* upon the job and printer state...
* add_job_subscriptions() - Add any subcriptions 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
+ * apply_printer_defaults() - Apply printer default options to a job.
* authenticate_job() - Set job authentication info.
* cancel_all_jobs() - Cancel all print jobs.
* cancel_job() - Cancel a print 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.
* get_default() - Get the default destination.
* get_devices() - Get the list of available devices on the
* local system.
- * get_jobs() - Get a list of jobs for the specified printer.
* 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_ppds() - Get the list of PPD files on the local
* system.
* get_printers() - Get a list of printers.
* 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.
* move_job() - Move a job to a new destination.
* ppd_add_default() - Add a PPD default choice.
* 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_defaults() - Set printer default options from a request.
* start_printer() - Start a printer.
* stop_printer() - Stop a printer.
* user_allowed() - See if a user is allowed to print to a queue.
static void accept_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
static void add_class(cupsd_client_t *con, ipp_attribute_t *uri);
-static int add_file(cupsd_client_t *con, cupsd_job_t *job, mime_type_t *filetype,
- int compression);
+static int add_file(cupsd_client_t *con, cupsd_job_t *job,
+ mime_type_t *filetype, int compression);
+static cupsd_job_t *add_job(cupsd_client_t *con, ipp_attribute_t *uri,
+ cupsd_printer_t **dprinter);
static void add_job_state_reasons(cupsd_client_t *con, cupsd_job_t *job);
static void add_job_subscriptions(cupsd_client_t *con, cupsd_job_t *job);
+static void add_job_uuid(cupsd_client_t *con, cupsd_job_t *job);
static void add_printer(cupsd_client_t *con, ipp_attribute_t *uri);
-static void add_printer_state_reasons(cupsd_client_t *con, cupsd_printer_t *p);
+static void add_printer_state_reasons(cupsd_client_t *con,
+ cupsd_printer_t *p);
static void add_queued_job_count(cupsd_client_t *con, cupsd_printer_t *p);
+static void apply_printer_defaults(cupsd_printer_t *printer,
+ cupsd_job_t *job);
static void authenticate_job(cupsd_client_t *con, ipp_attribute_t *uri);
static void cancel_all_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
static void cancel_job(cupsd_client_t *con, ipp_attribute_t *uri);
static int check_quotas(cupsd_client_t *con, cupsd_printer_t *p);
static ipp_attribute_t *copy_attribute(ipp_t *to, ipp_attribute_t *attr,
int quickcopy);
-static void copy_attrs(ipp_t *to, ipp_t *from, ipp_attribute_t *req,
+static void copy_attrs(ipp_t *to, ipp_t *from, cups_array_t *ra,
ipp_tag_t group, int quickcopy);
-static int copy_banner(cupsd_client_t *con, cupsd_job_t *job, const char *name);
+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_model(cupsd_client_t *con, const char *from, const char *to);
+static int copy_model(cupsd_client_t *con, const char *from,
+ const char *to);
+static void copy_job_attrs(cupsd_client_t *con,
+ cupsd_job_t *job,
+ cups_array_t *ra);
+static void copy_printer_attrs(cupsd_client_t *con,
+ cupsd_printer_t *printer,
+ cups_array_t *ra);
static void copy_subscription_attrs(cupsd_client_t *con,
cupsd_subscription_t *sub,
cups_array_t *ra);
static void get_devices(cupsd_client_t *con);
static void get_jobs(cupsd_client_t *con, ipp_attribute_t *uri);
static void get_job_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
-static void get_notifications(cupsd_client_t *con, int id);
+static void get_notifications(cupsd_client_t *con);
static void get_ppds(cupsd_client_t *con);
static void get_printers(cupsd_client_t *con, int type);
static void get_printer_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
static void get_subscription_attrs(cupsd_client_t *con, int sub_id);
static void get_subscriptions(cupsd_client_t *con, ipp_attribute_t *uri);
+static const char *get_username(cupsd_client_t *con);
static void hold_job(cupsd_client_t *con, ipp_attribute_t *uri);
static void move_job(cupsd_client_t *con, ipp_attribute_t *uri);
static int ppd_add_default(const char *option, const char *choice,
;
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_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 int user_allowed(cupsd_printer_t *p, const char *username);
con->request->request.any.version[0],
con->request->request.any.version[1]);
}
- else if (con->request->attrs == NULL)
+ else if (!con->request->attrs)
{
cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL,
"%04X %s No attributes in request",
*/
for (attr = con->request->attrs, group = attr->group_tag;
- attr != NULL;
+ attr;
attr = attr->next)
if (attr->group_tag < group && attr->group_tag != IPP_TAG_ZERO)
{
else
group = attr->group_tag;
- if (attr == NULL)
+ if (!attr)
{
/*
* Then make sure that the first three attributes are:
attr = con->request->attrs;
if (attr && !strcmp(attr->name, "attributes-charset") &&
- attr->value_tag == IPP_TAG_CHARSET)
+ (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_CHARSET)
charset = attr;
else
charset = NULL;
attr = attr->next;
if (attr && !strcmp(attr->name, "attributes-natural-language") &&
- attr->value_tag == IPP_TAG_LANGUAGE)
+ (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_LANGUAGE)
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)
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)
uri = attr;
else
uri = NULL;
ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
"attributes-natural-language", NULL, DefaultLanguage);
- if (charset == NULL || language == NULL ||
- (uri == NULL &&
+ if (!charset || !language ||
+ (!uri &&
con->request->request.op.operation_id != CUPS_GET_DEFAULT &&
con->request->request.op.operation_id != CUPS_GET_PRINTERS &&
con->request->request.op.operation_id != CUPS_GET_CLASSES &&
cupsdLogMessage(CUPSD_LOG_DEBUG, "Request attributes follow...");
- for (attr = con->request->attrs; attr != NULL; attr = attr->next)
+ for (attr = con->request->attrs; attr; attr = attr->next)
cupsdLogMessage(CUPSD_LOG_DEBUG,
"attr \"%s\": group_tag = %x, value_tag = %x",
attr->name ? attr->name : "(null)", attr->group_tag,
* Remote unauthenticated user masquerading as local root...
*/
- cupsdSetString(&(username->values[0].string.text), RemoteRoot);
+ _cupsStrFree(username->values[0].string.text);
+ username->values[0].string.text = _cupsStrAlloc(RemoteRoot);
}
}
*/
if (uri)
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdProcessIPPRequest: URI=\"%s\"",
- uri->values[0].string.text);
+ 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)
{
break;
case IPP_GET_NOTIFICATIONS :
- get_notifications(con, sub_id);
+ get_notifications(con);
break;
default :
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
cupsdSaveAllPrinters();
cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" now accepting jobs (\"%s\").", name,
- con->username);
+ get_username(con));
/*
* Everything was ok, so return OK status...
const char *dest; /* Printer or class name */
ipp_attribute_t *attr; /* Printer attribute */
int modify; /* Non-zero if we just modified */
+ char newname[IPP_MAX_NAME]; /* New class name */
+ int need_restart_job; /* Need to restart job? */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_class(%p[%d], %s)", con,
* Do we have a valid URI?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
- if (strncmp(resource, "/classes/", 9) != 0 || strlen(resource) == 9)
+ if (strncmp(resource, "/classes/", 9) || strlen(resource) == 9)
{
/*
* No, return an error...
if (ImplicitAnyClasses)
{
- cupsArrayRemove(Printers, pclass);
- cupsdSetStringf(&pclass->name, "Any%s", resource + 9);
- cupsArrayAdd(Printers, pclass);
+ snprintf(newname, sizeof(newname), "Any%s", resource + 9);
+ cupsdRenamePrinter(pclass, newname);
}
else
cupsdDeletePrinter(pclass, 1);
* Rename the remote class to "Class"...
*/
- cupsdDeletePrinterFilters(pclass);
- cupsArrayRemove(Printers, pclass);
- cupsdSetStringf(&pclass->name, "%s@%s", resource + 9, pclass->hostname);
- cupsdSetPrinterAttrs(pclass);
- cupsArrayAdd(Printers, pclass);
+ snprintf(newname, sizeof(newname), "%s@%s", resource + 9, pclass->hostname);
+ cupsdRenamePrinter(pclass, newname);
/*
* Add the class as a new local class...
* Look for attributes and copy them over as needed...
*/
- if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL)
+ need_restart_job = 0;
+
+ 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-info", IPP_TAG_TEXT)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-info",
+ IPP_TAG_TEXT)) != NULL)
cupsdSetString(&pclass->info, attr->values[0].string.text);
- if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs",
+ IPP_TAG_BOOLEAN)) != NULL)
{
cupsdLogMessage(CUPSD_LOG_INFO, "Setting %s printer-is-accepting-jobs to %d (was %d.)",
pclass->name, attr->values[0].boolean, pclass->accepting);
cupsdAddPrinterHistory(pclass);
}
- 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)
cupsdSendBrowseDelete(pclass);
pclass->shared = attr->values[0].boolean;
}
- if ((attr = ippFindAttribute(con->request, "printer-state", IPP_TAG_ENUM)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-state",
+ IPP_TAG_ENUM)) != NULL)
{
if (attr->values[0].integer != IPP_PRINTER_IDLE &&
attr->values[0].integer != IPP_PRINTER_STOPPED)
if (attr->values[0].integer == IPP_PRINTER_STOPPED)
cupsdStopPrinter(pclass, 0);
else
+ {
cupsdSetPrinterState(pclass, (ipp_pstate_t)(attr->values[0].integer), 0);
+ need_restart_job = 1;
+ }
}
- if ((attr = ippFindAttribute(con->request, "printer-state-message", IPP_TAG_TEXT)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-state-message",
+ IPP_TAG_TEXT)) != NULL)
{
strlcpy(pclass->state_message, attr->values[0].string.text,
sizeof(pclass->state_message));
cupsdAddPrinterHistory(pclass);
}
- if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL &&
- !Classification)
- {
- cupsdSetString(&pclass->job_sheets[0], attr->values[0].string.text);
- if (attr->num_values > 1)
- cupsdSetString(&pclass->job_sheets[1], attr->values[1].string.text);
- else
- cupsdSetString(&pclass->job_sheets[1], "none");
- }
- if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",
- IPP_TAG_ZERO)) != NULL)
- {
- cupsdFreePrinterUsers(pclass);
-
- pclass->deny_users = 0;
- if (attr->value_tag == IPP_TAG_NAME &&
- (attr->num_values > 1 ||
- strcmp(attr->values[0].string.text, "all") != 0))
- for (i = 0; i < attr->num_values; i ++)
- cupsdAddPrinterUser(pclass, attr->values[i].string.text);
- }
- else if ((attr = ippFindAttribute(con->request, "requesting-user-name-denied",
- IPP_TAG_ZERO)) != NULL)
- {
- cupsdFreePrinterUsers(pclass);
-
- pclass->deny_users = 1;
- if (attr->value_tag == IPP_TAG_NAME &&
- (attr->num_values > 1 ||
- strcmp(attr->values[0].string.text, "none") != 0))
- for (i = 0; i < attr->num_values; i ++)
- cupsdAddPrinterUser(pclass, attr->values[i].string.text);
- }
- if ((attr = ippFindAttribute(con->request, "job-quota-period",
- IPP_TAG_INTEGER)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "add_class: Setting job-quota-period to %d...",
- attr->values[0].integer);
- cupsdFreeQuotas(pclass);
- pclass->quota_period = attr->values[0].integer;
- }
- if ((attr = ippFindAttribute(con->request, "job-k-limit",
- IPP_TAG_INTEGER)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "add_class: Setting job-k-limit to %d...",
- attr->values[0].integer);
- cupsdFreeQuotas(pclass);
- pclass->k_limit = attr->values[0].integer;
- }
- if ((attr = ippFindAttribute(con->request, "job-page-limit",
- IPP_TAG_INTEGER)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "add_class: Setting job-page-limit to %d...",
- attr->values[0].integer);
- cupsdFreeQuotas(pclass);
- pclass->page_limit = attr->values[0].integer;
- }
- if ((attr = ippFindAttribute(con->request, "printer-op-policy",
- IPP_TAG_NAME)) != NULL)
- {
- cupsd_policy_t *p; /* Policy */
-
-
- if ((p = cupsdFindPolicy(attr->values[0].string.text)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "add_class: Setting printer-op-policy to \"%s\"...",
- attr->values[0].string.text);
- cupsdSetString(&pclass->op_policy, attr->values[0].string.text);
- pclass->op_policy_ptr = p;
- }
- else
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("add_class: Unknown printer-op-policy \"%s\"."),
- attr->values[0].string.text);
- return;
- }
- }
- if ((attr = ippFindAttribute(con->request, "printer-error-policy",
- IPP_TAG_NAME)) != NULL)
- {
- if (strcmp(attr->values[0].string.text, "abort-job") &&
- strcmp(attr->values[0].string.text, "retry-job") &&
- strcmp(attr->values[0].string.text, "stop-printer"))
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("add_class: Unknown printer-error-policy \"%s\"."),
- attr->values[0].string.text);
- return;
- }
-
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "add_class: Setting printer-error-policy to \"%s\"...",
- attr->values[0].string.text);
- cupsdSetString(&pclass->error_policy, attr->values[0].string.text);
- }
- if ((attr = ippFindAttribute(con->request, "member-uris", IPP_TAG_URI)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "member-uris",
+ IPP_TAG_URI)) != NULL)
{
/*
* Clear the printer array as needed...
*/
+ need_restart_job = 1;
+
if (pclass->num_printers > 0)
{
free(pclass->printers);
* Search for the printer or class URI...
*/
- httpSeparateURI(attr->values[i].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[i].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((dest = cupsdValidateDest(host, resource, &dtype, &member)) == NULL)
{
}
}
+ set_printer_defaults(con, pclass);
+
/*
* Update the printer class attributes and return...
*/
cupsdSetPrinterAttrs(pclass);
cupsdSaveAllClasses();
- cupsdCheckJobs();
+
+ if (need_restart_job && pclass->job)
+ {
+ cupsd_job_t *job;
+
+ /*
+ * Stop the current job and then restart it below...
+ */
+
+ job = (cupsd_job_t *)pclass->job;
+
+ cupsdStopJob(job, 1);
+
+ job->state->values[0].integer = IPP_JOB_PENDING;
+ job->state_value = IPP_JOB_PENDING;
+ }
+
+ if (need_restart_job)
+ cupsdCheckJobs();
cupsdWritePrintcap();
{
cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, pclass, NULL,
"Class \"%s\" modified by \"%s\".", pclass->name,
- con->username);
+ get_username(con));
cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" modified by \"%s\".",
- pclass->name, con->username);
+ pclass->name, get_username(con));
}
else
{
cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, pclass, NULL,
"New class \"%s\" added by \"%s\".", pclass->name,
- con->username);
+ get_username(con));
cupsdLogMessage(CUPSD_LOG_INFO, "New class \"%s\" added by \"%s\".",
- pclass->name, con->username);
+ pclass->name, get_username(con));
}
con->response->request.status.status_code = IPP_OK;
sizeof(mime_type_t *));
}
- if (compressions == NULL || filetypes == NULL)
+ if (!compressions || !filetypes)
{
cupsdCancelJob(job, 1);
/*
- * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
- * upon the job and printer state...
+ * 'add_job()' - Add a job to a print queue.
*/
-static void
-add_job_state_reasons(
- cupsd_client_t *con, /* I - Client connection */
- cupsd_job_t *job) /* I - Job info */
+static cupsd_job_t * /* O - Job object */
+add_job(cupsd_client_t *con, /* I - Client connection */
+ ipp_attribute_t *uri, /* I - printer-uri */
+ cupsd_printer_t **dprinter) /* I - Destination printer */
{
- cupsd_printer_t *dest; /* Destination printer */
-
+ http_status_t status; /* Policy status */
+ ipp_attribute_t *attr; /* Current attribute */
+ const char *dest; /* Destination */
+ cups_ptype_t dtype; /* Destination type (printer or class) */
+ const char *val; /* Default option value */
+ int priority; /* Job priority */
+ char *title; /* Job name/title */
+ cupsd_job_t *job; /* Current job */
+ char job_uri[HTTP_MAX_URI], /* Job URI */
+ method[HTTP_MAX_URI], /* Method portion of URI */
+ username[HTTP_MAX_URI], /* Username portion of URI */
+ host[HTTP_MAX_URI], /* Host portion of URI */
+ resource[HTTP_MAX_URI]; /* Resource portion of URI */
+ int port; /* Port portion of URI */
+ cupsd_printer_t *printer; /* Printer data */
+ int kbytes; /* Size of print file */
+ int i; /* Looping var */
+ int lowerpagerange; /* Page range bound */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job_state_reasons(%p[%d], %d)",
- con, con->http.fd, job ? job->id : 0);
- switch (job ? job->state->values[0].integer : IPP_JOB_CANCELLED)
- {
- case IPP_JOB_PENDING :
- if (job->dtype & CUPS_PRINTER_CLASS)
- dest = cupsdFindClass(job->dest);
- else
- dest = cupsdFindPrinter(job->dest);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job(%p[%d], %s)", con,
+ con->http.fd, uri->values[0].string.text);
- if (dest != NULL && dest->state == IPP_PRINTER_STOPPED)
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "printer-stopped");
- else
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "none");
- break;
+ /*
+ * Is the destination valid?
+ */
- case IPP_JOB_HELD :
- if (ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_KEYWORD) != NULL ||
- ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME) != NULL)
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "job-hold-until-specified");
- else
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "job-incoming");
- break;
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
- case IPP_JOB_PROCESSING :
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "job-printing");
- break;
+ if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+ {
+ /*
+ * Bad URI...
+ */
- case IPP_JOB_STOPPED :
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "job-stopped");
- break;
+ send_ipp_status(con, IPP_NOT_FOUND,
+ _("The printer or class was not found."));
+ return (NULL);
+ }
- case IPP_JOB_CANCELLED :
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "job-canceled-by-user");
- break;
+ if (dprinter)
+ *dprinter = printer;
- case IPP_JOB_ABORTED :
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "aborted-by-system");
- break;
+ /*
+ * Check remote printing to non-shared printer...
+ */
- case IPP_JOB_COMPLETED :
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-state-reasons", NULL, "job-completed-successfully");
- break;
+ if (!printer->shared &&
+ strcasecmp(con->http.hostname, "localhost") &&
+ strcasecmp(con->http.hostname, ServerName))
+ {
+ send_ipp_status(con, IPP_NOT_AUTHORIZED,
+ _("The printer or class is not shared!"));
+ return (NULL);
}
-}
-
-
-/*
- * 'add_job_subscriptions()' - Add any subcriptions for a job.
- */
-static void
-add_job_subscriptions(
- cupsd_client_t *con, /* I - Client connection */
- cupsd_job_t *job) /* I - Newly created job */
-{
- int i; /* Looping var */
- ipp_attribute_t *prev, /* Previous attribute */
- *next, /* Next attribute */
- *attr; /* Current attribute */
- cupsd_subscription_t *sub; /* Subscription object */
- const char *recipient, /* notify-recipient-uri */
- *pullmethod; /* notify-pull-method */
- ipp_attribute_t *user_data; /* notify-user-data */
- int interval; /* notify-time-interval */
- unsigned mask; /* notify-events */
+ /*
+ * Check policy...
+ */
+ if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
+ {
+ send_http_error(con, status);
+ return (NULL);
+ }
+ else if ((printer->type & CUPS_PRINTER_AUTHENTICATED) && !con->username[0])
+ {
+ send_http_error(con, HTTP_UNAUTHORIZED);
+ return (NULL);
+ }
/*
- * Find the first subscription group attribute; return if we have
- * none...
+ * See if the printer is accepting jobs...
*/
- for (attr = job->attrs->attrs, prev = NULL;
- attr;
- prev = attr, attr = attr->next)
- if (attr->group_tag == IPP_TAG_SUBSCRIPTION)
- break;
-
- if (!attr)
- return;
+ if (!printer->accepting)
+ {
+ send_ipp_status(con, IPP_NOT_ACCEPTING,
+ _("Destination \"%s\" is not accepting jobs."),
+ dest);
+ return (NULL);
+ }
/*
- * Process the subscription attributes in the request...
+ * Validate job template attributes; for now just copies and page-ranges...
*/
- while (attr)
+ if ((attr = ippFindAttribute(con->request, "copies",
+ IPP_TAG_INTEGER)) != NULL)
{
- recipient = NULL;
- pullmethod = NULL;
- user_data = NULL;
- interval = 0;
- mask = CUPSD_EVENT_NONE;
+ if (attr->values[0].integer < 1 || attr->values[0].integer > MaxCopies)
+ {
+ send_ipp_status(con, IPP_ATTRIBUTES, _("Bad copies value %d."),
+ attr->values[0].integer);
+ ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER,
+ "copies", attr->values[0].integer);
+ return (NULL);
+ }
+ }
- while (attr && attr->group_tag != IPP_TAG_ZERO)
+ if ((attr = ippFindAttribute(con->request, "page-ranges",
+ IPP_TAG_RANGE)) != NULL)
+ {
+ for (i = 0, lowerpagerange = 1; i < attr->num_values; i ++)
{
- if (!strcmp(attr->name, "notify-recipient") &&
- attr->value_tag == IPP_TAG_URI)
- recipient = attr->values[0].string.text;
- else if (!strcmp(attr->name, "notify-pull-method") &&
- attr->value_tag == IPP_TAG_KEYWORD)
- pullmethod = attr->values[0].string.text;
- else if (!strcmp(attr->name, "notify-charset") &&
- attr->value_tag == IPP_TAG_CHARSET &&
- strcmp(attr->values[0].string.text, "us-ascii") &&
- strcmp(attr->values[0].string.text, "utf-8"))
+ if (attr->values[i].range.lower < lowerpagerange ||
+ attr->values[i].range.lower > attr->values[i].range.upper)
{
- send_ipp_status(con, IPP_CHARSET,
- _("Character set \"%s\" not supported!"),
- attr->values[0].string.text);
- return;
- }
- else if (!strcmp(attr->name, "notify-natural-language") &&
- (attr->value_tag != IPP_TAG_LANGUAGE ||
- strcmp(attr->values[0].string.text, DefaultLanguage)))
- {
- send_ipp_status(con, IPP_CHARSET,
- _("Language \"%s\" not supported!"),
- attr->values[0].string.text);
- return;
- }
- else if (!strcmp(attr->name, "notify-user-data") &&
- attr->value_tag == IPP_TAG_STRING)
- {
- if (attr->num_values > 1 || attr->values[0].unknown.length > 63)
- {
- send_ipp_status(con, IPP_REQUEST_VALUE,
- _("The notify-user-data value is too large "
- "(%d > 63 octets)!"),
- attr->values[0].unknown.length);
- return;
- }
-
- user_data = attr;
- }
- else if (!strcmp(attr->name, "notify-events") &&
- attr->value_tag == IPP_TAG_KEYWORD)
- {
- for (i = 0; i < attr->num_values; i ++)
- mask |= cupsdEventValue(attr->values[i].string.text);
- }
- else if (!strcmp(attr->name, "notify-lease-duration"))
- {
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("The notify-lease-duration attribute cannot be "
- "used with job subscriptions."));
- return;
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("Bad page-ranges values %d-%d."),
+ attr->values[i].range.lower,
+ attr->values[i].range.upper);
+ return (NULL);
}
- else if (!strcmp(attr->name, "notify-time-interval") &&
- attr->value_tag == IPP_TAG_INTEGER)
- interval = attr->values[0].integer;
- attr = attr->next;
+ lowerpagerange = attr->values[i].range.upper + 1;
}
+ }
- if (!recipient && !pullmethod)
- break;
-
- if (mask == CUPSD_EVENT_NONE)
- mask = CUPSD_EVENT_JOB_COMPLETED;
-
- sub = cupsdAddSubscription(mask, cupsdFindDest(job->dest), job, recipient,
- 0);
-
- sub->interval = interval;
-
- cupsdSetString(&sub->owner, job->username);
-
- if (user_data)
- {
- sub->user_data_len = user_data->values[0].unknown.length;
- memcpy(sub->user_data, user_data->values[0].unknown.data,
- sub->user_data_len);
- }
+ /*
+ * Make sure we aren't over our limit...
+ */
- ippAddSeparator(con->response);
- ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
- "notify-subscription-id", sub->id);
+ if (MaxJobs && cupsArrayCount(Jobs) >= MaxJobs)
+ cupsdCleanJobs();
- if (attr)
- attr = attr->next;
+ if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
+ {
+ send_ipp_status(con, IPP_NOT_POSSIBLE,
+ _("Too many active jobs."));
+ return (NULL);
}
- cupsdSaveAllSubscriptions();
+ if (!check_quotas(con, printer))
+ {
+ send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached."));
+ return (NULL);
+ }
/*
- * Remove all of the subscription attributes from the job request...
+ * Create the job and set things up...
*/
- for (attr = job->attrs->attrs, prev = NULL; attr; attr = next)
+ if ((attr = ippFindAttribute(con->request, "job-priority",
+ IPP_TAG_INTEGER)) != NULL)
+ priority = attr->values[0].integer;
+ else
{
- next = attr->next;
-
- if (attr->group_tag == IPP_TAG_SUBSCRIPTION ||
- attr->group_tag == IPP_TAG_ZERO)
- {
- /*
- * Free and remove this attribute...
- */
-
- _ipp_free_attr(attr);
-
- if (prev)
- prev->next = next;
- else
- job->attrs->attrs = next;
- }
+ if ((val = cupsGetOption("job-priority", printer->num_options,
+ printer->options)) != NULL)
+ priority = atoi(val);
else
- prev = attr;
- }
-
- job->attrs->last = prev;
- job->attrs->current = prev;
-}
-
+ priority = 50;
-/*
- * 'add_printer()' - Add a printer to the system.
- */
+ ippAddInteger(con->request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-priority",
+ priority);
+ }
-static void
-add_printer(cupsd_client_t *con, /* I - Client connection */
- ipp_attribute_t *uri) /* I - URI of printer */
-{
- http_status_t status; /* Policy status */
- int i; /* Looping var */
- char method[HTTP_MAX_URI], /* Method portion of URI */
- username[HTTP_MAX_URI], /* Username portion of URI */
- host[HTTP_MAX_URI], /* Host portion of URI */
- resource[HTTP_MAX_URI]; /* Resource portion of URI */
- int port; /* Port portion of URI */
- cupsd_printer_t *printer; /* Printer/class */
- ipp_attribute_t *attr; /* Printer attribute */
- cups_file_t *fp; /* Script/PPD file */
- char line[1024]; /* Line from file... */
- char srcfile[1024], /* Source Script/PPD file */
- dstfile[1024]; /* Destination Script/PPD file */
- int modify; /* Non-zero if we are modifying */
+ if ((attr = ippFindAttribute(con->request, "job-name",
+ IPP_TAG_NAME)) != NULL)
+ title = attr->values[0].string.text;
+ else
+ ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
+ title = "Untitled");
+ if ((job = cupsdAddJob(priority, printer->name)) == NULL)
+ {
+ send_ipp_status(con, IPP_INTERNAL_ERROR,
+ _("Unable to add job for destination \"%s\"!"), dest);
+ return (NULL);
+ }
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ job->dtype = dtype;
+ job->attrs = con->request;
+ con->request = NULL;
- /*
- * Do we have a valid URI?
- */
+ add_job_uuid(con, job);
+ apply_printer_defaults(printer, job);
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
- if (strncmp(resource, "/printers/", 10) != 0 || strlen(resource) == 10)
+ if (con->username[0])
{
- /*
- * No, return an error...
- */
-
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("The printer-uri must be of the form "
- "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
- return;
- }
+ cupsdSetString(&job->username, con->username);
- /*
- * Do we have a valid printer name?
- */
+ if (attr)
+ cupsdSetString(&attr->values[0].string.text, con->username);
- if (!validate_name(resource + 10))
+ save_auth_info(con, job);
+ }
+ else if (attr)
{
- /*
- * No, return an error...
- */
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "add_job: requesting-user-name=\"%s\"",
+ attr->values[0].string.text);
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("The printer-uri \"%s\" contains invalid characters."),
- uri->values[0].string.text);
- return;
+ cupsdSetString(&job->username, attr->values[0].string.text);
}
+ else
+ cupsdSetString(&job->username, "anonymous");
- /*
- * Check policy...
- */
-
- if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+ if (!attr)
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
+ "job-originating-user-name", NULL, job->username);
+ else
{
- send_http_error(con, status);
- return;
+ attr->group_tag = IPP_TAG_JOB;
+ _cupsStrFree(attr->name);
+ attr->name = _cupsStrAlloc("job-originating-user-name");
}
- /*
- * See if the printer already exists; if not, create a new printer...
- */
-
- if ((printer = cupsdFindPrinter(resource + 10)) == NULL)
+ if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
+ IPP_TAG_ZERO)) != NULL)
{
/*
- * Printer doesn't exist; see if we have a class of the same name...
+ * Request contains a job-originating-host-name attribute; validate it...
*/
- if ((printer = cupsdFindClass(resource + 10)) != NULL &&
- !(printer->type & CUPS_PRINTER_REMOTE))
+ if (attr->value_tag != IPP_TAG_NAME ||
+ attr->num_values != 1 ||
+ strcmp(con->http.hostname, "localhost"))
{
/*
- * Yes, return an error...
+ * 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.
*/
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("A class named \"%s\" already exists!"),
- resource + 10);
- return;
- }
+ 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...
+ */
- /*
- * No, add the printer...
- */
+ 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.charset)
+ {
+ _cupsStrFree(attr->values[i].string.charset);
+ attr->values[i].string.charset = NULL;
+ }
+ }
- printer = cupsdAddPrinter(resource + 10);
- modify = 0;
- }
- else if (printer->type & CUPS_PRINTER_IMPLICIT)
- {
- /*
- * Rename the implicit printer to "AnyPrinter" or delete it...
- */
+ default :
+ break;
+ }
- if (ImplicitAnyClasses)
- {
- cupsArrayRemove(Printers, printer);
- cupsdSetStringf(&printer->name, "Any%s", resource + 10);
- cupsArrayAdd(Printers, printer);
- }
- else
- cupsdDeletePrinter(printer, 1);
+ /*
+ * Use the default connection hostname instead...
+ */
- /*
- * Add the printer as a new local printer...
- */
+ attr->value_tag = IPP_TAG_NAME;
+ attr->num_values = 1;
+ attr->values[0].string.text = _cupsStrAlloc(con->http.hostname);
+ }
- printer = cupsdAddPrinter(resource + 10);
- modify = 0;
+ attr->group_tag = IPP_TAG_JOB;
}
- else if (printer->type & CUPS_PRINTER_REMOTE)
+ else
{
/*
- * Rename the remote printer to "Printer@server"...
+ * No job-originating-host-name attribute, so use the hostname from
+ * the connection...
*/
- cupsdDeletePrinterFilters(printer);
- cupsArrayRemove(Printers, printer);
- cupsdSetStringf(&printer->name, "%s@%s", resource + 10, printer->hostname);
- cupsdSetPrinterAttrs(printer);
- cupsArrayAdd(Printers, printer);
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
+ "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;
+
+ /*
+ * Add remaining job attributes...
+ */
+
+ ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
+ job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
+ "job-state", IPP_JOB_STOPPED);
+ job->state_value = job->state->values[0].integer;
+ 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);
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
+ title);
+
+ if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
+ IPP_TAG_INTEGER)) != NULL)
+ attr->values[0].integer = 0;
+ else
+ attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
+ "job-k-octets", 0);
+
+ if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+ IPP_TAG_KEYWORD)) == NULL)
+ attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
+ if (!attr)
+ {
+ if ((val = cupsGetOption("job-hold-until", printer->num_options,
+ printer->options)) == NULL)
+ val = "no-hold";
+ 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") &&
+ !(printer->type & CUPS_PRINTER_REMOTE))
+ {
/*
- * Add the printer as a new local printer...
+ * Hold job until specified time...
*/
- printer = cupsdAddPrinter(resource + 10);
- modify = 0;
+ cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+ }
+ else if (job->attrs->request.op.operation_id == IPP_CREATE_JOB)
+ {
+ job->hold_until = time(NULL) + 60;
+ job->state->values[0].integer = IPP_JOB_HELD;
+ job->state_value = IPP_JOB_HELD;
}
else
- modify = 1;
+ {
+ job->state->values[0].integer = IPP_JOB_PENDING;
+ job->state_value = IPP_JOB_PENDING;
+ }
- /*
- * Look for attributes and copy them over as needed...
- */
+ if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
+ Classification)
+ {
+ /*
+ * Add job sheets options...
+ */
- if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL)
- cupsdSetString(&printer->location, attr->values[0].string.text);
+ if ((attr = ippFindAttribute(job->attrs, "job-sheets",
+ IPP_TAG_ZERO)) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Adding default job-sheets values \"%s,%s\"...",
+ printer->job_sheets[0], printer->job_sheets[1]);
- if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL)
- cupsdSetString(&printer->info, attr->values[0].string.text);
+ attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets",
+ 2, NULL, NULL);
+ attr->values[0].string.text = _cupsStrAlloc(printer->job_sheets[0]);
+ attr->values[1].string.text = _cupsStrAlloc(printer->job_sheets[1]);
+ }
+
+ job->job_sheets = attr;
- if ((attr = ippFindAttribute(con->request, "device-uri", IPP_TAG_URI)) != NULL)
- {
/*
- * Do we have a valid device URI?
+ * Enforce classification level if set...
*/
- httpSeparateURI(attr->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
-
- if (!strcmp(method, "file"))
+ if (Classification)
{
- /*
- * See if the administrator has enabled file devices...
- */
+ cupsdLogMessage(CUPSD_LOG_INFO,
+ "Classification=\"%s\", ClassifyOverride=%d",
+ Classification ? Classification : "(null)",
+ ClassifyOverride);
- if (!FileDevice && strcmp(resource, "/dev/null"))
+ if (ClassifyOverride)
{
- /*
- * File devices are disabled and the URL is not file:/dev/null...
- */
+ if (!strcmp(attr->values[0].string.text, "none") &&
+ (attr->num_values == 1 ||
+ !strcmp(attr->values[1].string.text, "none")))
+ {
+ /*
+ * Force the leading banner to have the classification on it...
+ */
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("File device URIs have been disabled! "
- "To enable, see the FileDevice directive in "
- "\"%s/cupsd.conf\"."),
- ServerRoot);
- return;
- }
- }
- else
- {
- /*
- * See if the backend exists and is executable...
- */
+ cupsdSetString(&attr->values[0].string.text, Classification);
- snprintf(srcfile, sizeof(srcfile), "%s/backend/%s", ServerBin, method);
- if (access(srcfile, X_OK))
+ cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
+ "job-sheets=\"%s,none\", "
+ "job-originating-user-name=\"%s\"",
+ job->id, Classification, job->username);
+ }
+ else if (attr->num_values == 2 &&
+ strcmp(attr->values[0].string.text,
+ attr->values[1].string.text) &&
+ strcmp(attr->values[0].string.text, "none") &&
+ strcmp(attr->values[1].string.text, "none"))
+ {
+ /*
+ * Can't put two different security markings on the same document!
+ */
+
+ cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text);
+
+ cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
+ "job-sheets=\"%s,%s\", "
+ "job-originating-user-name=\"%s\"",
+ job->id, attr->values[0].string.text,
+ attr->values[1].string.text, job->username);
+ }
+ else if (strcmp(attr->values[0].string.text, Classification) &&
+ strcmp(attr->values[0].string.text, "none") &&
+ (attr->num_values == 1 ||
+ (strcmp(attr->values[1].string.text, Classification) &&
+ strcmp(attr->values[1].string.text, "none"))))
+ {
+ if (attr->num_values == 1)
+ cupsdLogMessage(CUPSD_LOG_NOTICE,
+ "[Job %d] CLASSIFICATION OVERRIDDEN "
+ "job-sheets=\"%s\", "
+ "job-originating-user-name=\"%s\"",
+ job->id, attr->values[0].string.text, job->username);
+ else
+ cupsdLogMessage(CUPSD_LOG_NOTICE,
+ "[Job %d] CLASSIFICATION OVERRIDDEN "
+ "job-sheets=\"%s,%s\",fffff "
+ "job-originating-user-name=\"%s\"",
+ job->id, attr->values[0].string.text,
+ attr->values[1].string.text, job->username);
+ }
+ }
+ else if (strcmp(attr->values[0].string.text, Classification) &&
+ (attr->num_values == 1 ||
+ strcmp(attr->values[1].string.text, Classification)))
{
/*
- * Could not find device in list!
+ * Force the banner to have the classification on it...
*/
- send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"),
- attr->values[0].string.text);
- return;
- }
- }
+ 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);
+ }
+ else
+ {
+ if (attr->num_values == 1 ||
+ strcmp(attr->values[0].string.text, "none"))
+ cupsdSetString(&(attr->values[0].string.text), Classification);
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Setting %s device-uri to \"%s\" (was \"%s\".)",
- printer->name,
- cupsdSanitizeURI(attr->values[0].string.text, line,
- sizeof(line)),
- cupsdSanitizeURI(printer->device_uri, resource,
- sizeof(resource)));
+ if (attr->num_values > 1 &&
+ strcmp(attr->values[1].string.text, "none"))
+ cupsdSetString(&(attr->values[1].string.text), Classification);
+ }
- cupsdSetString(&printer->device_uri, attr->values[0].string.text);
- }
+ if (attr->num_values > 1)
+ cupsdLogMessage(CUPSD_LOG_NOTICE,
+ "[Job %d] CLASSIFICATION FORCED "
+ "job-sheets=\"%s,%s\", "
+ "job-originating-user-name=\"%s\"",
+ job->id, attr->values[0].string.text,
+ attr->values[1].string.text, job->username);
+ else
+ cupsdLogMessage(CUPSD_LOG_NOTICE,
+ "[Job %d] CLASSIFICATION FORCED "
+ "job-sheets=\"%s\", "
+ "job-originating-user-name=\"%s\"",
+ job->id, Classification, job->username);
+ }
+ }
- if ((attr = ippFindAttribute(con->request, "port-monitor", IPP_TAG_KEYWORD)) != NULL)
- {
- ipp_attribute_t *supported; /* port-monitor-supported attribute */
+ /*
+ * See if we need to add the starting sheet...
+ */
+ if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
+ {
+ cupsdLogMessage(CUPSD_LOG_INFO,
+ "Adding start banner page \"%s\" to job %d.",
+ attr->values[0].string.text, job->id);
- supported = ippFindAttribute(printer->attrs, "port-monitor-supported",
- IPP_TAG_KEYWORD);
- for (i = 0; i < supported->num_values; i ++)
- if (!strcmp(supported->values[i].string.text,
- attr->values[0].string.text))
- break;
+ kbytes = copy_banner(con, job, attr->values[0].string.text);
- if (i >= supported->num_values)
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"!"),
- attr->values[0].string.text);
- return;
+ cupsdUpdateQuota(printer, job->username, 0, kbytes);
+ }
+ }
+ else if ((attr = ippFindAttribute(job->attrs, "job-sheets",
+ IPP_TAG_ZERO)) != NULL)
+ job->sheets = attr;
+
+ /*
+ * Fill in the response info...
+ */
+
+ snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
+ LocalPort, job->id);
+
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
+ job_uri);
+
+ ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
+
+ ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
+ job->state_value);
+ add_job_state_reasons(con, job);
+
+ con->response->request.status.status_code = IPP_OK;
+
+ /*
+ * Add any job subscriptions...
+ */
+
+ add_job_subscriptions(con, job);
+
+ /*
+ * Set all but the first two attributes to the job attributes group...
+ */
+
+ for (attr = job->attrs->attrs->next->next; attr; attr = attr->next)
+ attr->group_tag = IPP_TAG_JOB;
+
+ /*
+ * Fire the "job created" event...
+ */
+
+ cupsdAddEvent(CUPSD_EVENT_JOB_CREATED, printer, job, "Job created.");
+
+ /*
+ * Return the new job...
+ */
+
+ return (job);
+}
+
+
+/*
+ * 'add_job_state_reasons()' - Add the "job-state-reasons" attribute based
+ * upon the job and printer state...
+ */
+
+static void
+add_job_state_reasons(
+ cupsd_client_t *con, /* I - Client connection */
+ cupsd_job_t *job) /* I - Job info */
+{
+ cupsd_printer_t *dest; /* Destination printer */
+
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_job_state_reasons(%p[%d], %d)",
+ con, con->http.fd, job ? job->id : 0);
+
+ switch (job ? job->state_value : IPP_JOB_CANCELLED)
+ {
+ case IPP_JOB_PENDING :
+ if (job->dtype & CUPS_PRINTER_CLASS)
+ dest = cupsdFindClass(job->dest);
+ else
+ dest = cupsdFindPrinter(job->dest);
+
+ if (dest && dest->state == IPP_PRINTER_STOPPED)
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "printer-stopped");
+ else
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "none");
+ break;
+
+ case IPP_JOB_HELD :
+ if (ippFindAttribute(job->attrs, "job-hold-until",
+ IPP_TAG_KEYWORD) != NULL ||
+ ippFindAttribute(job->attrs, "job-hold-until",
+ IPP_TAG_NAME) != NULL)
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "job-hold-until-specified");
+ else
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "job-incoming");
+ break;
+
+ case IPP_JOB_PROCESSING :
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "job-printing");
+ break;
+
+ case IPP_JOB_STOPPED :
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "job-stopped");
+ break;
+
+ case IPP_JOB_CANCELLED :
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "job-canceled-by-user");
+ break;
+
+ case IPP_JOB_ABORTED :
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "aborted-by-system");
+ break;
+
+ case IPP_JOB_COMPLETED :
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD,
+ "job-state-reasons", NULL, "job-completed-successfully");
+ break;
+ }
+}
+
+
+/*
+ * 'add_job_subscriptions()' - Add any subcriptions for a job.
+ */
+
+static void
+add_job_subscriptions(
+ cupsd_client_t *con, /* I - Client connection */
+ cupsd_job_t *job) /* I - Newly created job */
+{
+ int i; /* Looping var */
+ ipp_attribute_t *prev, /* Previous attribute */
+ *next, /* Next attribute */
+ *attr; /* Current attribute */
+ cupsd_subscription_t *sub; /* Subscription object */
+ const char *recipient, /* notify-recipient-uri */
+ *pullmethod; /* notify-pull-method */
+ ipp_attribute_t *user_data; /* notify-user-data */
+ int interval; /* notify-time-interval */
+ unsigned mask; /* notify-events */
+
+
+ /*
+ * Find the first subscription group attribute; return if we have
+ * none...
+ */
+
+ for (attr = job->attrs->attrs, prev = NULL;
+ attr;
+ prev = attr, attr = attr->next)
+ if (attr->group_tag == IPP_TAG_SUBSCRIPTION)
+ break;
+
+ if (!attr)
+ return;
+
+ /*
+ * Process the subscription attributes in the request...
+ */
+
+ while (attr)
+ {
+ recipient = NULL;
+ pullmethod = NULL;
+ user_data = NULL;
+ interval = 0;
+ mask = CUPSD_EVENT_NONE;
+
+ while (attr && attr->group_tag != IPP_TAG_ZERO)
+ {
+ if (!strcmp(attr->name, "notify-recipient") &&
+ attr->value_tag == IPP_TAG_URI)
+ recipient = attr->values[0].string.text;
+ else if (!strcmp(attr->name, "notify-pull-method") &&
+ attr->value_tag == IPP_TAG_KEYWORD)
+ pullmethod = attr->values[0].string.text;
+ else if (!strcmp(attr->name, "notify-charset") &&
+ attr->value_tag == IPP_TAG_CHARSET &&
+ strcmp(attr->values[0].string.text, "us-ascii") &&
+ strcmp(attr->values[0].string.text, "utf-8"))
+ {
+ send_ipp_status(con, IPP_CHARSET,
+ _("Character set \"%s\" not supported!"),
+ attr->values[0].string.text);
+ return;
+ }
+ else if (!strcmp(attr->name, "notify-natural-language") &&
+ (attr->value_tag != IPP_TAG_LANGUAGE ||
+ strcmp(attr->values[0].string.text, DefaultLanguage)))
+ {
+ send_ipp_status(con, IPP_CHARSET,
+ _("Language \"%s\" not supported!"),
+ attr->values[0].string.text);
+ return;
+ }
+ else if (!strcmp(attr->name, "notify-user-data") &&
+ attr->value_tag == IPP_TAG_STRING)
+ {
+ if (attr->num_values > 1 || attr->values[0].unknown.length > 63)
+ {
+ send_ipp_status(con, IPP_REQUEST_VALUE,
+ _("The notify-user-data value is too large "
+ "(%d > 63 octets)!"),
+ attr->values[0].unknown.length);
+ return;
+ }
+
+ user_data = attr;
+ }
+ else if (!strcmp(attr->name, "notify-events") &&
+ attr->value_tag == IPP_TAG_KEYWORD)
+ {
+ for (i = 0; i < attr->num_values; i ++)
+ mask |= cupsdEventValue(attr->values[i].string.text);
+ }
+ else if (!strcmp(attr->name, "notify-lease-duration"))
+ {
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("The notify-lease-duration attribute cannot be "
+ "used with job subscriptions."));
+ return;
+ }
+ else if (!strcmp(attr->name, "notify-time-interval") &&
+ attr->value_tag == IPP_TAG_INTEGER)
+ interval = attr->values[0].integer;
+
+ attr = attr->next;
+ }
+
+ if (!recipient && !pullmethod)
+ break;
+
+ if (mask == CUPSD_EVENT_NONE)
+ mask = CUPSD_EVENT_JOB_COMPLETED;
+
+ sub = cupsdAddSubscription(mask, cupsdFindDest(job->dest), job, recipient,
+ 0);
+
+ sub->interval = interval;
+
+ cupsdSetString(&sub->owner, job->username);
+
+ if (user_data)
+ {
+ sub->user_data_len = user_data->values[0].unknown.length;
+ memcpy(sub->user_data, user_data->values[0].unknown.data,
+ sub->user_data_len);
+ }
+
+ ippAddSeparator(con->response);
+ ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+ "notify-subscription-id", sub->id);
+
+ if (attr)
+ attr = attr->next;
+ }
+
+ cupsdSaveAllSubscriptions();
+
+ /*
+ * Remove all of the subscription attributes from the job request...
+ */
+
+ for (attr = job->attrs->attrs, prev = NULL; attr; attr = next)
+ {
+ next = attr->next;
+
+ if (attr->group_tag == IPP_TAG_SUBSCRIPTION ||
+ attr->group_tag == IPP_TAG_ZERO)
+ {
+ /*
+ * Free and remove this attribute...
+ */
+
+ _ippFreeAttr(attr);
+
+ if (prev)
+ prev->next = next;
+ else
+ job->attrs->attrs = next;
+ }
+ else
+ prev = attr;
+ }
+
+ job->attrs->last = prev;
+ job->attrs->current = prev;
+}
+
+
+/*
+ * 'add_job_uuid()' - Add job-uuid attribute to a job.
+ *
+ * See RFC 4122 for the definition of UUIDs and the format.
+ */
+
+static void
+add_job_uuid(cupsd_client_t *con, /* I - Client connection */
+ cupsd_job_t *job) /* I - Job */
+{
+ char uuid[1024]; /* job-uuid string */
+ ipp_attribute_t *attr; /* job-uuid attribute */
+ _cups_md5_state_t md5state; /* MD5 state */
+ unsigned char md5sum[16]; /* MD5 digest/sum */
+
+
+ /*
+ * First see if the job already has a job-uuid attribute; if so, return...
+ */
+
+ if ((attr = ippFindAttribute(job->attrs, "job-uuid", IPP_TAG_URI)) != NULL)
+ return;
+
+ /*
+ * No job-uuid attribute, so build a version 3 UUID with the local job
+ * ID at the end; see RFC 4122 for details. Start with the MD5 sum of
+ * the ServerName, server name and port that the client connected to,
+ * and local job ID...
+ */
+
+ snprintf(uuid, sizeof(uuid), "%s:%s:%d:%d", ServerName, con->servername,
+ con->serverport, job->id);
+
+ _cupsMD5Init(&md5state);
+ _cupsMD5Append(&md5state, (unsigned char *)uuid, strlen(uuid));
+ _cupsMD5Finish(&md5state, md5sum);
+
+ /*
+ * Format the UUID URI using the MD5 sum and job ID.
+ */
+
+ snprintf(uuid, sizeof(uuid),
+ "urn:uuid:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
+ "%02x%02x%02x%02x%02x%02x",
+ md5sum[0], md5sum[1], md5sum[2], md5sum[3], md5sum[4], md5sum[5],
+ (md5sum[6] & 15) | 0x30, md5sum[7], (md5sum[8] & 0x3f) | 0x40,
+ md5sum[9], md5sum[10], md5sum[11], md5sum[12], md5sum[13],
+ md5sum[14], md5sum[15]);
+
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-uuid", NULL, uuid);
+}
+
+
+/*
+ * 'add_printer()' - Add a printer to the system.
+ */
+
+static void
+add_printer(cupsd_client_t *con, /* I - Client connection */
+ ipp_attribute_t *uri) /* I - URI of printer */
+{
+ http_status_t status; /* Policy status */
+ int i; /* Looping var */
+ char method[HTTP_MAX_URI], /* Method portion of URI */
+ username[HTTP_MAX_URI], /* Username portion of URI */
+ host[HTTP_MAX_URI], /* Host portion of URI */
+ resource[HTTP_MAX_URI]; /* Resource portion of URI */
+ int port; /* Port portion of URI */
+ cupsd_printer_t *printer; /* Printer/class */
+ ipp_attribute_t *attr; /* Printer attribute */
+ cups_file_t *fp; /* Script/PPD file */
+ char line[1024]; /* Line from file... */
+ char srcfile[1024], /* Source Script/PPD file */
+ dstfile[1024]; /* Destination Script/PPD file */
+ int modify; /* Non-zero if we are modifying */
+ char newname[IPP_MAX_NAME]; /* New printer name */
+ int need_restart_job; /* Need to restart job? */
+
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer(%p[%d], %s)", con,
+ con->http.fd, uri->values[0].string.text);
+
+ /*
+ * Do we have a valid URI?
+ */
+
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
+
+ if (strncmp(resource, "/printers/", 10) || strlen(resource) == 10)
+ {
+ /*
+ * No, return an error...
+ */
+
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("The printer-uri must be of the form "
+ "\"ipp://HOSTNAME/printers/PRINTERNAME\"."));
+ return;
+ }
+
+ /*
+ * Do we have a valid printer name?
+ */
+
+ if (!validate_name(resource + 10))
+ {
+ /*
+ * No, return an error...
+ */
+
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("The printer-uri \"%s\" contains invalid characters."),
+ uri->values[0].string.text);
+ return;
+ }
+
+ /*
+ * Check policy...
+ */
+
+ if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+ {
+ send_http_error(con, status);
+ return;
+ }
+
+ /*
+ * See if the printer already exists; if not, create a new printer...
+ */
+
+ if ((printer = cupsdFindPrinter(resource + 10)) == NULL)
+ {
+ /*
+ * Printer doesn't exist; see if we have a class of the same name...
+ */
+
+ if ((printer = cupsdFindClass(resource + 10)) != NULL &&
+ !(printer->type & CUPS_PRINTER_REMOTE))
+ {
+ /*
+ * Yes, return an error...
+ */
+
+ send_ipp_status(con, IPP_NOT_POSSIBLE,
+ _("A class named \"%s\" already exists!"),
+ resource + 10);
+ return;
+ }
+
+ /*
+ * No, add the printer...
+ */
+
+ printer = cupsdAddPrinter(resource + 10);
+ modify = 0;
+ }
+ else if (printer->type & CUPS_PRINTER_IMPLICIT)
+ {
+ /*
+ * Rename the implicit printer to "AnyPrinter" or delete it...
+ */
+
+ if (ImplicitAnyClasses)
+ {
+ snprintf(newname, sizeof(newname), "Any%s", resource + 10);
+ cupsdRenamePrinter(printer, newname);
+ }
+ else
+ cupsdDeletePrinter(printer, 1);
+
+ /*
+ * Add the printer as a new local printer...
+ */
+
+ printer = cupsdAddPrinter(resource + 10);
+ modify = 0;
+ }
+ else if (printer->type & CUPS_PRINTER_REMOTE)
+ {
+ /*
+ * Rename the remote printer to "Printer@server"...
+ */
+
+ snprintf(newname, sizeof(newname), "%s@%s", resource + 10,
+ printer->hostname);
+ cupsdRenamePrinter(printer, newname);
+
+ /*
+ * Add the printer as a new local printer...
+ */
+
+ printer = cupsdAddPrinter(resource + 10);
+ modify = 0;
+ }
+ else
+ modify = 1;
+
+ /*
+ * Look for attributes and copy them over as needed...
+ */
+
+ need_restart_job = 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-info",
+ IPP_TAG_TEXT)) != NULL)
+ cupsdSetString(&printer->info, attr->values[0].string.text);
+
+ if ((attr = ippFindAttribute(con->request, "device-uri",
+ IPP_TAG_URI)) != NULL)
+ {
+ /*
+ * Do we have a valid device URI?
+ */
+
+ need_restart_job = 1;
+
+ httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
+
+ if (!strcmp(method, "file"))
+ {
+ /*
+ * See if the administrator has enabled file devices...
+ */
+
+ if (!FileDevice && strcmp(resource, "/dev/null"))
+ {
+ /*
+ * File devices are disabled and the URL is not file:/dev/null...
+ */
+
+ send_ipp_status(con, IPP_NOT_POSSIBLE,
+ _("File device URIs have been disabled! "
+ "To enable, see the FileDevice directive in "
+ "\"%s/cupsd.conf\"."),
+ ServerRoot);
+ return;
+ }
+ }
+ else
+ {
+ /*
+ * See if the backend exists and is executable...
+ */
+
+ snprintf(srcfile, sizeof(srcfile), "%s/backend/%s", ServerBin, method);
+ if (access(srcfile, X_OK))
+ {
+ /*
+ * Could not find device in list!
+ */
+
+ send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad device-uri \"%s\"!"),
+ attr->values[0].string.text);
+ return;
+ }
+ }
+
+ cupsdLogMessage(CUPSD_LOG_INFO,
+ "Setting %s device-uri to \"%s\" (was \"%s\".)",
+ printer->name,
+ cupsdSanitizeURI(attr->values[0].string.text, line,
+ sizeof(line)),
+ cupsdSanitizeURI(printer->device_uri, resource,
+ sizeof(resource)));
+
+ cupsdSetString(&printer->device_uri, attr->values[0].string.text);
+ }
+
+ if ((attr = ippFindAttribute(con->request, "port-monitor",
+ IPP_TAG_KEYWORD)) != NULL)
+ {
+ ipp_attribute_t *supported; /* port-monitor-supported attribute */
+
+
+ need_restart_job = 1;
+
+ supported = ippFindAttribute(printer->attrs, "port-monitor-supported",
+ IPP_TAG_KEYWORD);
+ for (i = 0; i < supported->num_values; i ++)
+ if (!strcmp(supported->values[i].string.text,
+ attr->values[0].string.text))
+ break;
+
+ if (i >= supported->num_values)
+ {
+ send_ipp_status(con, IPP_NOT_POSSIBLE, _("Bad port-monitor \"%s\"!"),
+ attr->values[0].string.text);
+ return;
}
cupsdLogMessage(CUPSD_LOG_INFO,
cupsdClearString(&printer->port_monitor);
}
- if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs",
+ IPP_TAG_BOOLEAN)) != NULL)
{
cupsdLogMessage(CUPSD_LOG_INFO,
"Setting %s printer-is-accepting-jobs to %d (was %d.)",
cupsdAddPrinterHistory(printer);
}
- 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 (printer->shared && !attr->values[0].boolean)
cupsdSendBrowseDelete(printer);
printer->shared = attr->values[0].boolean;
}
- if ((attr = ippFindAttribute(con->request, "printer-state", IPP_TAG_ENUM)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-state",
+ IPP_TAG_ENUM)) != NULL)
{
if (attr->values[0].integer != IPP_PRINTER_IDLE &&
attr->values[0].integer != IPP_PRINTER_STOPPED)
if (attr->values[0].integer == IPP_PRINTER_STOPPED)
cupsdStopPrinter(printer, 0);
else
+ {
+ need_restart_job = 1;
cupsdSetPrinterState(printer, (ipp_pstate_t)(attr->values[0].integer), 0);
+ }
}
- if ((attr = ippFindAttribute(con->request, "printer-state-message", IPP_TAG_TEXT)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "printer-state-message",
+ IPP_TAG_TEXT)) != NULL)
{
strlcpy(printer->state_message, attr->values[0].string.text,
sizeof(printer->state_message));
cupsdAddPrinterHistory(printer);
}
- if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL &&
- !Classification)
- {
- cupsdSetString(&printer->job_sheets[0], attr->values[0].string.text);
- if (attr->num_values > 1)
- cupsdSetString(&printer->job_sheets[1], attr->values[1].string.text);
- else
- cupsdSetString(&printer->job_sheets[1], "none");
- }
- if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",
- IPP_TAG_ZERO)) != NULL)
- {
- cupsdFreePrinterUsers(printer);
-
- printer->deny_users = 0;
- if (attr->value_tag == IPP_TAG_NAME &&
- (attr->num_values > 1 ||
- strcmp(attr->values[0].string.text, "all") != 0))
- for (i = 0; i < attr->num_values; i ++)
- cupsdAddPrinterUser(printer, attr->values[i].string.text);
- }
- else if ((attr = ippFindAttribute(con->request, "requesting-user-name-denied",
- IPP_TAG_ZERO)) != NULL)
- {
- cupsdFreePrinterUsers(printer);
-
- printer->deny_users = 1;
- if (attr->value_tag == IPP_TAG_NAME &&
- (attr->num_values > 1 ||
- strcmp(attr->values[0].string.text, "none") != 0))
- for (i = 0; i < attr->num_values; i ++)
- cupsdAddPrinterUser(printer, attr->values[i].string.text);
- }
- if ((attr = ippFindAttribute(con->request, "job-quota-period",
- IPP_TAG_INTEGER)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-quota-period to %d...",
- attr->values[0].integer);
- cupsdFreeQuotas(printer);
- printer->quota_period = attr->values[0].integer;
- }
- if ((attr = ippFindAttribute(con->request, "job-k-limit",
- IPP_TAG_INTEGER)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-k-limit to %d...",
- attr->values[0].integer);
- cupsdFreeQuotas(printer);
- printer->k_limit = attr->values[0].integer;
- }
- if ((attr = ippFindAttribute(con->request, "job-page-limit",
- IPP_TAG_INTEGER)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-page-limit to %d...",
- attr->values[0].integer);
- cupsdFreeQuotas(printer);
- printer->page_limit = attr->values[0].integer;
- }
- if ((attr = ippFindAttribute(con->request, "printer-op-policy",
- IPP_TAG_NAME)) != NULL)
- {
- cupsd_policy_t *p; /* Policy */
-
-
- if ((p = cupsdFindPolicy(attr->values[0].string.text)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "Setting printer-op-policy to \"%s\"...",
- attr->values[0].string.text);
- cupsdSetString(&printer->op_policy, attr->values[0].string.text);
- printer->op_policy_ptr = p;
- }
- else
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("Unknown printer-op-policy \"%s\"."),
- attr->values[0].string.text);
- return;
- }
- }
- if ((attr = ippFindAttribute(con->request, "printer-error-policy",
- IPP_TAG_NAME)) != NULL)
- {
- if (strcmp(attr->values[0].string.text, "abort-job") &&
- strcmp(attr->values[0].string.text, "retry-job") &&
- strcmp(attr->values[0].string.text, "stop-printer"))
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("Unknown printer-error-policy \"%s\"."),
- attr->values[0].string.text);
- return;
- }
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "Setting printer-error-policy to \"%s\"...",
- attr->values[0].string.text);
- cupsdSetString(&printer->error_policy, attr->values[0].string.text);
- }
+ set_printer_defaults(con, printer);
/*
* See if we have all required attributes...
*/
if (!printer->device_uri)
- cupsdSetString(&printer->device_uri, "file:/dev/null");
+ cupsdSetString(&printer->device_uri, "file:///dev/null");
/*
* See if we have an interface script or PPD file attached to the request...
if (con->filename)
{
+ need_restart_job = 1;
+
strlcpy(srcfile, con->filename, sizeof(srcfile));
- if ((fp = cupsFileOpen(srcfile, "rb")) != NULL)
+ if ((fp = cupsFileOpen(srcfile, "rb")))
{
/*
* Yes; get the first line from it...
}
}
}
- else if ((attr = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME)) != NULL)
+ else if ((attr = ippFindAttribute(con->request, "ppd-name",
+ IPP_TAG_NAME)) != NULL)
{
+ need_restart_job = 1;
+
if (!strcmp(attr->values[0].string.text, "raw"))
{
/*
}
}
- /*
- * Make this printer the default if there is none...
- */
-
- if (DefaultPrinter == NULL)
- DefaultPrinter = printer;
-
/*
* Update the printer attributes and return...
*/
cupsdSetPrinterAttrs(printer);
cupsdSaveAllPrinters();
- if (printer->job != NULL)
+ if (need_restart_job && printer->job)
{
cupsd_job_t *job;
job = (cupsd_job_t *)printer->job;
cupsdStopJob(job, 1);
+
job->state->values[0].integer = IPP_JOB_PENDING;
+ job->state_value = IPP_JOB_PENDING;
}
- cupsdCheckJobs();
+ if (need_restart_job)
+ cupsdCheckJobs();
cupsdWritePrintcap();
{
cupsdAddEvent(CUPSD_EVENT_PRINTER_MODIFIED, printer, NULL,
"Printer \"%s\" modified by \"%s\".", printer->name,
- con->username);
+ get_username(con));
cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" modified by \"%s\".",
- printer->name, con->username);
+ printer->name, get_username(con));
}
else
{
cupsdAddEvent(CUPSD_EVENT_PRINTER_ADDED, printer, NULL,
"New printer \"%s\" added by \"%s\".", printer->name,
- con->username);
+ get_username(con));
cupsdLogMessage(CUPSD_LOG_INFO, "New printer \"%s\" added by \"%s\".",
- printer->name, con->username);
+ printer->name, get_username(con));
}
con->response->request.status.status_code = IPP_OK;
}
+/*
+ * 'apply_printer_defaults()' - Apply printer default options to a job.
+ */
+
+static void
+apply_printer_defaults(
+ cupsd_printer_t *printer, /* I - Printer */
+ cupsd_job_t *job) /* I - Job */
+{
+ int i, /* Looping var */
+ num_options; /* Number of default options */
+ cups_option_t *options, /* Default options */
+ *option; /* Current option */
+
+
+ /*
+ * Collect all of the default options and add the missing ones to the
+ * job object...
+ */
+
+ for (i = printer->num_options, num_options = 0, option = printer->options;
+ i > 0;
+ i --, option ++)
+ if (!ippFindAttribute(job->attrs, option->name, IPP_TAG_ZERO))
+ {
+ num_options = cupsAddOption(option->name, option->value, num_options,
+ &options);
+ }
+
+ /*
+ * Encode these options as attributes in the job object...
+ */
+
+ cupsEncodeOptions2(job->attrs, num_options, options, IPP_TAG_JOB);
+ cupsFreeOptions(num_options, options);
+}
+
+
/*
* 'authenticate_job()' - Set job authentication info.
*/
* Got a printer URI; see if we also have a job-id attribute...
*/
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Got a printer-uri attribute but no job-id!"));
* Got a job URI; parse it to get the job ID...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if (strncmp(resource, "/jobs/", 6))
{
* See if the job has been completed...
*/
- if (job->state->values[0].integer != IPP_JOB_HELD)
+ if (job->state_value != IPP_JOB_HELD)
{
/*
* Return a "not-possible" error...
if (!validate_user(job, con, job->username, username, sizeof(username)))
{
- send_ipp_status(con, IPP_FORBIDDEN,
- _("You are not authorized to authenticate "
- "job #%d owned by \"%s\"!"),
- jobid, job->username);
+ send_http_error(con, HTTP_UNAUTHORIZED);
return;
}
* Reset the job-hold-until value to "no-hold"...
*/
- if ((attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_KEYWORD)) == NULL)
+ if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+ IPP_TAG_KEYWORD)) == NULL)
attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
- if (attr != NULL)
+ if (attr)
{
attr->value_tag = IPP_TAG_KEYWORD;
cupsdSetString(&(attr->values[0].string.text), "no-hold");
* "my-jobs" is specified...
*/
- if ((attr = ippFindAttribute(con->request, "my-jobs", IPP_TAG_BOOLEAN)) != NULL &&
+ if ((attr = ippFindAttribute(con->request, "my-jobs",
+ IPP_TAG_BOOLEAN)) != NULL &&
attr->values[0].boolean)
{
- if ((attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "requesting-user-name",
+ IPP_TAG_NAME)) != NULL)
username = attr->values[0].string.text;
else
{
* Look for the "purge-jobs" attribute...
*/
- if ((attr = ippFindAttribute(con->request, "purge-jobs", IPP_TAG_BOOLEAN)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "purge-jobs",
+ IPP_TAG_BOOLEAN)) != NULL)
purge = attr->values[0].boolean;
else
purge = 1;
* And if the destination is valid...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- userpass, sizeof(userpass), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), userpass, sizeof(userpass), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
* Bad URI?
*/
- if (!strncmp(resource, "/printers/", 10) ||
- !strncmp(resource, "/classes/", 9))
+ if ((!strncmp(resource, "/printers/", 10) && resource[10]) ||
+ (!strncmp(resource, "/classes/", 9) && resource[9]))
{
send_ipp_status(con, IPP_NOT_FOUND,
_("The printer or class was not found."));
cupsdCancelJobs(NULL, username, purge);
cupsdLogMessage(CUPSD_LOG_INFO, "All jobs were %s by \"%s\".",
- purge ? "purged" : "cancelled", con->username);
+ purge ? "purged" : "cancelled", get_username(con));
}
else
{
cupsdCancelJobs(dest, username, purge);
cupsdLogMessage(CUPSD_LOG_INFO, "All jobs on \"%s\" were %s by \"%s\".",
- dest, purge ? "purged" : "cancelled", con->username);
+ dest, purge ? "purged" : "cancelled", get_username(con));
}
con->response->request.status.status_code = IPP_OK;
* Got a printer URI; see if we also have a job-id attribute...
*/
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Got a printer-uri attribute but no job-id!"));
* Find the current job on the specified printer...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs);
job;
job = (cupsd_job_t *)cupsArrayNext(ActiveJobs))
- if (job->state->values[0].integer <= IPP_JOB_PROCESSING &&
+ if (job->state_value <= IPP_JOB_PROCESSING &&
!strcasecmp(job->dest, dest))
break;
- if (job != NULL)
+ if (job)
jobid = job->id;
else
{
* Got a job URI; parse it to get the job ID...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if (strncmp(resource, "/jobs/", 6))
{
if (!validate_user(job, con, job->username, username, sizeof(username)))
{
- send_ipp_status(con, IPP_FORBIDDEN,
- _("You are not authorized to delete job #%d "
- "owned by \"%s\"!"),
- jobid, job->username);
+ send_http_error(con, HTTP_UNAUTHORIZED);
return;
}
* we can't cancel...
*/
- if (job->state->values[0].integer >= IPP_JOB_CANCELLED)
+ if (job->state_value >= IPP_JOB_CANCELLED)
{
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("Job #%d is already %s - can\'t cancel."), jobid,
- job->state->values[0].integer == IPP_JOB_CANCELLED ? "cancelled" :
- job->state->values[0].integer == IPP_JOB_ABORTED ? "aborted" :
+ job->state_value == IPP_JOB_CANCELLED ? "cancelled" :
+ job->state_value == IPP_JOB_ABORTED ? "aborted" :
"completed");
return;
}
* 'cancel_subscription()' - Cancel a subscription.
*/
-static void
-cancel_subscription(
- cupsd_client_t *con, /* I - Client connection */
- int sub_id) /* I - Subscription ID */
-{
+static void
+cancel_subscription(
+ cupsd_client_t *con, /* I - Client connection */
+ int sub_id) /* I - Subscription ID */
+{
+ http_status_t status; /* Policy status */
+ cupsd_subscription_t *sub; /* Subscription */
+
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cancel_subscription(con=%p[%d], sub_id=%d)",
+ con, con->http.fd, sub_id);
+
+ /*
+ * Is the subscription ID valid?
+ */
+
+ if ((sub = cupsdFindSubscription(sub_id)) == NULL)
+ {
+ /*
+ * Bad subscription ID...
+ */
+
+ send_ipp_status(con, IPP_NOT_FOUND,
+ _("notify-subscription-id %d no good!"), sub_id);
+ return;
+ }
+
+ /*
+ * Check policy...
+ */
+
+ if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr :
+ DefaultPolicyPtr,
+ con, sub->owner)) != HTTP_OK)
+ {
+ send_http_error(con, status);
+ return;
+ }
+
+ /*
+ * Cancel the subscription...
+ */
+
+ cupsdDeleteSubscription(sub, 1);
+
+ con->response->request.status.status_code = IPP_OK;
}
cupsd_printer_t *p) /* I - Printer or class */
{
int i; /* Looping var */
- ipp_attribute_t *attr; /* Current attribute */
char username[33]; /* Username */
cupsd_quota_t *q; /* Quota data */
struct passwd *pw; /* User password data */
* Check input...
*/
- if (con == NULL || p == NULL)
+ if (!con || !p)
return (0);
/*
* Figure out who is printing...
*/
- attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME);
-
- if (con->username[0])
- strlcpy(username, con->username, sizeof(username));
- else if (attr != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "check_quotas: requesting-user-name = \"%s\"",
- attr->values[0].string.text);
-
- strlcpy(username, attr->values[0].string.text, sizeof(username));
- }
- else
- strcpy(username, "anonymous");
+ strlcpy(username, get_username(con), sizeof(username));
/*
* Check global active job limits for printers and users...
else
{
for (i = 0; i < attr->num_values; i ++)
- toattr->values[i].string.text = strdup(attr->values[i].string.text);
+ toattr->values[i].string.text = _cupsStrAlloc(attr->values[i].string.text);
}
break;
{
if (!i)
toattr->values[i].string.charset =
- strdup(attr->values[i].string.charset);
+ _cupsStrAlloc(attr->values[i].string.charset);
else
toattr->values[i].string.charset =
toattr->values[0].string.charset;
- toattr->values[i].string.text = strdup(attr->values[i].string.text);
+ toattr->values[i].string.text = _cupsStrAlloc(attr->values[i].string.text);
}
}
break;
if (toattr->values[i].unknown.length > 0)
{
- if ((toattr->values[i].unknown.data = malloc(toattr->values[i].unknown.length)) == NULL)
+ if ((toattr->values[i].unknown.data =
+ malloc(toattr->values[i].unknown.length)) == NULL)
toattr->values[i].unknown.length = 0;
else
memcpy(toattr->values[i].unknown.data,
*/
static void
-copy_attrs(ipp_t *to, /* I - Destination request */
- ipp_t *from, /* I - Source request */
- ipp_attribute_t *req, /* I - Requested attributes */
- ipp_tag_t group, /* I - Group to copy */
- int quickcopy) /* I - Do a quick copy? */
+copy_attrs(ipp_t *to, /* I - Destination request */
+ ipp_t *from, /* I - Source request */
+ cups_array_t *ra, /* I - Requested attributes */
+ ipp_tag_t group, /* I - Group to copy */
+ int quickcopy) /* I - Do a quick copy? */
{
- int i; /* Looping var */
ipp_attribute_t *fromattr; /* Source attribute */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_attrs(%p, %p, %p, %x)", to, from,
- req, group);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "copy_attrs(to=%p, from=%p, ra=%p, group=%x, quickcopy=%d)",
+ to, from, ra, group, quickcopy);
- if (to == NULL || from == NULL)
+ if (!to || !from)
return;
- if (req != NULL && strcmp(req->values[0].string.text, "all") == 0)
- req = NULL; /* "all" means no filter... */
-
- for (fromattr = from->attrs; fromattr != NULL; fromattr = fromattr->next)
+ for (fromattr = from->attrs; fromattr; fromattr = fromattr->next)
{
/*
* Filter attributes as needed...
*/
if (group != IPP_TAG_ZERO && fromattr->group_tag != group &&
- fromattr->group_tag != IPP_TAG_ZERO)
+ fromattr->group_tag != IPP_TAG_ZERO && !fromattr->name)
continue;
- if (req != NULL && fromattr->name != NULL)
- {
- for (i = 0; i < req->num_values; i ++)
- if (strcmp(fromattr->name, req->values[i].string.text) == 0)
- break;
-
- if (i == req->num_values)
- continue;
- }
-
- copy_attribute(to, fromattr, quickcopy);
+ if (!ra || cupsArrayFind(ra, fromattr->name))
+ copy_attribute(to, fromattr, quickcopy);
}
}
* Find the banner; return if not found or "none"...
*/
- if (name == NULL ||
- strcmp(name, "none") == 0 ||
+ if (!name || !strcmp(name, "none") ||
(banner = cupsdFindBanner(name)) == NULL)
return (0);
else
s = attrname;
- if (strcmp(s, "printer-name") == 0)
+ if (!strcmp(s, "printer-name"))
{
cupsFilePuts(out, job->dest);
continue;
{
case IPP_TAG_INTEGER :
case IPP_TAG_ENUM :
- if (strncmp(s, "time-at-", 8) == 0)
+ if (!strncmp(s, "time-at-", 8))
cupsFilePuts(out, cupsdGetDateTime(attr->values[i].integer));
else
cupsFilePrintf(out, "%d", attr->values[i].integer);
case IPP_TAG_TEXT :
case IPP_TAG_NAME :
case IPP_TAG_KEYWORD :
- case IPP_TAG_CHARSET :
- case IPP_TAG_LANGUAGE :
- if (strcasecmp(banner->filetype->type, "postscript") == 0)
- {
- /*
- * Need to quote strings for PS banners...
- */
-
- const char *p;
-
- for (p = attr->values[i].string.text; *p; p ++)
- {
- if (*p == '(' || *p == ')' || *p == '\\')
- {
- cupsFilePutChar(out, '\\');
- cupsFilePutChar(out, *p);
- }
- else if (*p < 32 || *p > 126)
- cupsFilePrintf(out, "\\%03o", *p & 255);
- else
- cupsFilePutChar(out, *p);
- }
- }
- else
- cupsFilePuts(out, attr->values[i].string.text);
- break;
-
- default :
- break; /* anti-compiler-warning-code */
- }
- }
- }
- else if (ch == '\\') /* Quoted char */
- {
- ch = cupsFileGetChar(in);
-
- if (ch != '{') /* Only do special handling for \{ */
- cupsFilePutChar(out, '\\');
-
- cupsFilePutChar(out, ch);
- }
- else
- cupsFilePutChar(out, ch);
-
- cupsFileClose(in);
-
- kbytes = (cupsFileTell(out) + 1023) / 1024;
-
- if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
- attr->values[0].integer += kbytes;
-
- cupsFileClose(out);
-
- return (kbytes);
-}
-
-
-/*
- * 'copy_file()' - Copy a PPD file or interface script...
- */
-
-static int /* O - 0 = success, -1 = error */
-copy_file(const char *from, /* I - Source file */
- const char *to) /* I - Destination file */
-{
- cups_file_t *src, /* Source file */
- *dst; /* Destination file */
- int bytes; /* Bytes to read/write */
- char buffer[2048]; /* Copy buffer */
-
-
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_file(\"%s\", \"%s\")", from, to);
-
- /*
- * Open the source and destination file for a copy...
- */
-
- if ((src = cupsFileOpen(from, "rb")) == NULL)
- return (-1);
-
- if ((dst = cupsFileOpen(to, "wb")) == NULL)
- {
- cupsFileClose(src);
- return (-1);
- }
-
- /*
- * Copy the source file to the destination...
- */
-
- while ((bytes = cupsFileRead(src, buffer, sizeof(buffer))) > 0)
- if (cupsFileWrite(dst, buffer, bytes) < bytes)
- {
- cupsFileClose(src);
- cupsFileClose(dst);
- return (-1);
- }
-
- /*
- * Close both files and return...
- */
-
- cupsFileClose(src);
-
- return (cupsFileClose(dst));
-}
-
-
-/*
- * 'copy_model()' - Copy a PPD model file, substituting default values
- * as needed...
- */
-
-static int /* O - 0 = success, -1 = error */
-copy_model(cupsd_client_t *con, /* I - Client connection */
- const char *from, /* I - Source file */
- const char *to) /* I - Destination file */
-{
- fd_set *input; /* select() input set */
- struct timeval timeout; /* select() timeout */
- int maxfd; /* Maximum file descriptor for select() */
- char tempfile[1024]; /* Temporary PPD file */
- int tempfd; /* Temporary PPD file descriptor */
- int temppid; /* Process ID of cups-driverd */
- int temppipe[2]; /* Temporary pipes */
- char *argv[4], /* Command-line arguments */
- *envp[100]; /* Environment */
- cups_file_t *src, /* Source file */
- *dst; /* Destination file */
- int bytes, /* Bytes from pipe */
- total; /* Total bytes from pipe */
- char buffer[2048], /* Copy buffer */
- *ptr; /* Pointer into buffer */
- int i; /* Looping var */
- char option[PPD_MAX_NAME], /* Option name */
- choice[PPD_MAX_NAME]; /* Choice name */
- int num_defaults; /* Number of default options */
- ppd_default_t *defaults; /* Default options */
- char cups_protocol[PPD_MAX_LINE];
- /* cupsProtocol attribute */
- int have_letter, /* Have Letter size */
- have_a4; /* Have A4 size */
-#ifdef HAVE_LIBPAPER
- char *paper_result; /* Paper size name from libpaper */
- char system_paper[64]; /* Paper size name buffer */
-#endif /* HAVE_LIBPAPER */
-
-
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "copy_model(con=%p, from=\"%s\", to=\"%s\")",
- con, from, to);
-
- /*
- * Run cups-driverd to get the PPD file...
- */
-
- argv[0] = "cups-driverd";
- argv[1] = "cat";
- argv[2] = (char *)from;
- argv[3] = NULL;
-
- 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);
- tempfd = open(tempfile, O_WRONLY | O_CREAT | O_TRUNC, 0600);
- if (tempfd < 0)
- return (-1);
-
- cupsdOpenPipe(temppipe);
-
- if ((input = calloc(1, SetSize)) == NULL)
- {
- close(tempfd);
- unlink(tempfile);
-
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "copy_model: Unable to allocate %d bytes for select()...",
- SetSize);
- return (-1);
- }
-
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "copy_model: Running \"cups-driverd cat %s\"...", from);
-
- if (!cupsdStartProcess(buffer, argv, envp, -1, temppipe[1], CGIPipes[1],
- -1, 0, &temppid))
- {
- close(tempfd);
- unlink(tempfile);
- return (-1);
- }
-
- close(temppipe[1]);
-
- /*
- * Wait up to 30 seconds for the PPD file to be copied...
- */
-
- total = 0;
-
- if (temppipe[0] > CGIPipes[0])
- maxfd = temppipe[0] + 1;
- else
- maxfd = CGIPipes[0] + 1;
-
- for (;;)
- {
- /*
- * See if we have data ready...
- */
-
- bytes = 0;
-
- FD_SET(temppipe[0], input);
- FD_SET(CGIPipes[0], input);
-
- timeout.tv_sec = 30;
- timeout.tv_usec = 0;
-
- if ((i = select(maxfd, input, NULL, NULL, &timeout)) < 0)
- {
- if (errno == EINTR)
- continue;
- else
- break;
- }
- else if (i == 0)
- {
- /*
- * We have timed out...
- */
-
- break;
- }
+ case IPP_TAG_CHARSET :
+ case IPP_TAG_LANGUAGE :
+ if (!strcasecmp(banner->filetype->type, "postscript"))
+ {
+ /*
+ * Need to quote strings for PS banners...
+ */
- if (FD_ISSET(temppipe[0], input))
- {
- /*
- * Read the PPD file from the pipe, and write it to the PPD file.
- */
+ const char *p;
- if ((bytes = read(temppipe[0], buffer, sizeof(buffer))) > 0)
- {
- if (write(tempfd, buffer, bytes) < bytes)
- break;
+ for (p = attr->values[i].string.text; *p; p ++)
+ {
+ if (*p == '(' || *p == ')' || *p == '\\')
+ {
+ cupsFilePutChar(out, '\\');
+ cupsFilePutChar(out, *p);
+ }
+ else if (*p < 32 || *p > 126)
+ cupsFilePrintf(out, "\\%03o", *p & 255);
+ else
+ cupsFilePutChar(out, *p);
+ }
+ }
+ else
+ cupsFilePuts(out, attr->values[i].string.text);
+ break;
- total += bytes;
+ default :
+ break; /* anti-compiler-warning-code */
+ }
}
- else
- break;
}
+ else if (ch == '\\') /* Quoted char */
+ {
+ ch = cupsFileGetChar(in);
- if (FD_ISSET(CGIPipes[0], input))
- cupsdUpdateCGI();
- }
-
- close(temppipe[0]);
- close(tempfd);
-
- if (!total)
- {
- /*
- * No data from cups-deviced...
- */
+ if (ch != '{') /* Only do special handling for \{ */
+ cupsFilePutChar(out, '\\');
- cupsdLogMessage(CUPSD_LOG_ERROR, "copy_model: empty PPD file!");
- unlink(tempfile);
- return (-1);
- }
+ cupsFilePutChar(out, ch);
+ }
+ else
+ cupsFilePutChar(out, ch);
- /*
- * Read the source file and see what page sizes are supported...
- */
+ cupsFileClose(in);
- if ((src = cupsFileOpen(tempfile, "rb")) == NULL)
- {
- unlink(tempfile);
- return (-1);
- }
+ kbytes = (cupsFileTell(out) + 1023) / 1024;
- have_letter = 0;
- have_a4 = 0;
+ if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
+ IPP_TAG_INTEGER)) != NULL)
+ attr->values[0].integer += kbytes;
- while (cupsFileGets(src, buffer, sizeof(buffer)) != NULL)
- if (!strncmp(buffer, "*PageSize ", 10))
- {
- /*
- * Strip UI text and command data from the end of the line...
- */
+ cupsFileClose(out);
- if ((ptr = strchr(buffer + 10, '/')) != NULL)
- *ptr = '\0';
- if ((ptr = strchr(buffer + 10, ':')) != NULL)
- *ptr = '\0';
+ return (kbytes);
+}
- for (ptr = buffer + 10; isspace(*ptr); ptr ++);
- /*
- * Look for Letter and A4 page sizes...
- */
+/*
+ * 'copy_file()' - Copy a PPD file or interface script...
+ */
- if (!strcmp(ptr, "Letter"))
- have_letter = 1;
+static int /* O - 0 = success, -1 = error */
+copy_file(const char *from, /* I - Source file */
+ const char *to) /* I - Destination file */
+{
+ cups_file_t *src, /* Source file */
+ *dst; /* Destination file */
+ int bytes; /* Bytes to read/write */
+ char buffer[2048]; /* Copy buffer */
- if (!strcmp(ptr, "A4"))
- have_a4 = 1;
- }
- cupsFileRewind(src);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_file(\"%s\", \"%s\")", from, to);
/*
- * Open the destination (if possible) and set the default options...
+ * Open the source and destination file for a copy...
*/
- num_defaults = 0;
- defaults = NULL;
- cups_protocol[0] = '\0';
+ if ((src = cupsFileOpen(from, "rb")) == NULL)
+ return (-1);
- if ((dst = cupsFileOpen(to, "rb")) != NULL)
+ if ((dst = cupsFileOpen(to, "wb")) == NULL)
{
- /*
- * Read all of the default lines from the old PPD...
- */
-
- while (cupsFileGets(dst, buffer, sizeof(buffer)) != NULL)
- if (!strncmp(buffer, "*Default", 8))
- {
- /*
- * Add the default option...
- */
-
- if (!ppd_parse_line(buffer, option, sizeof(option),
- choice, sizeof(choice)))
- num_defaults = ppd_add_default(option, choice, num_defaults,
- &defaults);
- }
- else if (!strncmp(buffer, "*cupsProtocol:", 14))
- strlcpy(cups_protocol, buffer, sizeof(cups_protocol));
-
- cupsFileClose(dst);
+ cupsFileClose(src);
+ return (-1);
}
-#ifdef HAVE_LIBPAPER
- else if ((paper_result = systempapername()) != NULL)
- {
- /*
- * Set the default media sizes from the systemwide default...
- */
- strlcpy(system_paper, paper_result, sizeof(system_paper));
- system_paper[0] = toupper(system_paper[0] & 255);
+ /*
+ * Copy the source file to the destination...
+ */
- if ((!strcmp(system_paper, "Letter") && have_letter) ||
- (!strcmp(system_paper, "A4") && have_a4))
+ while ((bytes = cupsFileRead(src, buffer, sizeof(buffer))) > 0)
+ if (cupsFileWrite(dst, buffer, bytes) < bytes)
{
- num_defaults = ppd_add_default("PageSize", system_paper,
- num_defaults, &defaults);
- num_defaults = ppd_add_default("PageRegion", system_paper,
- num_defaults, &defaults);
- num_defaults = ppd_add_default("PaperDimension", system_paper,
- num_defaults, &defaults);
- num_defaults = ppd_add_default("ImageableArea", system_paper,
- num_defaults, &defaults);
+ cupsFileClose(src);
+ cupsFileClose(dst);
+ return (-1);
}
- }
-#endif /* HAVE_LIBPAPER */
- else
- {
- /*
- * Add the default media sizes...
- *
- * Note: These values are generally not valid for large-format devices
- * like plotters, however it is probably safe to say that those
- * users will configure the media size after initially adding
- * the device anyways...
- */
- if (!DefaultLanguage ||
- !strcasecmp(DefaultLanguage, "C") ||
- !strcasecmp(DefaultLanguage, "POSIX") ||
- !strcasecmp(DefaultLanguage, "en") ||
- !strncasecmp(DefaultLanguage, "en_US", 5) ||
- !strncasecmp(DefaultLanguage, "en_CA", 5) ||
- !strncasecmp(DefaultLanguage, "fr_CA", 5))
- {
- /*
- * These are the only locales that will default to "letter" size...
- */
+ /*
+ * Close both files and return...
+ */
- if (have_letter)
- {
- num_defaults = ppd_add_default("PageSize", "Letter", num_defaults,
- &defaults);
- num_defaults = ppd_add_default("PageRegion", "Letter", num_defaults,
- &defaults);
- num_defaults = ppd_add_default("PaperDimension", "Letter", num_defaults,
- &defaults);
- num_defaults = ppd_add_default("ImageableArea", "Letter", num_defaults,
- &defaults);
- }
- }
- else if (have_a4)
- {
- /*
- * The rest default to "a4" size...
- */
+ cupsFileClose(src);
- num_defaults = ppd_add_default("PageSize", "A4", num_defaults,
- &defaults);
- num_defaults = ppd_add_default("PageRegion", "A4", num_defaults,
- &defaults);
- num_defaults = ppd_add_default("PaperDimension", "A4", num_defaults,
- &defaults);
- num_defaults = ppd_add_default("ImageableArea", "A4", num_defaults,
- &defaults);
- }
- }
+ return (cupsFileClose(dst));
+}
+
+
+/*
+ * 'copy_model()' - Copy a PPD model file, substituting default values
+ * as needed...
+ */
+
+static int /* O - 0 = success, -1 = error */
+copy_model(cupsd_client_t *con, /* I - Client connection */
+ const char *from, /* I - Source file */
+ const char *to) /* I - Destination file */
+{
+ fd_set *input; /* select() input set */
+ struct timeval timeout; /* select() timeout */
+ int maxfd; /* Maximum file descriptor for select() */
+ char tempfile[1024]; /* Temporary PPD file */
+ int tempfd; /* Temporary PPD file descriptor */
+ int temppid; /* Process ID of cups-driverd */
+ int temppipe[2]; /* Temporary pipes */
+ char *argv[4], /* Command-line arguments */
+ *envp[MAX_ENV]; /* Environment */
+ cups_file_t *src, /* Source file */
+ *dst; /* Destination file */
+ int bytes, /* Bytes from pipe */
+ total; /* Total bytes from pipe */
+ char buffer[2048], /* Copy buffer */
+ *ptr; /* Pointer into buffer */
+ int i; /* Looping var */
+ char option[PPD_MAX_NAME], /* Option name */
+ choice[PPD_MAX_NAME]; /* Choice name */
+ int num_defaults; /* Number of default options */
+ ppd_default_t *defaults; /* Default options */
+ char cups_protocol[PPD_MAX_LINE];
+ /* cupsProtocol attribute */
+ int have_letter, /* Have Letter size */
+ have_a4; /* Have A4 size */
+#ifdef HAVE_LIBPAPER
+ char *paper_result; /* Paper size name from libpaper */
+ char system_paper[64]; /* Paper size name buffer */
+#endif /* HAVE_LIBPAPER */
+
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "copy_model(con=%p, from=\"%s\", to=\"%s\")",
+ con, from, to);
/*
- * Open the destination file for a copy...
+ * Run cups-driverd to get the PPD file...
*/
- if ((dst = cupsFileOpen(to, "wb")) == NULL)
- {
- if (num_defaults > 0)
- free(defaults);
+ argv[0] = "cups-driverd";
+ argv[1] = "cat";
+ argv[2] = (char *)from;
+ argv[3] = NULL;
- cupsFileClose(src);
- unlink(tempfile);
+ 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);
+ tempfd = open(tempfile, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ if (tempfd < 0)
return (-1);
- }
- /*
- * Copy the source file to the destination...
- */
+ cupsdOpenPipe(temppipe);
- while (cupsFileGets(src, buffer, sizeof(buffer)) != NULL)
+ if ((input = calloc(1, SetSize)) == NULL)
{
- if (!strncmp(buffer, "*Default", 8))
- {
- /*
- * Check for an previous default option choice...
- */
+ close(tempfd);
+ unlink(tempfile);
- if (!ppd_parse_line(buffer, option, sizeof(option),
- choice, sizeof(choice)))
- {
- for (i = 0; i < num_defaults; i ++)
- if (!strcmp(option, defaults[i].option))
- {
- /*
- * Substitute the previous choice...
- */
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "copy_model: Unable to allocate %d bytes for select()...",
+ SetSize);
+ return (-1);
+ }
- snprintf(buffer, sizeof(buffer), "*Default%s: %s", option,
- defaults[i].choice);
- break;
- }
- }
- }
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "copy_model: Running \"cups-driverd cat %s\"...", from);
- cupsFilePrintf(dst, "%s\n", buffer);
+ if (!cupsdStartProcess(buffer, argv, envp, -1, temppipe[1], CGIPipes[1],
+ -1, 0, &temppid))
+ {
+ free(input);
+ close(tempfd);
+ unlink(tempfile);
+ return (-1);
}
- if (cups_protocol[0])
- cupsFilePrintf(dst, "%s\n", cups_protocol);
-
- if (num_defaults > 0)
- free(defaults);
+ close(temppipe[1]);
/*
- * Close both files and return...
+ * Wait up to 30 seconds for the PPD file to be copied...
*/
- cupsFileClose(src);
-
- unlink(tempfile);
-
- return (cupsFileClose(dst));
-}
-
+ total = 0;
-/*
- * 'copy_subscription_attrs()' - Copy subscription attributes.
- */
+ if (temppipe[0] > CGIPipes[0])
+ maxfd = temppipe[0] + 1;
+ else
+ maxfd = CGIPipes[0] + 1;
-static void
-copy_subscription_attrs(
- cupsd_client_t *con, /* I - Client connection */
- cupsd_subscription_t *sub, /* I - Subscription */
- cups_array_t *ra) /* I - Requested attributes array */
-{
- ipp_attribute_t *attr; /* Current attribute */
- char printer_uri[HTTP_MAX_URI];
- /* Printer URI */
- int count; /* Number of events */
- unsigned mask; /* Current event mask */
- const char *name; /* Current event name */
+ for (;;)
+ {
+ /*
+ * See if we have data ready...
+ */
+ bytes = 0;
- /*
- * Copy the subscription attributes to the response using the
- * requested-attributes attribute that may be provided by the client.
- */
+ FD_SET(temppipe[0], input);
+ FD_SET(CGIPipes[0], input);
- if (!ra || cupsArrayFind(ra, "notify-subscription-id"))
- ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
- "notify-subscription-id", sub->id);
+ timeout.tv_sec = 30;
+ timeout.tv_usec = 0;
- if (!ra || cupsArrayFind(ra, "notify-events"))
- {
- if ((name = cupsdEventName((cupsd_eventmask_t)sub->mask)) != NULL)
+ if ((i = select(maxfd, input, NULL, NULL, &timeout)) < 0)
+ {
+ if (errno == EINTR)
+ continue;
+ else
+ break;
+ }
+ else if (i == 0)
{
/*
- * Simple event list...
+ * We have timed out...
*/
- ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
- IPP_TAG_KEYWORD | IPP_TAG_COPY,
- "notify-events", NULL, name);
+ break;
}
- else
+
+ if (FD_ISSET(temppipe[0], input))
{
/*
- * Complex event list...
+ * Read the PPD file from the pipe, and write it to the PPD file.
*/
- for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
- if (sub->mask & mask)
- count ++;
-
- attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
- IPP_TAG_KEYWORD | IPP_TAG_COPY,
- "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);
+ if ((bytes = read(temppipe[0], buffer, sizeof(buffer))) > 0)
+ {
+ if (write(tempfd, buffer, bytes) < bytes)
+ break;
- count ++;
- }
+ total += bytes;
+ }
+ else
+ break;
}
+
+ if (FD_ISSET(CGIPipes[0], input))
+ cupsdUpdateCGI();
}
- if (!ra || cupsArrayFind(ra, "notify-subscriber-user-name"))
- ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_NAME,
- "notify-subscriber-user-name", NULL, sub->owner);
+ close(temppipe[0]);
+ close(tempfd);
- if (sub->recipient && (!ra || cupsArrayFind(ra, "notify-recipient-uri")))
- ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
- "notify-recipient-uri", NULL, sub->recipient);
- else if (!ra || cupsArrayFind(ra, "notify-pull-method"))
- ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
- "notify-pull-method", NULL, "ippget");
+ free(input);
- if (sub->user_data_len > 0 && (!ra || cupsArrayFind(ra, "notify-user-data")))
- ippAddOctetString(con->response, IPP_TAG_SUBSCRIPTION, "notify-user-data",
- sub->user_data, sub->user_data_len);
+ if (!total)
+ {
+ /*
+ * No data from cups-deviced...
+ */
- if (!sub->job && (!ra || cupsArrayFind(ra, "notify-lease-duration")))
- ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
- "notify-lease-duration", sub->lease);
+ cupsdLogMessage(CUPSD_LOG_ERROR, "copy_model: empty PPD file!");
+ unlink(tempfile);
+ return (-1);
+ }
- if (!ra || cupsArrayFind(ra, "notify-time-interval"))
- ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
- "notify-time-interval", sub->interval);
+ /*
+ * Read the source file and see what page sizes are supported...
+ */
- if (sub->dest && (!ra || cupsArrayFind(ra, "notify-printer-uri")))
+ if ((src = cupsFileOpen(tempfile, "rb")) == NULL)
{
- httpAssembleURIf(printer_uri, sizeof(printer_uri), "ipp", NULL,
- con->servername, con->serverport, "/printers/%s",
- sub->dest->name);
- ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
- "notify-printer-uri", NULL, printer_uri);
+ unlink(tempfile);
+ return (-1);
}
- if (sub->job && (!ra || cupsArrayFind(ra, "notify-job-id")))
- ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
- "notify-job-id", sub->job->id);
-}
+ have_letter = 0;
+ have_a4 = 0;
+ while (cupsFileGets(src, buffer, sizeof(buffer)))
+ if (!strncmp(buffer, "*PageSize ", 10))
+ {
+ /*
+ * Strip UI text and command data from the end of the line...
+ */
-/*
- * 'create_job()' - Print a file to a printer or class.
- */
+ if ((ptr = strchr(buffer + 10, '/')) != NULL)
+ *ptr = '\0';
+ if ((ptr = strchr(buffer + 10, ':')) != NULL)
+ *ptr = '\0';
-static void
-create_job(cupsd_client_t *con, /* I - Client connection */
- ipp_attribute_t *uri) /* I - Printer URI */
-{
- http_status_t status; /* Policy status */
- ipp_attribute_t *attr; /* Current attribute */
- const char *dest; /* Destination */
- cups_ptype_t dtype; /* Destination type (printer or class) */
- int priority; /* Job priority */
- char *title; /* Job name/title */
- cupsd_job_t *job; /* Current job */
- char job_uri[HTTP_MAX_URI], /* Job URI */
- method[HTTP_MAX_URI], /* Method portion of URI */
- username[HTTP_MAX_URI], /* Username portion of URI */
- host[HTTP_MAX_URI], /* Host portion of URI */
- resource[HTTP_MAX_URI]; /* Resource portion of URI */
- int port; /* Port portion of URI */
- cupsd_printer_t *printer; /* Printer data */
- int kbytes; /* Size of print file */
- int i; /* Looping var */
- int lowerpagerange; /* Page range bound */
+ for (ptr = buffer + 10; isspace(*ptr); ptr ++);
+
+ /*
+ * Look for Letter and A4 page sizes...
+ */
+
+ if (!strcmp(ptr, "Letter"))
+ have_letter = 1;
+ if (!strcmp(ptr, "A4"))
+ have_a4 = 1;
+ }
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ cupsFileRewind(src);
/*
- * Is the destination valid?
+ * Open the destination (if possible) and set the default options...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ num_defaults = 0;
+ defaults = NULL;
+ cups_protocol[0] = '\0';
- if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+ if ((dst = cupsFileOpen(to, "rb")) != NULL)
{
/*
- * Bad URI...
+ * Read all of the default lines from the old PPD...
*/
- send_ipp_status(con, IPP_NOT_FOUND,
- _("The printer or class was not found."));
- return;
- }
+ while (cupsFileGets(dst, buffer, sizeof(buffer)))
+ if (!strncmp(buffer, "*Default", 8))
+ {
+ /*
+ * Add the default option...
+ */
- /*
- * Check remote printing to non-shared printer...
- */
+ if (!ppd_parse_line(buffer, option, sizeof(option),
+ choice, sizeof(choice)))
+ num_defaults = ppd_add_default(option, choice, num_defaults,
+ &defaults);
+ }
+ else if (!strncmp(buffer, "*cupsProtocol:", 14))
+ strlcpy(cups_protocol, buffer, sizeof(cups_protocol));
- if (!printer->shared &&
- strcasecmp(con->http.hostname, "localhost") &&
- strcasecmp(con->http.hostname, ServerName))
- {
- send_ipp_status(con, IPP_NOT_AUTHORIZED,
- _("The printer or class is not shared!"));
- return;
+ cupsFileClose(dst);
}
+#ifdef HAVE_LIBPAPER
+ else if ((paper_result = systempapername()) != NULL)
+ {
+ /*
+ * Set the default media sizes from the systemwide default...
+ */
- /*
- * Check policy...
- */
+ strlcpy(system_paper, paper_result, sizeof(system_paper));
+ system_paper[0] = toupper(system_paper[0] & 255);
- if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
- {
- send_http_error(con, status);
- return;
+ if ((!strcmp(system_paper, "Letter") && have_letter) ||
+ (!strcmp(system_paper, "A4") && have_a4))
+ {
+ num_defaults = ppd_add_default("PageSize", system_paper,
+ num_defaults, &defaults);
+ num_defaults = ppd_add_default("PageRegion", system_paper,
+ num_defaults, &defaults);
+ num_defaults = ppd_add_default("PaperDimension", system_paper,
+ num_defaults, &defaults);
+ num_defaults = ppd_add_default("ImageableArea", system_paper,
+ num_defaults, &defaults);
+ }
}
- else if ((printer->type & CUPS_PRINTER_AUTHENTICATED) && !con->username[0])
+#endif /* HAVE_LIBPAPER */
+ else
{
- send_http_error(con, HTTP_UNAUTHORIZED);
- return;
+ /*
+ * Add the default media sizes...
+ *
+ * Note: These values are generally not valid for large-format devices
+ * like plotters, however it is probably safe to say that those
+ * users will configure the media size after initially adding
+ * the device anyways...
+ */
+
+ if (!DefaultLanguage ||
+ !strcasecmp(DefaultLanguage, "C") ||
+ !strcasecmp(DefaultLanguage, "POSIX") ||
+ !strcasecmp(DefaultLanguage, "en") ||
+ !strncasecmp(DefaultLanguage, "en_US", 5) ||
+ !strncasecmp(DefaultLanguage, "en_CA", 5) ||
+ !strncasecmp(DefaultLanguage, "fr_CA", 5))
+ {
+ /*
+ * These are the only locales that will default to "letter" size...
+ */
+
+ if (have_letter)
+ {
+ num_defaults = ppd_add_default("PageSize", "Letter", num_defaults,
+ &defaults);
+ num_defaults = ppd_add_default("PageRegion", "Letter", num_defaults,
+ &defaults);
+ num_defaults = ppd_add_default("PaperDimension", "Letter", num_defaults,
+ &defaults);
+ num_defaults = ppd_add_default("ImageableArea", "Letter", num_defaults,
+ &defaults);
+ }
+ }
+ else if (have_a4)
+ {
+ /*
+ * The rest default to "a4" size...
+ */
+
+ num_defaults = ppd_add_default("PageSize", "A4", num_defaults,
+ &defaults);
+ num_defaults = ppd_add_default("PageRegion", "A4", num_defaults,
+ &defaults);
+ num_defaults = ppd_add_default("PaperDimension", "A4", num_defaults,
+ &defaults);
+ num_defaults = ppd_add_default("ImageableArea", "A4", num_defaults,
+ &defaults);
+ }
}
/*
- * See if the printer is accepting jobs...
+ * Open the destination file for a copy...
*/
- if (!printer->accepting)
+ if ((dst = cupsFileOpen(to, "wb")) == NULL)
{
- send_ipp_status(con, IPP_NOT_ACCEPTING,
- _("Destination \"%s\" is not accepting jobs."),
- dest);
- return;
+ if (num_defaults > 0)
+ free(defaults);
+
+ cupsFileClose(src);
+ unlink(tempfile);
+ return (-1);
}
/*
- * Validate job template attributes; for now just copies and page-ranges...
+ * Copy the source file to the destination...
*/
- if ((attr = ippFindAttribute(con->request, "copies", IPP_TAG_INTEGER)) != NULL)
+ while (cupsFileGets(src, buffer, sizeof(buffer)))
{
- if (attr->values[0].integer < 1 || attr->values[0].integer > MaxCopies)
+ if (!strncmp(buffer, "*Default", 8))
{
- send_ipp_status(con, IPP_ATTRIBUTES, _("Bad copies value %d."),
- attr->values[0].integer);
- ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER,
- "copies", attr->values[0].integer);
- return;
- }
- }
+ /*
+ * Check for an previous default option choice...
+ */
- if ((attr = ippFindAttribute(con->request, "page-ranges", IPP_TAG_RANGE)) != NULL)
- {
- for (i = 0, lowerpagerange = 1; i < attr->num_values; i ++)
- {
- if (attr->values[i].range.lower < lowerpagerange ||
- attr->values[i].range.lower > attr->values[i].range.upper)
+ if (!ppd_parse_line(buffer, option, sizeof(option),
+ choice, sizeof(choice)))
{
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("Bad page-ranges values %d-%d."),
- attr->values[i].range.lower,
- attr->values[i].range.upper);
- return;
- }
+ for (i = 0; i < num_defaults; i ++)
+ if (!strcmp(option, defaults[i].option))
+ {
+ /*
+ * Substitute the previous choice...
+ */
- lowerpagerange = attr->values[i].range.upper + 1;
+ snprintf(buffer, sizeof(buffer), "*Default%s: %s", option,
+ defaults[i].choice);
+ break;
+ }
+ }
}
- }
- /*
- * Make sure we aren't over our limit...
- */
-
- if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
- cupsdCleanJobs();
-
- if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("Too many active jobs."));
- return;
+ cupsFilePrintf(dst, "%s\n", buffer);
}
- if (!check_quotas(con, printer))
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached."));
- return;
- }
+ if (cups_protocol[0])
+ cupsFilePrintf(dst, "%s\n", cups_protocol);
+
+ if (num_defaults > 0)
+ free(defaults);
/*
- * Create the job and set things up...
+ * Close both files and return...
*/
- if ((attr = ippFindAttribute(con->request, "job-priority", IPP_TAG_INTEGER)) != NULL)
- priority = attr->values[0].integer;
- else
- ippAddInteger(con->request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-priority",
- priority = 50);
-
- if ((attr = ippFindAttribute(con->request, "job-name", IPP_TAG_NAME)) != NULL)
- title = attr->values[0].string.text;
- else
- ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
- title = "Untitled");
+ cupsFileClose(src);
- if ((job = cupsdAddJob(priority, printer->name)) == NULL)
- {
- send_ipp_status(con, IPP_INTERNAL_ERROR,
- _("Unable to add job for destination \"%s\"!"), dest);
- return;
- }
+ unlink(tempfile);
- job->dtype = dtype;
- job->attrs = con->request;
- con->request = NULL;
+ return (cupsFileClose(dst));
+}
- attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
- if (con->username[0])
- {
- cupsdSetString(&job->username, con->username);
+/*
+ * 'copy_job_attrs()' - Copy job attributes.
+ */
- if (attr)
- cupsdSetString(&attr->values[0].string.text, con->username);
+static void
+copy_job_attrs(cupsd_client_t *con, /* I - Client connection */
+ cupsd_job_t *job, /* I - Job */
+ cups_array_t *ra) /* I - Requested attributes array */
+{
+ char job_uri[HTTP_MAX_URI]; /* Job URI */
- save_auth_info(con, job);
- }
- else if (attr != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "create_job: requesting-user-name = \"%s\"",
- attr->values[0].string.text);
- cupsdSetString(&job->username, attr->values[0].string.text);
- }
- else
- cupsdSetString(&job->username, "anonymous");
+ /*
+ * Send the requested attributes for each job...
+ */
- if (attr == NULL)
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
- "job-originating-user-name", NULL, job->username);
- else
- {
- attr->group_tag = IPP_TAG_JOB;
- cupsdSetString(&attr->name, "job-originating-user-name");
- }
+ httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
+ con->servername, con->serverport, "/jobs/%d",
+ job->id);
- if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
- IPP_TAG_ZERO)) != NULL)
- {
- /*
- * Request contains a job-originating-host-name attribute; validate it...
- */
+ if (!ra || cupsArrayFind(ra, "job-more-info"))
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
+ "job-more-info", NULL, job_uri);
- if (attr->value_tag != IPP_TAG_NAME ||
- attr->num_values != 1 ||
- strcmp(con->http.hostname, "localhost") != 0)
- {
- /*
- * 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.
- */
+ if (job->state_value > IPP_JOB_PROCESSING &&
+ (!ra || cupsArrayFind(ra, "job-preserved")))
+ ippAddBoolean(con->response, IPP_TAG_JOB, "job-preserved",
+ job->num_files > 0);
- 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...
- */
+ if (!ra || cupsArrayFind(ra, "job-printer-up-time"))
+ ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
+ "job-printer-up-time", time(NULL));
- for (i = 0; i < attr->num_values; i ++)
- {
- free(attr->values[i].string.text);
- attr->values[i].string.text = NULL;
- if (attr->values[i].string.charset)
- {
- free(attr->values[i].string.charset);
- attr->values[i].string.charset = NULL;
- }
- }
+ if (!ra || cupsArrayFind(ra, "job-state-reasons"))
+ add_job_state_reasons(con, job);
- default :
- break;
- }
+ if (!ra || cupsArrayFind(ra, "job-uri"))
+ ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
+ "job-uri", NULL, job_uri);
- /*
- * Use the default connection hostname instead...
- */
+ copy_attrs(con->response, job->attrs, ra, IPP_TAG_JOB, 0);
+}
- attr->value_tag = IPP_TAG_NAME;
- attr->num_values = 1;
- attr->values[0].string.text = strdup(con->http.hostname);
- }
- attr->group_tag = IPP_TAG_JOB;
- }
- else
- {
- /*
- * No job-originating-host-name attribute, so use the hostname from
- * the connection...
- */
+/*
+ * 'copy_printer_attrs()' - Copy printer attributes.
+ */
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
- "job-originating-host-name", NULL, con->http.hostname);
- }
+static void
+copy_printer_attrs(
+ cupsd_client_t *con, /* I - Client connection */
+ cupsd_printer_t *printer, /* I - Printer */
+ cups_array_t *ra) /* I - Requested attributes array */
+{
+ char printer_uri[HTTP_MAX_URI];
+ /* Printer URI */
+ time_t curtime; /* Current time */
+ int i; /* Looping var */
+ ipp_attribute_t *history; /* History collection */
- 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;
/*
- * Add remaining job attributes...
+ * Copy the printer attributes to the response using requested-attributes
+ * and document-format attributes that may be provided by the client.
*/
- ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
- job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
- "job-state", IPP_JOB_STOPPED);
- 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);
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
- title);
+ curtime = time(NULL);
- if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
- attr->values[0].integer = 0;
- else
- attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
- "job-k-octets", 0);
+#ifdef __APPLE__
+ if ((!ra || cupsArrayFind(ra, "com.apple.print.recoverable-message")) &&
+ printer->recoverable)
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+ "com.apple.print.recoverable-message", NULL,
+ printer->recoverable);
+#endif /* __APPLE__ */
- if ((attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_KEYWORD)) == NULL)
- attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
- if (attr == NULL)
- attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-hold-until", NULL, "no-hold");
- if (attr != NULL && strcmp(attr->values[0].string.text, "no-hold") != 0 &&
- !(printer->type & CUPS_PRINTER_REMOTE))
+ if (!ra || cupsArrayFind(ra, "printer-current-time"))
+ ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
+ ippTimeToDate(curtime));
+
+ if (!ra || cupsArrayFind(ra, "printer-error-policy"))
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "printer-error-policy", NULL, printer->error_policy);
+
+ if (!ra || cupsArrayFind(ra, "printer-is-accepting-jobs"))
+ ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
+ printer->accepting);
+
+ if (!ra || cupsArrayFind(ra, "printer-is-shared"))
+ ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared",
+ printer->shared);
+
+ if (!ra || cupsArrayFind(ra, "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);
+
+ if (!ra || cupsArrayFind(ra, "printer-state-change-time"))
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "printer-state-change-time", printer->state_time);
+
+ if (MaxPrinterHistory > 0 && printer->num_history > 0 &&
+ cupsArrayFind(ra, "printer-state-history"))
{
/*
- * Hold job until specified time...
+ * Printer history is only sent if specifically requested, so that
+ * older CUPS/IPP clients won't barf on the collection attributes.
*/
- cupsdSetJobHoldUntil(job, attr->values[0].string.text);
+ history = ippAddCollections(con->response, IPP_TAG_PRINTER,
+ "printer-state-history",
+ printer->num_history, NULL);
+
+ for (i = 0; i < printer->num_history; i ++)
+ copy_attrs(history->values[i].collection = ippNew(), printer->history[i],
+ NULL, IPP_TAG_ZERO, 0);
}
- else
- job->hold_until = time(NULL) + 60;
- job->state->values[0].integer = IPP_JOB_HELD;
+ if (!ra || cupsArrayFind(ra, "printer-state-message"))
+ ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+ "printer-state-message", NULL, printer->state_message);
- if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
- Classification)
+ if (!ra || cupsArrayFind(ra, "printer-state-reasons"))
+ add_printer_state_reasons(con, printer);
+
+ if (!ra || cupsArrayFind(ra, "printer-type"))
{
+ int type; /* printer-type value */
+
+
/*
- * Add job sheets options...
+ * Add the CUPS-specific printer-type attribute...
*/
- if ((attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_ZERO)) == NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "Adding default job-sheets values \"%s,%s\"...",
- printer->job_sheets[0], printer->job_sheets[1]);
+ type = printer->type;
- attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets",
- 2, NULL, NULL);
- attr->values[0].string.text = strdup(printer->job_sheets[0]);
- attr->values[1].string.text = strdup(printer->job_sheets[1]);
- }
+ if (printer == DefaultPrinter)
+ type |= CUPS_PRINTER_DEFAULT;
- job->job_sheets = attr;
+ if (!printer->accepting)
+ type |= CUPS_PRINTER_REJECTING;
- /*
- * Enforce classification level if set...
- */
+ if (!printer->shared)
+ type |= CUPS_PRINTER_NOT_SHARED;
- if (Classification)
- {
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Classification=\"%s\", ClassifyOverride=%d",
- Classification ? Classification : "(null)",
- ClassifyOverride);
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-type",
+ type);
+ }
- if (ClassifyOverride)
- {
- if (!strcmp(attr->values[0].string.text, "none") &&
- (attr->num_values == 1 ||
- !strcmp(attr->values[1].string.text, "none")))
- {
- /*
- * Force the leading banner to have the classification on it...
- */
+ if (!ra || cupsArrayFind(ra, "printer-up-time"))
+ ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "printer-up-time", curtime);
- cupsdSetString(&attr->values[0].string.text, Classification);
+ if ((!ra || cupsArrayFind(ra, "printer-uri-supported")) &&
+ !ippFindAttribute(printer->attrs, "printer-uri-supported",
+ IPP_TAG_URI))
+ {
+ httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
+ "ipp", NULL, con->servername, con->serverport,
+ "/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);
+ }
- cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
- "job-sheets=\"%s,none\", "
- "job-originating-user-name=\"%s\"",
- job->id, Classification, job->username);
- }
- else if (attr->num_values == 2 &&
- strcmp(attr->values[0].string.text, attr->values[1].string.text) != 0 &&
- strcmp(attr->values[0].string.text, "none") != 0 &&
- strcmp(attr->values[1].string.text, "none") != 0)
- {
- /*
- * Can't put two different security markings on the same document!
- */
+ if (!ra || cupsArrayFind(ra, "queued-job-count"))
+ add_queued_job_count(con, printer);
- cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text);
+ copy_attrs(con->response, printer->attrs, ra, IPP_TAG_ZERO, 0);
+ copy_attrs(con->response, CommonData, ra, IPP_TAG_ZERO, IPP_TAG_COPY);
+}
- cupsdLogMessage(CUPSD_LOG_NOTICE, "[Job %d] CLASSIFICATION FORCED "
- "job-sheets=\"%s,%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, attr->values[0].string.text,
- attr->values[1].string.text, job->username);
- }
- else if (strcmp(attr->values[0].string.text, Classification) &&
- strcmp(attr->values[0].string.text, "none") &&
- (attr->num_values == 1 ||
- (strcmp(attr->values[1].string.text, Classification) &&
- strcmp(attr->values[1].string.text, "none"))))
- {
- if (attr->num_values == 1)
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION OVERRIDDEN "
- "job-sheets=\"%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, attr->values[0].string.text, job->username);
- else
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION OVERRIDDEN "
- "job-sheets=\"%s,%s\",fffff "
- "job-originating-user-name=\"%s\"",
- job->id, attr->values[0].string.text,
- attr->values[1].string.text, job->username);
- }
- }
- else if (strcmp(attr->values[0].string.text, Classification) != 0 &&
- (attr->num_values == 1 ||
- strcmp(attr->values[1].string.text, Classification) != 0))
- {
- /*
- * Force the banner to have the classification on it...
- */
- 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);
- }
- else
- {
- if (attr->num_values == 1 ||
- strcmp(attr->values[0].string.text, "none"))
- cupsdSetString(&(attr->values[0].string.text), Classification);
+/*
+ * 'copy_subscription_attrs()' - Copy subscription attributes.
+ */
- if (attr->num_values > 1 &&
- strcmp(attr->values[1].string.text, "none"))
- cupsdSetString(&(attr->values[1].string.text), Classification);
- }
+static void
+copy_subscription_attrs(
+ cupsd_client_t *con, /* I - Client connection */
+ cupsd_subscription_t *sub, /* I - Subscription */
+ cups_array_t *ra) /* I - Requested attributes array */
+{
+ ipp_attribute_t *attr; /* Current attribute */
+ char printer_uri[HTTP_MAX_URI];
+ /* Printer URI */
+ int count; /* Number of events */
+ unsigned mask; /* Current event mask */
+ const char *name; /* Current event name */
- if (attr->num_values > 1)
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION FORCED "
- "job-sheets=\"%s,%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, attr->values[0].string.text,
- attr->values[1].string.text, job->username);
- else
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION FORCED "
- "job-sheets=\"%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, Classification, job->username);
- }
- }
- /*
- * See if we need to add the starting sheet...
- */
+ /*
+ * Copy the subscription attributes to the response using the
+ * requested-attributes attribute that may be provided by the client.
+ */
+
+ if (!ra || cupsArrayFind(ra, "notify-events"))
+ {
+ if ((name = cupsdEventName((cupsd_eventmask_t)sub->mask)) != NULL)
+ {
+ /*
+ * Simple event list...
+ */
- if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
+ ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
+ IPP_TAG_KEYWORD | IPP_TAG_COPY,
+ "notify-events", NULL, name);
+ }
+ else
{
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Adding start banner page \"%s\" to job %d.",
- attr->values[0].string.text, job->id);
+ /*
+ * Complex event list...
+ */
- kbytes = copy_banner(con, job, attr->values[0].string.text);
+ for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
+ if (sub->mask & mask)
+ count ++;
- cupsdUpdateQuota(printer, job->username, 0, kbytes);
+ attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
+ IPP_TAG_KEYWORD | IPP_TAG_COPY,
+ "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);
+
+ count ++;
+ }
}
}
- else if ((attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_ZERO)) != NULL)
- job->sheets = attr;
- /*
- * Fill in the response info...
- */
+ if (sub->job && (!ra || cupsArrayFind(ra, "notify-job-id")))
+ ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+ "notify-job-id", sub->job->id);
- snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
- LocalPort, job->id);
+ if (!sub->job && (!ra || cupsArrayFind(ra, "notify-lease-duration")))
+ ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+ "notify-lease-duration", sub->lease);
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL, job_uri);
+ if (sub->dest && (!ra || cupsArrayFind(ra, "notify-printer-uri")))
+ {
+ httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
+ "ipp", NULL, con->servername, con->serverport,
+ "/printers/%s", sub->dest->name);
+ ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
+ "notify-printer-uri", NULL, printer_uri);
+ }
- ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
+ if (sub->recipient && (!ra || cupsArrayFind(ra, "notify-recipient-uri")))
+ ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
+ "notify-recipient-uri", NULL, sub->recipient);
+ else if (!ra || cupsArrayFind(ra, "notify-pull-method"))
+ ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
+ "notify-pull-method", NULL, "ippget");
- ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
- job->state->values[0].integer);
+ if (!ra || cupsArrayFind(ra, "notify-subscriber-user-name"))
+ ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_NAME,
+ "notify-subscriber-user-name", NULL, sub->owner);
- con->response->request.status.status_code = IPP_OK;
+ if (!ra || cupsArrayFind(ra, "notify-subscription-id"))
+ ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+ "notify-subscription-id", sub->id);
- /*
- * Add any job subscriptions...
- */
+ if (!ra || cupsArrayFind(ra, "notify-time-interval"))
+ ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+ "notify-time-interval", sub->interval);
- add_job_subscriptions(con, job);
+ if (sub->user_data_len > 0 && (!ra || cupsArrayFind(ra, "notify-user-data")))
+ ippAddOctetString(con->response, IPP_TAG_SUBSCRIPTION, "notify-user-data",
+ sub->user_data, sub->user_data_len);
+}
+
+
+/*
+ * 'create_job()' - Print a file to a printer or class.
+ */
+
+static void
+create_job(cupsd_client_t *con, /* I - Client connection */
+ ipp_attribute_t *uri) /* I - Printer URI */
+{
+ cupsd_job_t *job; /* New job */
+
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "create_job(%p[%d], %s)", con,
+ con->http.fd, uri->values[0].string.text);
/*
- * Set all but the first two attributes to the job attributes group...
+ * Create the job object...
*/
- for (attr = job->attrs->attrs->next->next; attr; attr = attr->next)
- attr->group_tag = IPP_TAG_JOB;
+ if ((job = add_job(con, uri, NULL)) == NULL)
+ return;
/*
* Save and log the job...
cupsdLogMessage(CUPSD_LOG_INFO, "Job %d created on \"%s\" by \"%s\".",
job->id, job->dest, job->username);
-
- cupsdAddEvent(CUPSD_EVENT_JOB_CREATED, printer, job, "Job created.");
}
unsigned mask; /* notify-events */
+#ifdef DEBUG
+ for (attr = con->request->attrs; attr; attr = attr->next)
+ {
+ if (attr->group_tag != IPP_TAG_ZERO)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "g%04x v%04x %s", attr->group_tag,
+ attr->value_tag, attr->name);
+ else
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "----SEP----");
+ }
+#endif /* DEBUG */
+
/*
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- userpass, sizeof(userpass), host, sizeof(host), &port,
- resource, sizeof(resource));
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "cupsdCreateSubscription(con=%p(%d), uri=\"%s\")",
+ con, con->http.fd, uri->values[0].string.text);
+
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), userpass, sizeof(userpass), host,
+ sizeof(host), &port, resource, sizeof(resource));
if (!strcmp(resource, "/"))
{
* Get the user that is requesting the subscription...
*/
- if (con->username[0])
- username = con->username;
- else if ((attr = ippFindAttribute(con->request, "requesting-user-name",
- IPP_TAG_NAME)) != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "create_subscription: requesting-user-name = \"%s\"",
- attr->values[0].string.text);
-
- username = attr->values[0].string.text;
- }
- else
- username = "anonymous";
+ username = get_username(con);
/*
* Find the first subscription group attribute; return if we have
* Process the subscription attributes in the request...
*/
+ con->response->request.status.status_code = IPP_BAD_REQUEST;
+
while (attr)
{
recipient = NULL;
attr = attr->next;
}
+ if (recipient)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "recipient=\"%s\"", recipient);
+ if (pullmethod)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "pullmethod=\"%s\"", pullmethod);
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "notify-lease-duration=%d", lease);
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "notify-time-interval=%d", interval);
+
if (!recipient && !pullmethod)
break;
}
}
- if (MaxLeaseDuration && lease > MaxLeaseDuration)
+ if (MaxLeaseDuration && (lease == 0 || lease > MaxLeaseDuration))
{
cupsdLogMessage(CUPSD_LOG_INFO,
"create_subscription: Limiting notify-lease-duration to "
sub = cupsdAddSubscription(mask, printer, job, recipient, 0);
+ if (job)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Added subscription %d for job %d",
+ sub->id, job->id);
+ else if (printer)
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Added subscription %d for printer \"%s\"",
+ sub->id, printer->name);
+ else
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Added subscription %d for server",
+ sub->id);
+
sub->interval = interval;
sub->lease = lease;
- sub->expire = time(NULL) + lease;
+ sub->expire = lease ? time(NULL) + lease : 0;
cupsdSetString(&sub->owner, username);
ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
"notify-subscription-id", sub->id);
+ con->response->request.status.status_code = IPP_OK;
+
if (attr)
attr = attr->next;
}
cupsdSaveAllSubscriptions();
- con->response->request.status.status_code = IPP_OK;
}
* Do we have a valid URI?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
cupsdAddEvent(CUPSD_EVENT_PRINTER_DELETED, printer, NULL,
"%s \"%s\" deleted by \"%s\".",
(dtype & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
- dest, con->username);
+ dest, get_username(con));
cupsdExpireSubscriptions(printer, NULL);
if (dtype & CUPS_PRINTER_CLASS)
{
cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" deleted by \"%s\".", dest,
- con->username);
+ get_username(con));
cupsdDeletePrinter(printer, 0);
cupsdSaveAllClasses();
else
{
cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" deleted by \"%s\".", dest,
- con->username);
+ get_username(con));
cupsdDeletePrinter(printer, 0);
cupsdSaveAllPrinters();
static void
get_default(cupsd_client_t *con) /* I - Client connection */
{
- http_status_t status; /* Policy status */
- int i; /* Looping var */
- ipp_attribute_t *requested, /* requested-attributes */
- *history; /* History collection */
- int need_history; /* Need to send history collection? */
- char printer_uri[HTTP_MAX_URI];
- /* Printer URI */
- time_t curtime; /* Current time */
+ http_status_t status; /* Policy status */
+ cups_array_t *ra; /* Requested attributes array */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_default(%p[%d])", con, con->http.fd);
return;
}
- if (DefaultPrinter != NULL)
+ if (DefaultPrinter)
{
- /*
- * Copy the printer attributes to the response using requested-attributes
- * and document-format attributes that may be provided by the client.
- */
-
- if (!ippFindAttribute(DefaultPrinter->attrs, "printer-uri-supported",
- IPP_TAG_URI))
- {
- httpAssembleURIf(printer_uri, sizeof(printer_uri), "ipp", NULL,
- con->servername, con->serverport, "/printers/%s",
- DefaultPrinter->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);
- }
-
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
- DefaultPrinter->state);
-
- add_printer_state_reasons(con, DefaultPrinter);
-
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-state-message", NULL, DefaultPrinter->state_message);
-
- ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
- DefaultPrinter->accepting);
- ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared",
- DefaultPrinter->shared);
-
- curtime = time(NULL);
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-up-time", curtime);
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-state-change-time", DefaultPrinter->state_time);
- ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
- ippTimeToDate(curtime));
-
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-error-policy", NULL, DefaultPrinter->error_policy);
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-op-policy", NULL, DefaultPrinter->op_policy);
-
- add_queued_job_count(con, DefaultPrinter);
+ ra = create_requested_array(con->request);
- requested = ippFindAttribute(con->request, "requested-attributes",
- IPP_TAG_KEYWORD);
+ copy_printer_attrs(con, DefaultPrinter, ra);
- copy_attrs(con->response, DefaultPrinter->attrs, requested, IPP_TAG_ZERO, 0);
- copy_attrs(con->response, CommonData, requested, IPP_TAG_ZERO, IPP_TAG_COPY);
+ cupsArrayDelete(ra);
- need_history = 0;
-
- if (MaxPrinterHistory > 0 && DefaultPrinter->num_history > 0 && requested)
- {
- for (i = 0; i < requested->num_values; i ++)
- if (!strcmp(requested->values[i].string.text, "all") ||
- !strcmp(requested->values[i].string.text, "printer-state-history"))
- {
- need_history = 1;
- break;
- }
- }
-
- if (need_history)
- {
- history = ippAddCollections(con->response, IPP_TAG_PRINTER,
- "printer-state-history",
- DefaultPrinter->num_history, NULL);
-
- for (i = 0; i < DefaultPrinter->num_history; i ++)
- copy_attrs(history->values[i].collection = ippNew(),
- DefaultPrinter->history[i],
- NULL, IPP_TAG_ZERO, 0);
- }
-
- con->response->request.status.status_code = requested ? IPP_OK_SUBST : IPP_OK;
+ con->response->request.status.status_code = IPP_OK;
}
else
send_ipp_status(con, IPP_NOT_FOUND, _("No default printer"));
if (alen > (sizeof(attrs) - (aptr - attrs) - 2))
break;
- /*
- * Put commas between values...
- */
+ /*
+ * Put commas between values...
+ */
+
+ if (i)
+ *aptr++ = ',';
+
+ /*
+ * Add the value to the end of the string...
+ */
+
+ strcpy(aptr, requested->values[i].string.text);
+ aptr += alen;
+ }
+
+ /*
+ * If we have more attribute names than will fit, default to "all"...
+ */
+
+ if (i < requested->num_values)
+ strcpy(attrs, "all");
+ }
+ else
+ strcpy(attrs, "all");
+
+ snprintf(command, sizeof(command), "%s/daemon/cups-deviced", ServerBin);
+ snprintf(options, sizeof(options),
+ "%d+%d+%d+requested-attributes=%s",
+ con->request->request.op.request_id,
+ limit ? limit->values[0].integer : 0, User,
+ attrs);
+
+ if (cupsdSendCommand(con, command, options, 1))
+ {
+ /*
+ * Command started successfully, don't send an IPP response here...
+ */
+
+ ippDelete(con->response);
+ con->response = NULL;
+ }
+ else
+ {
+ /*
+ * Command failed, return "internal error" so the user knows something
+ * went wrong...
+ */
+
+ send_ipp_status(con, IPP_INTERNAL_ERROR,
+ _("cups-deviced failed to execute."));
+ }
+}
+
+
+/*
+ * 'get_job_attrs()' - Get job attributes.
+ */
+
+static void
+get_job_attrs(cupsd_client_t *con, /* I - Client connection */
+ ipp_attribute_t *uri) /* I - Job URI */
+{
+ http_status_t status; /* Policy status */
+ ipp_attribute_t *attr; /* Current attribute */
+ int jobid; /* Job ID */
+ cupsd_job_t *job; /* Current job */
+ char method[HTTP_MAX_URI], /* Method portion of URI */
+ username[HTTP_MAX_URI], /* Username portion of URI */
+ host[HTTP_MAX_URI], /* Host portion of URI */
+ resource[HTTP_MAX_URI]; /* Resource portion of URI */
+ int port; /* Port portion of URI */
+ cups_array_t *ra; /* Requested attributes array */
+
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_job_attrs(%p[%d], %s)", con,
+ con->http.fd, uri->values[0].string.text);
+
+ /*
+ * See if we have a job URI or a printer URI...
+ */
+
+ if (!strcmp(uri->name, "printer-uri"))
+ {
+ /*
+ * Got a printer URI; see if we also have a job-id attribute...
+ */
+
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
+ {
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("Got a printer-uri attribute but no job-id!"));
+ return;
+ }
- if (i)
- *aptr++ = ',';
+ jobid = attr->values[0].integer;
+ }
+ else
+ {
+ /*
+ * Got a job URI; parse it to get the job ID...
+ */
+
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
+ if (strncmp(resource, "/jobs/", 6))
+ {
/*
- * Add the value to the end of the string...
+ * Not a valid URI!
*/
- strcpy(aptr, requested->values[i].string.text);
- aptr += alen;
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("Bad job-uri attribute \"%s\"!"),
+ uri->values[0].string.text);
+ return;
}
- /*
- * If we have more attribute names than will fit, default to "all"...
- */
-
- if (i < requested->num_values)
- strcpy(attrs, "all");
+ jobid = atoi(resource + 6);
}
- else
- strcpy(attrs, "all");
- snprintf(command, sizeof(command), "%s/daemon/cups-deviced", ServerBin);
- snprintf(options, sizeof(options),
- "cups-deviced %d+%d+requested-attributes=%s",
- con->request->request.op.request_id,
- limit ? limit->values[0].integer : 0,
- attrs);
+ /*
+ * See if the job exists...
+ */
- if (cupsdSendCommand(con, command, options, 1))
+ if ((job = cupsdFindJob(jobid)) == NULL)
{
/*
- * Command started successfully, don't send an IPP response here...
+ * Nope - return a "not found" error...
*/
- ippDelete(con->response);
- con->response = NULL;
+ send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
+ return;
}
- else
- {
- /*
- * Command failed, return "internal error" so the user knows something
- * went wrong...
- */
- send_ipp_status(con, IPP_INTERNAL_ERROR,
- _("cups-deviced failed to execute."));
+ /*
+ * Check policy...
+ */
+
+ if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+ {
+ send_http_error(con, status);
+ return;
}
+
+ /*
+ * Copy attributes...
+ */
+
+ cupsdLoadJob(job);
+
+ ra = create_requested_array(con->request);
+ copy_job_attrs(con, job, ra);
+ cupsArrayDelete(ra);
+
+ con->response->request.status.status_code = IPP_OK;
}
ipp_attribute_t *uri) /* I - Printer URI */
{
http_status_t status; /* Policy status */
- ipp_attribute_t *attr, /* Current attribute */
- *requested; /* Requested attributes */
+ ipp_attribute_t *attr; /* Current attribute */
const char *dest; /* Destination */
cups_ptype_t dtype; /* Destination type (printer or class) */
cups_ptype_t dmask; /* Destination type mask */
int limit; /* Maximum number of jobs to return */
int count; /* Number of jobs that match */
cupsd_job_t *job; /* Current job pointer */
- char job_uri[HTTP_MAX_URI]; /* Job URI... */
cupsd_printer_t *printer; /* Printer */
cups_array_t *list; /* Which job list... */
+ cups_array_t *ra; /* Requested attributes array */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs(%p[%d], %s)", con, con->http.fd,
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
- if (strcmp(resource, "/") == 0 ||
- (strncmp(resource, "/jobs", 5) == 0 && strlen(resource) <= 6))
+ if (!strcmp(resource, "/") ||
+ (!strncmp(resource, "/jobs", 5) && strlen(resource) <= 6))
{
dest = NULL;
dtype = (cups_ptype_t)0;
dmask = (cups_ptype_t)0;
printer = NULL;
}
- else if (strncmp(resource, "/printers", 9) == 0 && strlen(resource) <= 10)
+ else if (!strncmp(resource, "/printers", 9) && strlen(resource) <= 10)
{
dest = NULL;
dtype = (cups_ptype_t)0;
dmask = CUPS_PRINTER_CLASS;
printer = NULL;
}
- else if (strncmp(resource, "/classes", 8) == 0 && strlen(resource) <= 9)
+ else if (!strncmp(resource, "/classes", 8) && strlen(resource) <= 9)
{
dest = NULL;
dtype = CUPS_PRINTER_CLASS;
* See if the "which-jobs" attribute have been specified...
*/
- if ((attr = ippFindAttribute(con->request, "which-jobs", IPP_TAG_KEYWORD)) != NULL &&
+ if ((attr = ippFindAttribute(con->request, "which-jobs",
+ IPP_TAG_KEYWORD)) != NULL &&
!strcmp(attr->values[0].string.text, "completed"))
{
completed = 1;
* 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)
limit = attr->values[0].integer;
else
limit = 1000000;
* See if we only want to see jobs for a specific user...
*/
- if ((attr = ippFindAttribute(con->request, "my-jobs", IPP_TAG_BOOLEAN)) != NULL &&
+ if ((attr = ippFindAttribute(con->request, "my-jobs",
+ IPP_TAG_BOOLEAN)) != NULL &&
attr->values[0].boolean)
- {
- if (con->username[0])
- strlcpy(username, con->username, sizeof(username));
- else if ((attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME)) != NULL)
- strlcpy(username, attr->values[0].string.text, sizeof(username));
- else
- strcpy(username, "anonymous");
- }
+ strlcpy(username, get_username(con), sizeof(username));
else
username[0] = '\0';
- requested = ippFindAttribute(con->request, "requested-attributes",
- IPP_TAG_KEYWORD);
+ ra = create_requested_array(con->request);
/*
* OK, build a list of jobs for this printer...
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: job->id = %d", job->id);
- if ((dest != NULL && strcmp(job->dest, dest) != 0) &&
- (job->printer == NULL || dest == NULL ||
- strcmp(job->printer->name, dest) != 0))
+ if ((dest && strcmp(job->dest, dest)) &&
+ (!job->printer || !dest || strcmp(job->printer->name, dest)))
continue;
if ((job->dtype & dmask) != dtype &&
- (job->printer == NULL || (job->printer->type & dmask) != dtype))
+ (!job->printer || (job->printer->type & dmask) != dtype))
continue;
- if (username[0] != '\0' && strcasecmp(username, job->username) != 0)
+ if (username[0] && strcasecmp(username, job->username))
continue;
- if (completed && job->state->values[0].integer <= IPP_JOB_STOPPED)
+ if (completed && job->state_value <= IPP_JOB_STOPPED)
continue;
if (job->id < first_job_id)
continue;
- count ++;
-
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: count = %d", count);
-
- /*
- * Send the requested attributes for each job...
- */
-
- snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
- LocalPort, job->id);
+ cupsdLoadJob(job);
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
- "job-more-info", NULL, job_uri);
-
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
- "job-uri", NULL, job_uri);
-
- ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
- "job-printer-up-time", time(NULL));
+ if (!job->attrs)
+ continue;
- /*
- * Copy the job attributes to the response using the requested-attributes
- * attribute that may be provided by the client.
- */
+ if (count > 0)
+ ippAddSeparator(con->response);
- copy_attrs(con->response, job->attrs, requested, IPP_TAG_JOB, 0);
+ count ++;
- add_job_state_reasons(con, job);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_jobs: count = %d", count);
- ippAddSeparator(con->response);
+ copy_job_attrs(con, job, ra);
}
- if (requested != NULL)
- con->response->request.status.status_code = IPP_OK_SUBST;
- else
- con->response->request.status.status_code = IPP_OK;
+ cupsArrayDelete(ra);
+
+ con->response->request.status.status_code = IPP_OK;
}
/*
- * 'get_job_attrs()' - Get job attributes.
+ * 'get_notifications()' - Get events for a subscription.
*/
static void
-get_job_attrs(cupsd_client_t *con, /* I - Client connection */
- ipp_attribute_t *uri) /* I - Job URI */
+get_notifications(cupsd_client_t *con) /* I - Client connection */
{
- http_status_t status; /* Policy status */
- ipp_attribute_t *attr, /* Current attribute */
- *requested; /* Requested attributes */
- int jobid; /* Job ID */
- cupsd_job_t *job; /* Current job */
- char method[HTTP_MAX_URI], /* Method portion of URI */
- username[HTTP_MAX_URI], /* Username portion of URI */
- host[HTTP_MAX_URI], /* Host portion of URI */
- resource[HTTP_MAX_URI]; /* Resource portion of URI */
- int port; /* Port portion of URI */
- char job_uri[HTTP_MAX_URI]; /* Job URI... */
+ int i, j; /* Looping vars */
+ http_status_t status; /* Policy status */
+ cupsd_subscription_t *sub; /* Subscription */
+ ipp_attribute_t *ids, /* notify-subscription-ids */
+ *sequences; /* notify-sequence-numbers */
+ int min_seq; /* Minimum sequence number */
+ int interval; /* Poll interval */
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_job_attrs(%p[%d], %s)", con,
- con->http.fd, uri->values[0].string.text);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_subscription_attrs(con=%p[%d])",
+ con, con->http.fd);
/*
- * See if we have a job URI or a printer URI...
+ * Get subscription attributes...
*/
- if (strcmp(uri->name, "printer-uri") == 0)
- {
- /*
- * Got a printer URI; see if we also have a job-id attribute...
- */
-
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
- {
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("Got a printer-uri attribute but no job-id!"));
- return;
- }
+ ids = ippFindAttribute(con->request, "notify-subscription-ids",
+ IPP_TAG_INTEGER);
+ sequences = ippFindAttribute(con->request, "notify-sequence-numbers",
+ IPP_TAG_INTEGER);
- jobid = attr->values[0].integer;
- }
- else
+ if (!ids)
{
- /*
- * Got a job URI; parse it to get the job ID...
- */
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("Missing notify-subscription-ids attribute!"));
+ return;
+ }
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ /*
+ * Are the subscription IDs valid?
+ */
- if (strncmp(resource, "/jobs/", 6) != 0)
+ for (i = 0, interval = 60; i < ids->num_values; i ++)
+ {
+ if ((sub = cupsdFindSubscription(ids->values[i].integer)) == NULL)
{
/*
- * Not a valid URI!
+ * Bad subscription ID...
*/
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("Bad job-uri attribute \"%s\"!"),
- uri->values[0].string.text);
+ send_ipp_status(con, IPP_NOT_FOUND,
+ _("notify-subscription-id %d no good!"),
+ ids->values[i].integer);
return;
}
- jobid = atoi(resource + 6);
- }
+ /*
+ * Check policy...
+ */
- /*
- * See if the job exists...
- */
+ if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr :
+ DefaultPolicyPtr,
+ con, sub->owner)) != HTTP_OK)
+ {
+ send_http_error(con, status);
+ return;
+ }
- if ((job = cupsdFindJob(jobid)) == NULL)
- {
/*
- * Nope - return a "not found" error...
+ * Check the subscription type and update the interval accordingly.
*/
- send_ipp_status(con, IPP_NOT_FOUND, _("Job #%d does not exist!"), jobid);
- return;
+ if (sub->job && sub->job->state_value == IPP_JOB_PROCESSING &&
+ interval > 10)
+ interval = 10;
+ else if (sub->job && sub->job->state_value >= IPP_JOB_STOPPED)
+ interval = 0;
+ else if (sub->dest && sub->dest->state == IPP_PRINTER_PROCESSING &&
+ interval > 30)
+ interval = 30;
}
/*
- * Check policy...
+ * Tell the client to poll again in N seconds...
*/
- if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
- {
- send_http_error(con, status);
- return;
- }
+ if (interval > 0)
+ ippAddInteger(con->response, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
+ "notify-get-interval", interval);
+
+ ippAddInteger(con->response, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
+ "printer-up-time", time(NULL));
/*
- * Put out the standard attributes...
+ * Copy the subscription event attributes to the response.
*/
- snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d",
- ServerName, LocalPort, job->id);
-
- ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
-
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
- "job-more-info", NULL, job_uri);
+ con->response->request.status.status_code =
+ interval ? IPP_OK : IPP_OK_EVENTS_COMPLETE;
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI,
- "job-uri", NULL, job_uri);
-
- ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER,
- "job-printer-up-time", time(NULL));
+ for (i = 0; i < ids->num_values; i ++)
+ {
+ /*
+ * Get the subscription and sequence number...
+ */
- /*
- * Copy the job attributes to the response using the requested-attributes
- * attribute that may be provided by the client.
- */
+ sub = cupsdFindSubscription(ids->values[i].integer);
- requested = ippFindAttribute(con->request, "requested-attributes",
- IPP_TAG_KEYWORD);
+ if (sequences && i < sequences->num_values)
+ min_seq = sequences->values[i].integer;
+ else
+ min_seq = 1;
- copy_attrs(con->response, job->attrs, requested, IPP_TAG_JOB, 0);
+ /*
+ * If we don't have any new events, nothing to do here...
+ */
- add_job_state_reasons(con, job);
+ if (min_seq > (sub->first_event_id + sub->num_events))
+ continue;
- if (requested != NULL)
- con->response->request.status.status_code = IPP_OK_SUBST;
- else
- con->response->request.status.status_code = IPP_OK;
-}
+ /*
+ * Otherwise copy all of the new events...
+ */
+ if (sub->first_event_id > min_seq)
+ j = 0;
+ else
+ j = min_seq - sub->first_event_id;
-/*
- * 'get_notifications()' - Get events for a subscription.
- */
+ for (; j < sub->num_events; j ++)
+ {
+ ippAddSeparator(con->response);
-static void
-get_notifications(cupsd_client_t *con, /* I - Client connection */
- int id) /* I - Subscription ID */
-{
+ copy_attrs(con->response, sub->events[j]->attrs, NULL,
+ IPP_TAG_EVENT_NOTIFICATION, 0);
+ }
+ }
}
snprintf(command, sizeof(command), "%s/daemon/cups-driverd", ServerBin);
snprintf(options, sizeof(options),
- "cups-driverd list+%d+%d+requested-attributes=%s%s%s",
+ "list+%d+%d+requested-attributes=%s%s%s",
con->request->request.op.request_id,
limit ? limit->values[0].integer : 0,
attrs,
/* Resource portion of URI */
int port; /* Port portion of URI */
cupsd_printer_t *printer; /* Printer/class */
- char printer_uri[HTTP_MAX_URI];
- /* Printer URI */
- time_t curtime; /* Current time */
- int i; /* Looping var */
- ipp_attribute_t *requested, /* requested-attributes */
- *history; /* History collection */
- int need_history; /* Need to send history collection? */
+ cups_array_t *ra; /* Requested attributes array */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printer_attrs(%p[%d], %s)", con,
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
send_ipp_status(con, IPP_NOT_FOUND,
_("The printer or class was not found."));
return;
- }
-
- /*
- * Check policy...
- */
-
- if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
- {
- send_http_error(con, status);
- return;
- }
-
- curtime = time(NULL);
-
- /*
- * Copy the printer attributes to the response using requested-attributes
- * and document-format attributes that may be provided by the client.
- */
-
- if (!ippFindAttribute(printer->attrs, "printer-uri-supported",
- IPP_TAG_URI))
- {
- httpAssembleURIf(printer_uri, sizeof(printer_uri), "ipp", NULL,
- con->servername, con->serverport, "/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);
- }
-
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
- printer->state);
-
- add_printer_state_reasons(con, printer);
-
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-state-message", NULL, printer->state_message);
-
- ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
- printer->accepting);
- ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared",
- printer->shared);
-
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-up-time", curtime);
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-state-change-time", printer->state_time);
- ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
- ippTimeToDate(curtime));
-
- 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-op-policy", NULL, printer->op_policy);
-
- add_queued_job_count(con, printer);
-
- requested = ippFindAttribute(con->request, "requested-attributes",
- IPP_TAG_KEYWORD);
-
- copy_attrs(con->response, printer->attrs, requested, IPP_TAG_ZERO, 0);
- copy_attrs(con->response, CommonData, requested, IPP_TAG_ZERO, IPP_TAG_COPY);
+ }
- need_history = 0;
+ /*
+ * Check policy...
+ */
- if (MaxPrinterHistory > 0 && printer->num_history > 0 && requested)
+ if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
{
- for (i = 0; i < requested->num_values; i ++)
- if (!strcmp(requested->values[i].string.text, "all") ||
- !strcmp(requested->values[i].string.text, "printer-state-history"))
- {
- need_history = 1;
- break;
- }
+ send_http_error(con, status);
+ return;
}
- if (need_history)
- {
- history = ippAddCollections(con->response, IPP_TAG_PRINTER,
- "printer-state-history",
- printer->num_history, NULL);
+ /*
+ * Send the attributes...
+ */
- for (i = 0; i < printer->num_history; i ++)
- copy_attrs(history->values[i].collection = ippNew(), printer->history[i],
- NULL, IPP_TAG_ZERO, 0);
- }
+ ra = create_requested_array(con->request);
+
+ copy_printer_attrs(con, printer, ra);
+
+ cupsArrayDelete(ra);
- con->response->request.status.status_code = requested ? IPP_OK_SUBST : IPP_OK;
+ con->response->request.status.status_code = IPP_OK;
}
int type) /* I - 0 or CUPS_PRINTER_CLASS */
{
http_status_t status; /* Policy status */
- int i; /* Looping var */
- ipp_attribute_t *requested, /* requested-attributes */
- *history, /* History collection */
- *attr; /* Current attribute */
- int need_history; /* Need to send history collection? */
+ ipp_attribute_t *attr; /* Current attribute */
int limit; /* Maximum number of printers to return */
int count; /* Number of printers that match */
cupsd_printer_t *printer; /* Current printer pointer */
- time_t curtime; /* Current time */
int printer_type, /* printer-type attribute */
printer_mask; /* printer-type-mask attribute */
char *location; /* Location string */
const char *username; /* Current user */
char *first_printer_name; /* first-printer-name attribute */
- char printer_uri[HTTP_MAX_URI];
- /* Printer URI */
+ cups_array_t *ra; /* Requested attributes array */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_printers(%p[%d], %x)", con,
con->http.fd, type);
- if (!Printers || !cupsArrayCount(Printers))
+ /*
+ * Check policy...
+ */
+
+ if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
{
- send_ipp_status(con, IPP_NOT_FOUND, _("No destinations added."));
+ send_http_error(con, status);
return;
}
/*
- * Check policy...
+ * Check for printers...
*/
- if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
+ if (!Printers || !cupsArrayCount(Printers))
{
- send_http_error(con, status);
+ send_ipp_status(con, IPP_NOT_FOUND, _("No destinations added."));
return;
}
* See if they want to limit the number of printers reported...
*/
- if ((attr = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "limit",
+ IPP_TAG_INTEGER)) != NULL)
limit = attr->values[0].integer;
else
limit = 10000000;
else
username = NULL;
- requested = ippFindAttribute(con->request, "requested-attributes",
- IPP_TAG_KEYWORD);
-
- need_history = 0;
-
- if (MaxPrinterHistory > 0 && requested)
- {
- for (i = 0; i < requested->num_values; i ++)
- if (!strcmp(requested->values[i].string.text, "all") ||
- !strcmp(requested->values[i].string.text, "printer-state-history"))
- {
- need_history = 1;
- break;
- }
- }
+ ra = create_requested_array(con->request);
/*
* OK, build a list of printers for this printer...
*/
- curtime = time(NULL);
-
if (first_printer_name)
{
if ((printer = cupsdFindDest(first_printer_name)) == NULL)
printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
for (count = 0;
- count < limit && printer != NULL;
+ count < limit && printer;
printer = (cupsd_printer_t *)cupsArrayNext(Printers))
+ {
if ((!type || (printer->type & CUPS_PRINTER_CLASS) == type) &&
(printer->type & printer_mask) == printer_type &&
- (location == NULL || printer->location == NULL ||
+ (!location || !printer->location ||
!strcasecmp(printer->location, location)))
{
/*
count ++;
/*
- * Send the following attributes for each printer:
- *
- * printer-state
- * printer-state-message
- * printer-is-accepting-jobs
- * printer-is-shared
- * printer-up-time
- * printer-state-change-time
- * + all printer attributes
+ * Send the attributes...
*/
- if (!ippFindAttribute(printer->attrs, "printer-uri-supported",
- IPP_TAG_URI))
- {
- httpAssembleURIf(printer_uri, sizeof(printer_uri), "ipp", NULL,
- con->servername, con->serverport, "/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);
- }
-
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM,
- "printer-state", printer->state);
-
- add_printer_state_reasons(con, printer);
-
- ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-state-message", NULL, printer->state_message);
-
- ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
- printer->accepting);
- ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-shared",
- printer->shared);
-
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-up-time", curtime);
- ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "printer-state-change-time", printer->state_time);
- ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
- ippTimeToDate(curtime));
-
- 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-op-policy", NULL, printer->op_policy);
-
- add_queued_job_count(con, printer);
-
- copy_attrs(con->response, printer->attrs, requested, IPP_TAG_ZERO, 0);
-
- copy_attrs(con->response, CommonData, requested, IPP_TAG_ZERO,
- IPP_TAG_COPY);
-
- if (need_history && printer->num_history > 0)
- {
- history = ippAddCollections(con->response, IPP_TAG_PRINTER,
- "printer-state-history",
- printer->num_history, NULL);
-
- for (i = 0; i < printer->num_history; i ++)
- copy_attrs(history->values[i].collection = ippNew(),
- printer->history[i], NULL, IPP_TAG_ZERO, 0);
- }
+ copy_printer_attrs(con, printer, ra);
}
+ }
+
+ cupsArrayDelete(ra);
- con->response->request.status.status_code = requested ? IPP_OK_SUBST : IPP_OK;
+ con->response->request.status.status_code = IPP_OK;
}
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if (!strcmp(resource, "/") ||
(!strncmp(resource, "/jobs", 5) && strlen(resource) <= 6) ||
ra = create_requested_array(con->request);
- if ((attr = ippFindAttribute(con->request, "limit", IPP_TAG_INTEGER)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "limit",
+ IPP_TAG_INTEGER)) != NULL)
limit = attr->values[0].integer;
else
limit = 0;
if ((attr = ippFindAttribute(con->request, "my-subscriptions",
IPP_TAG_BOOLEAN)) != NULL &&
attr->values[0].boolean)
- {
- if (con->username[0])
- strlcpy(username, con->username, sizeof(username));
- else if ((attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME)) != NULL)
- strlcpy(username, attr->values[0].string.text, sizeof(username));
- else
- strcpy(username, "anonymous");
- }
+ strlcpy(username, get_username(con), sizeof(username));
else
username[0] = '\0';
}
+/*
+ * 'get_username()' - Get the username associated with a request.
+ */
+
+static const char * /* O - Username */
+get_username(cupsd_client_t *con) /* I - Connection */
+{
+ ipp_attribute_t *attr; /* Attribute */
+
+
+ if (con->username[0])
+ return (con->username);
+ else if ((attr = ippFindAttribute(con->request, "requesting-user-name",
+ IPP_TAG_NAME)) != NULL)
+ return (attr->values[0].string.text);
+ else
+ return ("anonymous");
+}
+
+
/*
* 'hold_job()' - Hold a print job.
*/
* Got a printer URI; see if we also have a job-id attribute...
*/
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Got a printer-uri attribute but no job-id!"));
* Got a job URI; parse it to get the job ID...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if (strncmp(resource, "/jobs/", 6))
{
if (!validate_user(job, con, job->username, username, sizeof(username)))
{
- send_ipp_status(con, IPP_FORBIDDEN,
- _("Not authorized to hold job #%d owned by \"%s\"!"),
- jobid, job->username);
+ send_http_error(con, HTTP_UNAUTHORIZED);
return;
}
IPP_TAG_KEYWORD)) == NULL)
attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
- if (attr != NULL)
+ if (attr)
{
/*
* Free the old hold value and copy the new one over...
*/
- free(attr->values[0].string.text);
+ _cupsStrFree(attr->values[0].string.text);
- if (newattr != NULL)
+ if (newattr)
{
attr->value_tag = newattr->value_tag;
- attr->values[0].string.text = strdup(newattr->values[0].string.text);
+ attr->values[0].string.text =
+ _cupsStrAlloc(newattr->values[0].string.text);
}
else
{
attr->value_tag = IPP_TAG_KEYWORD;
- attr->values[0].string.text = strdup("indefinite");
+ attr->values[0].string.text = _cupsStrAlloc("indefinite");
}
/*
cupsdSetJobHoldUntil(job, attr->values[0].string.text);
}
- cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was held by \"%s\".", jobid, username);
+ cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was held by \"%s\".", jobid,
+ username);
con->response->request.status.status_code = IPP_OK;
}
ipp_attribute_t *attr; /* Current attribute */
int jobid; /* Job ID */
cupsd_job_t *job; /* Current job */
- const char *dest; /* Destination */
- cups_ptype_t dtype; /* Destination type (printer or class) */
+ const char *src, /* Source printer/class */
+ *dest; /* Destination */
+ cups_ptype_t stype, /* Source type (printer or class) */
+ dtype; /* Destination type (printer or class) */
char method[HTTP_MAX_URI], /* Method portion of URI */
username[HTTP_MAX_URI], /* Username portion of URI */
host[HTTP_MAX_URI], /* Host portion of URI */
resource[HTTP_MAX_URI]; /* Resource portion of URI */
int port; /* Port portion of URI */
- cupsd_printer_t *printer; /* Printer */
+ cupsd_printer_t *sprinter, /* Source printer */
+ *dprinter; /* Destination printer */
cupsdLogMessage(CUPSD_LOG_DEBUG2, "move_job(%p[%d], %s)", con, con->http.fd,
uri->values[0].string.text);
+ /*
+ * Get the new printer or class...
+ */
+
+ if ((attr = ippFindAttribute(con->request, "job-printer-uri",
+ IPP_TAG_URI)) == NULL)
+ {
+ /*
+ * Need job-printer-uri...
+ */
+
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("job-printer-uri attribute missing!"));
+ return;
+ }
+
+ httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
+
+ if ((dest = cupsdValidateDest(host, resource, &dtype, &dprinter)) == NULL)
+ {
+ /*
+ * Bad URI...
+ */
+
+ send_ipp_status(con, IPP_NOT_FOUND,
+ _("The printer or class was not found."));
+ return;
+ }
+
+ /*
+ * Check policy...
+ */
+
+ if ((status = cupsdCheckPolicy(dprinter->op_policy_ptr, con, NULL)) != HTTP_OK)
+ {
+ send_http_error(con, status);
+ return;
+ }
+
/*
* See if we have a job URI or a printer URI...
*/
- if (strcmp(uri->name, "printer-uri") == 0)
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
+
+ if (!strcmp(uri->name, "printer-uri"))
{
/*
* Got a printer URI; see if we also have a job-id attribute...
*/
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
{
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("Got a printer-uri attribute but no job-id!"));
- return;
+ /*
+ * Move all jobs...
+ */
+
+ if ((src = cupsdValidateDest(host, resource, &stype, &sprinter)) == NULL)
+ {
+ /*
+ * Bad URI...
+ */
+
+ send_ipp_status(con, IPP_NOT_FOUND,
+ _("The printer or class was not found."));
+ return;
+ }
+
+ job = NULL;
}
+ else
+ {
+ /*
+ * Otherwise, just move a single job...
+ */
- jobid = attr->values[0].integer;
+ if ((job = cupsdFindJob(attr->values[0].integer)) == NULL)
+ {
+ /*
+ * Nope - return a "not found" error...
+ */
+
+ send_ipp_status(con, IPP_NOT_FOUND,
+ _("Job #%d does not exist!"), attr->values[0].integer);
+ return;
+ }
+ else
+ {
+ /*
+ * Job found, initialize source pointers...
+ */
+
+ src = NULL;
+ sprinter = NULL;
+ }
+ }
}
else
{
* Got a job URI; parse it to get the job ID...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
-
if (strncmp(resource, "/jobs/", 6))
{
/*
return;
}
+ /*
+ * See if the job exists...
+ */
+
jobid = atoi(resource + 6);
- }
- /*
- * See if the job exists...
- */
+ if ((job = cupsdFindJob(jobid)) == NULL)
+ {
+ /*
+ * Nope - return a "not found" error...
+ */
- if ((job = cupsdFindJob(jobid)) == NULL)
- {
- /*
- * Nope - return a "not found" error...
- */
+ send_ipp_status(con, IPP_NOT_FOUND,
+ _("Job #%d does not exist!"), jobid);
+ return;
+ }
+ else
+ {
+ /*
+ * Job found, initialize source pointers...
+ */
- send_ipp_status(con, IPP_NOT_FOUND,
- _("Job #%d does not exist!"), jobid);
- return;
+ src = NULL;
+ sprinter = NULL;
+ }
}
/*
- * See if the job has been completed...
+ * Now move the job or jobs...
*/
- if (job->state->values[0].integer > IPP_JOB_STOPPED)
+ if (job)
{
/*
- * Return a "not-possible" error...
+ * See if the job has been completed...
*/
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("Job #%d is finished and cannot be altered!"),
- jobid);
- return;
- }
-
- /*
- * See if the job is owned by the requesting user...
- */
+ if (job->state_value > IPP_JOB_STOPPED)
+ {
+ /*
+ * Return a "not-possible" error...
+ */
- if (!validate_user(job, con, job->username, username, sizeof(username)))
- {
- send_ipp_status(con, IPP_FORBIDDEN,
- _("You are not authorized to move job #%d owned "
- "by \"%s\"!"),
- jobid, job->username);
- return;
- }
+ send_ipp_status(con, IPP_NOT_POSSIBLE,
+ _("Job #%d is finished and cannot be altered!"),
+ job->id);
+ return;
+ }
- if ((attr = ippFindAttribute(con->request, "job-printer-uri", IPP_TAG_URI)) == NULL)
- {
/*
- * Need job-printer-uri...
+ * See if the job is owned by the requesting user...
*/
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("job-printer-uri attribute missing!"));
- return;
- }
-
- /*
- * Get the new printer or class...
- */
+ if (!validate_user(job, con, job->username, username, sizeof(username)))
+ {
+ send_http_error(con, HTTP_UNAUTHORIZED);
+ return;
+ }
- httpSeparateURI(attr->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ /*
+ * Move the job to a different printer or class...
+ */
- if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
+ cupsdMoveJob(job, dest);
+ }
+ else
{
/*
- * Bad URI...
+ * Got the source printer, now look through the jobs...
*/
- send_ipp_status(con, IPP_NOT_FOUND,
- _("The printer or class was not found."));
- return;
- }
+ for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
+ job;
+ job = (cupsd_job_t *)cupsArrayNext(Jobs))
+ {
+ /*
+ * See if the job is pointing at the source printer or has not been
+ * completed...
+ */
- /*
- * Check policy...
- */
+ if (strcasecmp(job->dest, src) ||
+ job->state_value > IPP_JOB_STOPPED)
+ continue;
- if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
- {
- send_http_error(con, status);
- return;
- }
+ /*
+ * See if the job can be moved by the requesting user...
+ */
- /*
- * Move the job to a different printer or class...
- */
+ if (!validate_user(job, con, job->username, username, sizeof(username)))
+ continue;
- cupsdMoveJob(job, dest);
+ /*
+ * Move the job to a different printer or class...
+ */
+
+ cupsdMoveJob(job, dest);
+ }
+ }
/*
* Start jobs if possible...
print_job(cupsd_client_t *con, /* I - Client connection */
ipp_attribute_t *uri) /* I - Printer URI */
{
- http_status_t status; /* Policy status */
ipp_attribute_t *attr; /* Current attribute */
ipp_attribute_t *format; /* Document-format attribute */
- const char *dest; /* Destination */
- cups_ptype_t dtype; /* Destination type (printer or class) */
- int priority; /* Job priority */
- char *title; /* Job name/title */
- cupsd_job_t *job; /* Current job */
- char job_uri[HTTP_MAX_URI], /* Job URI */
- method[HTTP_MAX_URI], /* Method portion of URI */
- username[HTTP_MAX_URI], /* Username portion of URI */
- host[HTTP_MAX_URI], /* Host portion of URI */
- resource[HTTP_MAX_URI], /* Resource portion of URI */
- filename[1024]; /* Job filename */
- int port; /* Port portion of URI */
+ cupsd_job_t *job; /* New job */
+ char filename[1024]; /* Job filename */
mime_type_t *filetype; /* Type of file */
char super[MIME_MAX_SUPER], /* Supertype of file */
type[MIME_MAX_TYPE], /* Subtype of file */
cupsd_printer_t *printer; /* Printer data */
struct stat fileinfo; /* File information */
int kbytes; /* Size of file */
- int i; /* Looping var */
- int lowerpagerange; /* Page range bound */
int compression; /* Document compression */
uri->values[0].string.text);
/*
- * Validate job template attributes; for now just copies and page-ranges...
- */
-
- if ((attr = ippFindAttribute(con->request, "copies", IPP_TAG_INTEGER)) != NULL)
- {
- if (attr->values[0].integer < 1 || attr->values[0].integer > MaxCopies)
- {
- send_ipp_status(con, IPP_ATTRIBUTES, _("Bad copies value %d."),
- attr->values[0].integer);
- ippAddInteger(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_INTEGER,
- "copies", attr->values[0].integer);
- return;
- }
- }
-
- if ((attr = ippFindAttribute(con->request, "page-ranges", IPP_TAG_RANGE)) != NULL)
- {
- for (i = 0, lowerpagerange = 1; i < attr->num_values; i ++)
- {
- if (attr->values[i].range.lower < lowerpagerange ||
- attr->values[i].range.lower > attr->values[i].range.upper)
- {
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("Bad page-ranges values %d-%d."),
- attr->values[i].range.lower,
- attr->values[i].range.upper);
- return;
- }
-
- lowerpagerange = attr->values[i].range.upper + 1;
- }
- }
-
- /*
- * OK, see if the client is sending the document compressed - CUPS
- * only supports "none" and "gzip".
+ * Validate print file attributes, for now just document-format and
+ * compression (CUPS only supports "none" and "gzip")...
*/
compression = CUPS_FILE_NONE;
- if ((attr = ippFindAttribute(con->request, "compression", IPP_TAG_KEYWORD)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "compression",
+ IPP_TAG_KEYWORD)) != NULL)
{
if (strcmp(attr->values[0].string.text, "none")
#ifdef HAVE_LIBZ
* Do we have a file to print?
*/
- if (!con->filename)
- {
- send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?!"));
- return;
- }
-
- /*
- * Is it a format we support?
- */
-
- if ((format = ippFindAttribute(con->request, "document-format",
- IPP_TAG_MIMETYPE)) != NULL)
- {
- /*
- * Grab format from client...
- */
-
- if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, type) != 2)
- {
- send_ipp_status(con, IPP_BAD_REQUEST,
- _("Could not scan type \"%s\"!"),
- format->values[0].string.text);
- return;
- }
- }
- else
- {
- /*
- * No document format attribute? Auto-type it!
- */
-
- strcpy(super, "application");
- strcpy(type, "octet-stream");
- }
-
- if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
- {
- /*
- * Auto-type the file...
- */
-
- cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: auto-typing file...");
-
- filetype = mimeFileType(MimeDatabase, con->filename, &compression);
-
- if (filetype != NULL)
- {
- /*
- * Replace the document-format attribute value with the auto-typed one.
- */
-
- snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
- filetype->type);
-
- if (format != NULL)
- {
- free(format->values[0].string.text);
- format->values[0].string.text = strdup(mimetype);
- }
- else
- ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
- "document-format", NULL, mimetype);
- }
- else
- filetype = mimeType(MimeDatabase, super, type);
- }
- else
- filetype = mimeType(MimeDatabase, super, type);
-
- if (filetype == NULL)
- {
- send_ipp_status(con, IPP_DOCUMENT_FORMAT,
- _("Unsupported format \'%s/%s\'!"), super, type);
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Hint: Do you have the raw file printing rules enabled?");
-
- if (format)
- ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE,
- "document-format", NULL, format->values[0].string.text);
-
- return;
- }
-
- cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: request file type is %s/%s.",
- filetype->super, filetype->type);
-
- /*
- * Read any embedded job ticket info from PS files...
- */
-
- if (!strcasecmp(filetype->super, "application") &&
- !strcasecmp(filetype->type, "postscript"))
- read_ps_job_ticket(con);
-
- /*
- * Is the destination valid?
- */
-
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
-
- if ((dest = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
- {
- /*
- * Bad URI...
- */
-
- send_ipp_status(con, IPP_NOT_FOUND,
- _("The printer or class was not found."));
- return;
- }
-
- /*
- * Check remote printing to non-shared printer...
- */
-
- if (!printer->shared &&
- strcasecmp(con->http.hostname, "localhost") &&
- strcasecmp(con->http.hostname, ServerName))
- {
- send_ipp_status(con, IPP_NOT_AUTHORIZED, _("Printer not shared!"));
- return;
- }
-
- /*
- * Check policy...
- */
-
- if ((status = cupsdCheckPolicy(printer->op_policy_ptr, con, NULL)) != HTTP_OK)
- {
- send_http_error(con, status);
- return;
- }
- else if ((printer->type & CUPS_PRINTER_AUTHENTICATED) && !con->username[0])
- {
- send_http_error(con, status);
- return;
- }
-
- /*
- * See if the printer is accepting jobs...
- */
-
- if (!printer->accepting)
- {
- send_ipp_status(con, IPP_NOT_ACCEPTING,
- _("Destination \"%s\" is not accepting jobs."), dest);
- return;
- }
-
- /*
- * Make sure we aren't over our limit...
- */
-
- if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
- cupsdCleanJobs();
-
- if (cupsArrayCount(Jobs) >= MaxJobs && MaxJobs)
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE,
- _("Too many jobs - %d jobs, max jobs is %d."),
- cupsArrayCount(Jobs), MaxJobs);
- return;
- }
-
- if (!check_quotas(con, printer))
- {
- send_ipp_status(con, IPP_NOT_POSSIBLE, _("Quota limit reached."));
- return;
- }
-
- /*
- * Create the job and set things up...
- */
-
- if ((attr = ippFindAttribute(con->request, "job-priority", IPP_TAG_INTEGER)) != NULL)
- priority = attr->values[0].integer;
- else
- ippAddInteger(con->request, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-priority",
- priority = 50);
-
- if ((attr = ippFindAttribute(con->request, "job-name", IPP_TAG_NAME)) != NULL)
- title = attr->values[0].string.text;
- else
- ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
- title = "Untitled");
-
- if ((job = cupsdAddJob(priority, printer->name)) == NULL)
- {
- send_ipp_status(con, IPP_INTERNAL_ERROR,
- _("Unable to add job for destination \"%s\"!"), dest);
- return;
- }
-
- job->dtype = dtype;
- job->attrs = con->request;
- con->request = NULL;
-
- /*
- * Copy the rest of the job info...
- */
-
- 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);
-
- save_auth_info(con, job);
- }
- else if (attr != NULL)
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: requesting-user-name = \"%s\"",
- attr->values[0].string.text);
-
- cupsdSetString(&job->username, attr->values[0].string.text);
- }
- else
- cupsdSetString(&job->username, "anonymous");
-
- if (attr == NULL)
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
- "job-originating-user-name", NULL, job->username);
- else
+ if (!con->filename)
{
- attr->group_tag = IPP_TAG_JOB;
- cupsdSetString(&attr->name, "job-originating-user-name");
+ send_ipp_status(con, IPP_BAD_REQUEST, _("No file!?!"));
+ return;
}
/*
- * Add remaining job attributes...
+ * Is it a format we support?
*/
- if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
- IPP_TAG_ZERO)) != NULL)
+ if ((format = ippFindAttribute(con->request, "document-format",
+ IPP_TAG_MIMETYPE)) != NULL)
{
/*
- * Request contains a job-originating-host-name attribute; validate it...
+ * Grab format from client...
*/
- if (attr->value_tag != IPP_TAG_NAME ||
- attr->num_values != 1 ||
- strcmp(con->http.hostname, "localhost") != 0)
+ if (sscanf(format->values[0].string.text, "%15[^/]/%31[^;]", super, type) != 2)
{
- /*
- * 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 ++)
- {
- free(attr->values[i].string.text);
- attr->values[i].string.text = NULL;
- if (attr->values[i].string.charset)
- {
- free(attr->values[i].string.charset);
- attr->values[i].string.charset = NULL;
- }
- }
-
- default :
- break;
- }
-
- /*
- * Use the default connection hostname instead...
- */
-
- attr->value_tag = IPP_TAG_NAME;
- attr->num_values = 1;
- attr->values[0].string.text = strdup(con->http.hostname);
+ send_ipp_status(con, IPP_BAD_REQUEST,
+ _("Could not scan type \"%s\"!"),
+ format->values[0].string.text);
+ return;
}
-
- attr->group_tag = IPP_TAG_JOB;
}
else
{
/*
- * No job-originating-host-name attribute, so use the hostname from
- * the connection...
+ * No document format attribute? Auto-type it!
*/
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME,
- "job-originating-host-name", NULL, con->http.hostname);
+ strcpy(super, "application");
+ strcpy(type, "octet-stream");
}
- ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
- job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
- "job-state", IPP_JOB_PENDING);
- 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);
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL,
- title);
-
- if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) == NULL)
- attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
- "job-k-octets", 0);
-
- if (stat(con->filename, &fileinfo))
- kbytes = 0;
- else
- kbytes = (fileinfo.st_size + 1023) / 1024;
-
- cupsdUpdateQuota(printer, job->username, 0, kbytes);
- attr->values[0].integer += kbytes;
-
- 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;
-
- if ((attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_KEYWORD)) == NULL)
- attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
- if (attr == NULL)
- attr = ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_KEYWORD,
- "job-hold-until", NULL, "no-hold");
-
- if (attr != NULL && strcmp(attr->values[0].string.text, "no-hold") != 0 &&
- !(printer->type & CUPS_PRINTER_REMOTE))
+ if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
{
/*
- * Hold job until specified time...
+ * Auto-type the file...
*/
- job->state->values[0].integer = IPP_JOB_HELD;
- cupsdSetJobHoldUntil(job, attr->values[0].string.text);
- }
+ ipp_attribute_t *doc_name; /* document-name attribute */
- if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) ||
- Classification)
- {
- /*
- * Add job sheets options...
- */
- if ((attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_ZERO)) == NULL)
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "print_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);
+
+ if (filetype)
{
- cupsdLogMessage(CUPSD_LOG_DEBUG,
- "Adding default job-sheets values \"%s,%s\"...",
- printer->job_sheets[0], printer->job_sheets[1]);
+ /*
+ * Replace the document-format attribute value with the auto-typed one.
+ */
- attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets",
- 2, NULL, NULL);
- attr->values[0].string.text = strdup(printer->job_sheets[0]);
- attr->values[1].string.text = strdup(printer->job_sheets[1]);
- }
+ snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
+ filetype->type);
- job->job_sheets = attr;
+ if (format)
+ {
+ _cupsStrFree(format->values[0].string.text);
- /*
- * Enforce classification level if set...
- */
+ format->values[0].string.text = _cupsStrAlloc(mimetype);
+ }
+ else
+ ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
+ "document-format", NULL, mimetype);
+ }
+ else
+ filetype = mimeType(MimeDatabase, super, type);
+ }
+ else
+ filetype = mimeType(MimeDatabase, super, type);
- if (Classification)
- {
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Classification=\"%s\", ClassifyOverride=%d",
- Classification ? Classification : "(null)",
- ClassifyOverride);
+ if (!filetype)
+ {
+ send_ipp_status(con, IPP_DOCUMENT_FORMAT,
+ _("Unsupported format \'%s/%s\'!"), super, type);
+ cupsdLogMessage(CUPSD_LOG_INFO,
+ "Hint: Do you have the raw file printing rules enabled?");
- if (ClassifyOverride)
- {
- if (strcmp(attr->values[0].string.text, "none") == 0 &&
- (attr->num_values == 1 ||
- strcmp(attr->values[1].string.text, "none") == 0))
- {
- /*
- * Force the leading banner to have the classification on it...
- */
+ if (format)
+ ippAddString(con->response, IPP_TAG_UNSUPPORTED_GROUP, IPP_TAG_MIMETYPE,
+ "document-format", NULL, format->values[0].string.text);
- cupsdSetString(&attr->values[0].string.text, Classification);
+ return;
+ }
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION FORCED "
- "job-sheets=\"%s,none\", "
- "job-originating-user-name=\"%s\"",
- job->id, Classification, job->username);
- }
- else if (attr->num_values == 2 &&
- strcmp(attr->values[0].string.text, attr->values[1].string.text) != 0 &&
- strcmp(attr->values[0].string.text, "none") != 0 &&
- strcmp(attr->values[1].string.text, "none") != 0)
- {
- /*
- * Can't put two different security markings on the same document!
- */
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: request file type is %s/%s.",
+ filetype->super, filetype->type);
- cupsdSetString(&attr->values[1].string.text, attr->values[0].string.text);
+ /*
+ * Read any embedded job ticket info from PS files...
+ */
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION FORCED "
- "job-sheets=\"%s,%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, attr->values[0].string.text,
- attr->values[1].string.text, job->username);
- }
- else if (strcmp(attr->values[0].string.text, Classification) &&
- strcmp(attr->values[0].string.text, "none") &&
- (attr->num_values == 1 ||
- (strcmp(attr->values[1].string.text, Classification) &&
- strcmp(attr->values[1].string.text, "none"))))
- {
- if (attr->num_values == 1)
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION OVERRIDDEN "
- "job-sheets=\"%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, attr->values[0].string.text,
- job->username);
- else
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION OVERRIDDEN "
- "job-sheets=\"%s,%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, attr->values[0].string.text,
- attr->values[1].string.text, job->username);
- }
- }
- else if (strcmp(attr->values[0].string.text, Classification) != 0 &&
- (attr->num_values == 1 ||
- strcmp(attr->values[1].string.text, Classification) != 0))
- {
- /*
- * Force the banner to have the classification on it...
- */
+ if (!strcasecmp(filetype->super, "application") &&
+ !strcasecmp(filetype->type, "postscript"))
+ read_ps_job_ticket(con);
- 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);
- }
- else
- {
- if (attr->num_values == 1 ||
- strcmp(attr->values[0].string.text, "none"))
- cupsdSetString(&(attr->values[0].string.text), Classification);
+ /*
+ * Create the job object...
+ */
- if (attr->num_values > 1 &&
- strcmp(attr->values[1].string.text, "none"))
- cupsdSetString(&(attr->values[1].string.text), Classification);
- }
+ if ((job = add_job(con, uri, &printer)) == NULL)
+ return;
- if (attr->num_values > 1)
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION FORCED "
- "job-sheets=\"%s,%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, attr->values[0].string.text,
- attr->values[1].string.text, job->username);
- else
- cupsdLogMessage(CUPSD_LOG_NOTICE,
- "[Job %d] CLASSIFICATION FORCED "
- "job-sheets=\"%s\", "
- "job-originating-user-name=\"%s\"",
- job->id, Classification, job->username);
- }
- }
+ /*
+ * Update quota data...
+ */
- /*
- * Add the starting sheet...
- */
+ if (stat(con->filename, &fileinfo))
+ kbytes = 0;
+ else
+ kbytes = (fileinfo.st_size + 1023) / 1024;
- if (!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)))
- {
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Adding start banner page \"%s\" to job %d.",
- attr->values[0].string.text, job->id);
+ cupsdUpdateQuota(printer, job->username, 0, kbytes);
- kbytes = copy_banner(con, job, attr->values[0].string.text);
+ if ((attr = ippFindAttribute(job->attrs, "job-k-octets",
+ IPP_TAG_INTEGER)) != NULL)
+ attr->values[0].integer += kbytes;
- cupsdUpdateQuota(printer, job->username, 0, kbytes);
- }
- }
- else if ((attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_ZERO)) != NULL)
- job->sheets = attr;
-
/*
* Add the job file...
*/
cupsdUpdateQuota(printer, job->username, 0, kbytes);
}
- /*
- * Fill in the response info...
- */
-
- snprintf(job_uri, sizeof(job_uri), "http://%s:%d/jobs/%d", ServerName,
- LocalPort, job->id);
-
- ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
- job_uri);
-
- ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
-
- ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
- job->state->values[0].integer);
- add_job_state_reasons(con, job);
-
- con->response->request.status.status_code = IPP_OK;
-
- /*
- * Add any job subscriptions...
- */
-
- add_job_subscriptions(con, job);
-
- /*
- * Set all but the first two attributes to the job attributes group...
- */
-
- for (attr = job->attrs->attrs->next->next; attr; attr = attr->next)
- attr->group_tag = IPP_TAG_JOB;
-
/*
* Log and save the job...
*/
cupsdSaveJob(job);
- cupsdAddEvent(CUPSD_EVENT_JOB_CREATED, printer, job, "Job created.");
-
/*
* Start the job if possible...
*/
return;
}
- if (strncmp(line, "%!PS-Adobe-", 11) != 0)
+ if (strncmp(line, "%!PS-Adobe-", 11))
{
/*
* Not a DSC-compliant file, so no job ticket info will be available...
num_options = 0;
options = NULL;
- while (cupsFileGets(fp, line, sizeof(line)) != NULL)
+ while (cupsFileGets(fp, line, sizeof(line)))
{
/*
* Stop at the first non-ticket line...
*/
- if (strncmp(line, "%cupsJobTicket:", 15) != 0)
+ if (strncmp(line, "%cupsJobTicket:", 15))
break;
/*
* See what the user wants to change.
*/
- for (attr = ticket->attrs; attr != NULL; attr = attr->next)
+ for (attr = ticket->attrs; attr; attr = attr->next)
{
if (attr->group_tag != IPP_TAG_JOB || !attr->name)
continue;
!strncmp(attr->name, "time-at-", 8))
continue; /* Read-only attrs */
- if ((attr2 = ippFindAttribute(con->request, attr->name, IPP_TAG_ZERO)) != NULL)
+ if ((attr2 = ippFindAttribute(con->request, attr->name,
+ IPP_TAG_ZERO)) != NULL)
{
/*
* Some other value; first free the old value...
}
else
{
- for (prev2 = con->request->attrs; prev2 != NULL; prev2 = prev2->next)
+ for (prev2 = con->request->attrs; prev2; prev2 = prev2->next)
if (prev2->next == attr2)
{
prev2->next = attr2->next;
if (con->request->last == attr2)
con->request->last = prev2;
- _ipp_free_attr(attr2);
+ _ippFreeAttr(attr2);
}
/*
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
cupsdSaveAllClasses();
cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" rejecting jobs (\"%s\").",
- name, con->username);
+ name, get_username(con));
}
else
{
cupsdSaveAllPrinters();
cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" rejecting jobs (\"%s\").",
- name, con->username);
+ name, get_username(con));
}
/*
* Got a printer URI; see if we also have a job-id attribute...
*/
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Got a printer-uri attribute but no job-id!"));
* Got a job URI; parse it to get the job ID...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if (strncmp(resource, "/jobs/", 6))
{
* See if job is "held"...
*/
- if (job->state->values[0].integer != IPP_JOB_HELD)
+ if (job->state_value != IPP_JOB_HELD)
{
/*
* Nope - return a "not possible" error...
if (!validate_user(job, con, job->username, username, sizeof(username)))
{
- send_ipp_status(con, IPP_FORBIDDEN,
- _("You are not authorized to release job id "
- "%d owned by \"%s\"!"),
- jobid, job->username);
+ send_http_error(con, HTTP_UNAUTHORIZED);
return;
}
* Reset the job-hold-until value to "no-hold"...
*/
- if ((attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_KEYWORD)) == NULL)
+ if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+ IPP_TAG_KEYWORD)) == NULL)
attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
- if (attr != NULL)
+ if (attr)
{
- free(attr->values[0].string.text);
+ _cupsStrFree(attr->values[0].string.text);
+
attr->value_tag = IPP_TAG_KEYWORD;
- attr->values[0].string.text = strdup("no-hold");
+ attr->values[0].string.text = _cupsStrAlloc("no-hold");
}
/*
cupsd_client_t *con, /* I - Client connection */
int sub_id) /* I - Subscription ID */
{
+ http_status_t status; /* Policy status */
+ cupsd_subscription_t *sub; /* Subscription */
+ ipp_attribute_t *lease; /* notify-lease-duration */
+
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "renew_subscription(con=%p[%d], sub_id=%d)",
+ con, con->http.fd, sub_id);
+
+ /*
+ * Is the subscription ID valid?
+ */
+
+ if ((sub = cupsdFindSubscription(sub_id)) == NULL)
+ {
+ /*
+ * Bad subscription ID...
+ */
+
+ send_ipp_status(con, IPP_NOT_FOUND,
+ _("notify-subscription-id %d no good!"), sub_id);
+ return;
+ }
+
+ if (sub->job)
+ {
+ /*
+ * Job subscriptions cannot be renewed...
+ */
+
+ send_ipp_status(con, IPP_NOT_POSSIBLE,
+ _("Job subscriptions cannot be renewed!"));
+ return;
+ }
+
+ /*
+ * Check policy...
+ */
+
+ if ((status = cupsdCheckPolicy(sub->dest ? sub->dest->op_policy_ptr :
+ DefaultPolicyPtr,
+ con, sub->owner)) != HTTP_OK)
+ {
+ send_http_error(con, status);
+ return;
+ }
+
+ /*
+ * Renew the subscription...
+ */
+
+ lease = ippFindAttribute(con->request, "notify-lease-duration",
+ IPP_TAG_INTEGER);
+
+ sub->lease = lease ? lease->values[0].integer : DefaultLeaseDuration;
+
+ if (MaxLeaseDuration && (sub->lease == 0 || sub->lease > MaxLeaseDuration))
+ {
+ cupsdLogMessage(CUPSD_LOG_INFO,
+ "renew_subscription: Limiting notify-lease-duration to "
+ "%d seconds.",
+ MaxLeaseDuration);
+ sub->lease = MaxLeaseDuration;
+ }
+
+ sub->expire = sub->lease ? time(NULL) + sub->lease : 0;
+
+ cupsdSaveAllSubscriptions();
+
+ con->response->request.status.status_code = IPP_OK;
}
* Got a printer URI; see if we also have a job-id attribute...
*/
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Got a printer-uri attribute but no job-id!"));
* Got a job URI; parse it to get the job ID...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
- if (strncmp(resource, "/jobs/", 6) != 0)
+ if (strncmp(resource, "/jobs/", 6))
{
/*
* Not a valid URI!
* See if job is in any of the "completed" states...
*/
- if (job->state->values[0].integer <= IPP_JOB_PROCESSING)
+ if (job->state_value <= IPP_JOB_PROCESSING)
{
/*
* Nope - return a "not possible" error...
* See if we have retained the job files...
*/
- if (!JobFiles && job->state->values[0].integer > IPP_JOB_STOPPED)
+ cupsdLoadJob(job);
+
+ if (!job->attrs ||job->num_files == 0)
{
/*
* Nope - return a "not possible" error...
if (!validate_user(job, con, job->username, username, sizeof(username)))
{
- send_ipp_status(con, IPP_FORBIDDEN,
- _("You are not authorized to restart job id "
- "%d owned by \"%s\"!"),
- jobid, job->username);
+ send_http_error(con, HTTP_UNAUTHORIZED);
return;
}
* Got a printer URI; see if we also have a job-id attribute...
*/
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Got a printer-uri attribute but no job-id!"));
* Got a job URI; parse it to get the job ID...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if (strncmp(resource, "/jobs/", 6))
{
if (!validate_user(job, con, job->username, username, sizeof(username)))
{
- send_ipp_status(con, IPP_FORBIDDEN,
- _("You are not authorized to send document "
- "for job #%d owned by \"%s\"!"),
- jobid, job->username);
+ send_http_error(con, HTTP_UNAUTHORIZED);
return;
}
compression = CUPS_FILE_NONE;
- if ((attr = ippFindAttribute(con->request, "compression", IPP_TAG_KEYWORD)) != NULL)
+ if ((attr = ippFindAttribute(con->request, "compression",
+ IPP_TAG_KEYWORD)) != NULL)
{
if (strcmp(attr->values[0].string.text, "none")
#ifdef HAVE_LIBZ
strcpy(type, "octet-stream");
}
- if (strcmp(super, "application") == 0 &&
- strcmp(type, "octet-stream") == 0)
+ if (!strcmp(super, "application") && !strcmp(type, "octet-stream"))
{
/*
* Auto-type the file...
*/
+ ipp_attribute_t *doc_name; /* document-name attribute */
+
+
cupsdLogMessage(CUPSD_LOG_DEBUG, "send_document: auto-typing file...");
- filetype = mimeFileType(MimeDatabase, con->filename, &compression);
+ 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);
- if (filetype != NULL)
+ if (filetype)
{
/*
* Replace the document-format attribute value with the auto-typed one.
snprintf(mimetype, sizeof(mimetype), "%s/%s", filetype->super,
filetype->type);
- if (format != NULL)
+ if (format)
{
- free(format->values[0].string.text);
- format->values[0].string.text = strdup(mimetype);
+ _cupsStrFree(format->values[0].string.text);
+ format->values[0].string.text = _cupsStrAlloc(mimetype);
}
else
ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE,
else
filetype = mimeType(MimeDatabase, super, type);
- if (filetype == NULL)
+ if (!filetype)
{
send_ipp_status(con, IPP_DOCUMENT_FORMAT,
_("Unsupported format \'%s/%s\'!"), super, type);
* Add the file to the job...
*/
+ cupsdLoadJob(job);
+
if (add_file(con, job, filetype, compression))
return;
cupsdUpdateQuota(printer, job->username, 0, kbytes);
- 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 += kbytes;
snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
* Start the job if this is the last document...
*/
- if ((attr = ippFindAttribute(con->request, "last-document", IPP_TAG_BOOLEAN)) != NULL &&
+ if ((attr = ippFindAttribute(con->request, "last-document",
+ IPP_TAG_BOOLEAN)) != NULL &&
attr->values[0].boolean)
{
/*
* See if we need to add the ending sheet...
*/
- if (printer != NULL &&
+ if (printer &&
!(printer->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT)) &&
- (attr = ippFindAttribute(job->attrs, "job-sheets", IPP_TAG_ZERO)) != NULL &&
+ (attr = ippFindAttribute(job->attrs, "job-sheets",
+ IPP_TAG_ZERO)) != NULL &&
attr->num_values > 1)
{
/*
cupsdUpdateQuota(printer, job->username, 0, kbytes);
}
- if (job->state->values[0].integer == IPP_JOB_STOPPED)
+ if (job->state_value == IPP_JOB_STOPPED)
+ {
job->state->values[0].integer = IPP_JOB_PENDING;
- else if (job->state->values[0].integer == IPP_JOB_HELD)
+ job->state_value = IPP_JOB_PENDING;
+ }
+ else if (job->state_value == IPP_JOB_HELD)
{
- if ((attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_KEYWORD)) == NULL)
+ if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+ IPP_TAG_KEYWORD)) == NULL)
attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
- if (attr == NULL || strcmp(attr->values[0].string.text, "no-hold") == 0)
+ if (!attr || !strcmp(attr->values[0].string.text, "no-hold"))
+ {
job->state->values[0].integer = IPP_JOB_PENDING;
+ job->state_value = IPP_JOB_PENDING;
+ }
}
cupsdSaveJob(job);
}
else
{
- if ((attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_KEYWORD)) == NULL)
+ if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
+ IPP_TAG_KEYWORD)) == NULL)
attr = ippFindAttribute(job->attrs, "job-hold-until", IPP_TAG_NAME);
- if (attr == NULL || strcmp(attr->values[0].string.text, "no-hold") == 0)
+ if (!attr || !strcmp(attr->values[0].string.text, "no-hold"))
{
job->state->values[0].integer = IPP_JOB_HELD;
+ job->state_value = IPP_JOB_HELD;
job->hold_until = time(NULL) + 60;
cupsdSaveJob(job);
}
ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", jobid);
ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
- job ? job->state->values[0].integer : IPP_JOB_CANCELLED);
+ job ? job->state_value : IPP_JOB_CANCELLED);
add_job_state_reasons(con, job);
con->response->request.status.status_code = IPP_OK;
con->response->request.status.status_code = status;
- if (ippFindAttribute(con->response, "attributes-charset", IPP_TAG_ZERO) == NULL)
+ if (ippFindAttribute(con->response, "attributes-charset",
+ IPP_TAG_ZERO) == NULL)
ippAddString(con->response, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
"attributes-charset", NULL, DefaultCharset);
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
cupsdLogMessage(CUPSD_LOG_INFO,
"Default destination set to \"%s\" by \"%s\".", name,
- con->username);
+ get_username(con));
/*
* Everything was ok, so return OK status...
* See if we have a job URI or a printer URI...
*/
- if (strcmp(uri->name, "printer-uri") == 0)
+ if (!strcmp(uri->name, "printer-uri"))
{
/*
* Got a printer URI; see if we also have a job-id attribute...
*/
- if ((attr = ippFindAttribute(con->request, "job-id", IPP_TAG_INTEGER)) == NULL)
+ if ((attr = ippFindAttribute(con->request, "job-id",
+ IPP_TAG_INTEGER)) == NULL)
{
send_ipp_status(con, IPP_BAD_REQUEST,
_("Got a printer-uri attribute but no job-id!"));
* Got a job URI; parse it to get the job ID...
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
- if (strncmp(resource, "/jobs/", 6) != 0)
+ if (strncmp(resource, "/jobs/", 6))
{
/*
* Not a valid URI!
* See if the job has been completed...
*/
- if (job->state->values[0].integer > IPP_JOB_STOPPED)
+ if (job->state_value > IPP_JOB_STOPPED)
{
/*
* Return a "not-possible" error...
if (!validate_user(job, con, job->username, username, sizeof(username)))
{
- send_ipp_status(con, IPP_FORBIDDEN,
- _("You are not authorized to alter job id "
- "%d owned by \"%s\"!"),
- jobid, job->username);
+ send_http_error(con, HTTP_UNAUTHORIZED);
return;
}
* See what the user wants to change.
*/
- for (attr = con->request->attrs; attr != NULL; attr = attr->next)
+ cupsdLoadJob(job);
+
+ for (attr = con->request->attrs; attr; attr = attr->next)
{
if (attr->group_tag != IPP_TAG_JOB || !attr->name)
continue;
if ((attr2 = copy_attribute(con->response, attr, 0)) != NULL)
attr2->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
}
- else if (job->state->values[0].integer >= IPP_JOB_PROCESSING)
+ else if (job->state_value >= IPP_JOB_PROCESSING)
{
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("Job is completed and cannot be changed."));
{
case IPP_JOB_PENDING :
case IPP_JOB_HELD :
- if (job->state->values[0].integer > IPP_JOB_HELD)
+ if (job->state_value > IPP_JOB_HELD)
{
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("Job state cannot be changed."));
return;
}
else if (con->response->request.status.status_code == IPP_OK)
+ {
job->state->values[0].integer = attr->values[0].integer;
+ job->state_value = attr->values[0].integer;
+ }
break;
case IPP_JOB_PROCESSING :
case IPP_JOB_STOPPED :
- if (job->state->values[0].integer != attr->values[0].integer)
+ if (job->state_value != attr->values[0].integer)
{
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("Job state cannot be changed."));
case IPP_JOB_CANCELLED :
case IPP_JOB_ABORTED :
case IPP_JOB_COMPLETED :
- if (job->state->values[0].integer > IPP_JOB_PROCESSING)
+ if (job->state_value > IPP_JOB_PROCESSING)
{
send_ipp_status(con, IPP_NOT_POSSIBLE,
_("Job state cannot be changed."));
if (JobHistory)
{
job->state->values[0].integer = attr->values[0].integer;
+ job->state_value = attr->values[0].integer;
cupsdSaveJob(job);
}
}
}
else if (con->response->request.status.status_code != IPP_OK)
continue;
- else if ((attr2 = ippFindAttribute(job->attrs, attr->name, IPP_TAG_ZERO)) != NULL)
+ else if ((attr2 = ippFindAttribute(job->attrs, attr->name,
+ IPP_TAG_ZERO)) != NULL)
{
/*
* Some other value; first free the old value...
if (job->attrs->last == attr2)
job->attrs->last = job->attrs->prev;
- _ipp_free_attr(attr2);
+ _ippFreeAttr(attr2);
/*
* Then copy the attribute...
if (attr2 == job->attrs->last)
job->attrs->last = job->attrs->prev;
- _ipp_free_attr(attr2);
+ _ippFreeAttr(attr2);
}
}
else
}
+/*
+ * 'set_printer_defaults()' - Set printer default options from a request.
+ */
+
+static void
+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 */
+ char name[256], /* New attribute name */
+ value[256]; /* String version of integer attrs */
+
+
+ for (attr = con->request->attrs; attr; attr = attr->next)
+ {
+ /*
+ * Skip non-printer attributes...
+ */
+
+ if (attr->group_tag != IPP_TAG_PRINTER || !attr->name)
+ continue;
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_printer_defaults: %s", attr->name);
+
+ if (!strcmp(attr->name, "job-sheets-default"))
+ {
+ /*
+ * Only allow keywords and names...
+ */
+
+ if (attr->value_tag != IPP_TAG_NAME && attr->value_tag != IPP_TAG_KEYWORD)
+ continue;
+
+ /*
+ * Only allow job-sheets-default to be set when running without a
+ * system high classification level...
+ */
+
+ if (Classification)
+ continue;
+
+ cupsdSetString(&printer->job_sheets[0], attr->values[0].string.text);
+
+ if (attr->num_values > 1)
+ cupsdSetString(&printer->job_sheets[1], attr->values[1].string.text);
+ else
+ cupsdSetString(&printer->job_sheets[1], "none");
+ }
+ else if (!strcmp(attr->name, "requesting-user-name-allowed"))
+ {
+ cupsdFreePrinterUsers(printer);
+
+ printer->deny_users = 0;
+
+ if (attr->value_tag == IPP_TAG_NAME &&
+ (attr->num_values > 1 ||
+ strcmp(attr->values[0].string.text, "all")))
+ {
+ for (i = 0; i < attr->num_values; i ++)
+ cupsdAddPrinterUser(printer, attr->values[i].string.text);
+ }
+ }
+ else if (!strcmp(attr->name, "requesting-user-name-denied"))
+ {
+ cupsdFreePrinterUsers(printer);
+
+ printer->deny_users = 1;
+
+ if (attr->value_tag == IPP_TAG_NAME &&
+ (attr->num_values > 1 ||
+ strcmp(attr->values[0].string.text, "none")))
+ {
+ for (i = 0; i < attr->num_values; i ++)
+ cupsdAddPrinterUser(printer, attr->values[i].string.text);
+ }
+ }
+ else if (!strcmp(attr->name, "job-quota-period"))
+ {
+ if (attr->value_tag != IPP_TAG_INTEGER)
+ continue;
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-quota-period to %d...",
+ attr->values[0].integer);
+ cupsdFreeQuotas(printer);
+
+ printer->quota_period = attr->values[0].integer;
+ }
+ else if (!strcmp(attr->name, "job-k-limit"))
+ {
+ if (attr->value_tag != IPP_TAG_INTEGER)
+ continue;
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-k-limit to %d...",
+ attr->values[0].integer);
+ cupsdFreeQuotas(printer);
+
+ printer->k_limit = attr->values[0].integer;
+ }
+ else if (!strcmp(attr->name, "job-page-limit"))
+ {
+ if (attr->value_tag != IPP_TAG_INTEGER)
+ continue;
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "Setting job-page-limit to %d...",
+ attr->values[0].integer);
+ cupsdFreeQuotas(printer);
+
+ printer->page_limit = attr->values[0].integer;
+ }
+ else if (!strcmp(attr->name, "printer-op-policy"))
+ {
+ cupsd_policy_t *p; /* Policy */
+
+
+ if (attr->value_tag != IPP_TAG_NAME)
+ continue;
+
+ if ((p = cupsdFindPolicy(attr->values[0].string.text)) != NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Setting printer-op-policy to \"%s\"...",
+ attr->values[0].string.text);
+ cupsdSetString(&printer->op_policy, attr->values[0].string.text);
+ printer->op_policy_ptr = p;
+ }
+ else
+ {
+ send_ipp_status(con, IPP_NOT_POSSIBLE,
+ _("Unknown printer-op-policy \"%s\"."),
+ attr->values[0].string.text);
+ return;
+ }
+ }
+ else if (!strcmp(attr->name, "printer-error-policy"))
+ {
+ if (attr->value_tag != IPP_TAG_NAME && attr->value_tag != IPP_TAG_KEYWORD)
+ continue;
+
+ if (strcmp(attr->values[0].string.text, "abort-job") &&
+ strcmp(attr->values[0].string.text, "retry-job") &&
+ strcmp(attr->values[0].string.text, "stop-printer"))
+ {
+ send_ipp_status(con, IPP_NOT_POSSIBLE,
+ _("Unknown printer-error-policy \"%s\"."),
+ attr->values[0].string.text);
+ return;
+ }
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Setting printer-error-policy to \"%s\"...",
+ attr->values[0].string.text);
+ cupsdSetString(&printer->error_policy, attr->values[0].string.text);
+ }
+ else if (!strcmp(attr->name, "document-format-default") ||
+ !strcmp(attr->name, "notify-lease-duration-default") ||
+ !strcmp(attr->name, "notify-notify-events-default"))
+ continue;
+
+ /*
+ * Skip any other non-default attributes...
+ */
+
+ namelen = strlen(attr->name);
+ if (namelen < 9 || strcmp(attr->name + namelen - 8, "-default") ||
+ namelen > (sizeof(name) - 1) || attr->num_values != 1)
+ continue;
+
+ /*
+ * OK, anything else must be a user-defined default...
+ */
+
+ strlcpy(name, attr->name, sizeof(name));
+ name[namelen - 8] = '\0'; /* Strip "-default" */
+
+ switch (attr->value_tag)
+ {
+ case IPP_TAG_DELETEATTR :
+ printer->num_options = cupsRemoveOption(name,
+ printer->num_options,
+ &(printer->options));
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Deleting %s", attr->name);
+ break;
+
+ case IPP_TAG_NAME :
+ case IPP_TAG_KEYWORD :
+ case IPP_TAG_URI :
+ printer->num_options = cupsAddOption(name,
+ attr->values[0].string.text,
+ printer->num_options,
+ &(printer->options));
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Setting %s to \"%s\"...", attr->name,
+ attr->values[0].string.text);
+ break;
+
+ case IPP_TAG_BOOLEAN :
+ printer->num_options = cupsAddOption(name,
+ attr->values[0].boolean ?
+ "true" : "false",
+ printer->num_options,
+ &(printer->options));
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Setting %s to %s...", attr->name,
+ attr->values[0].boolean ? "true" : "false");
+ break;
+
+ case IPP_TAG_INTEGER :
+ case IPP_TAG_ENUM :
+ sprintf(value, "%d", attr->values[0].integer);
+ printer->num_options = cupsAddOption(name, value,
+ printer->num_options,
+ &(printer->options));
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Setting %s to %s...", attr->name, value);
+ break;
+
+ case IPP_TAG_RANGE :
+ sprintf(value, "%d-%d", attr->values[0].range.lower,
+ attr->values[0].range.upper);
+ printer->num_options = cupsAddOption(name, value,
+ printer->num_options,
+ &(printer->options));
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Setting %s to %s...", attr->name, value);
+ break;
+
+ case IPP_TAG_RESOLUTION :
+ sprintf(value, "%dx%d%s", attr->values[0].resolution.xres,
+ attr->values[0].resolution.yres,
+ attr->values[0].resolution.units == IPP_RES_PER_INCH ?
+ "dpi" : "dpc");
+ printer->num_options = cupsAddOption(name, value,
+ printer->num_options,
+ &(printer->options));
+ cupsdLogMessage(CUPSD_LOG_DEBUG,
+ "Setting %s to %s...", attr->name, value);
+ break;
+
+ default :
+ /* Do nothing for other values */
+ break;
+ }
+ }
+}
+
+
/*
* 'start_printer()' - Start a printer.
*/
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
if (dtype & CUPS_PRINTER_CLASS)
cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" started by \"%s\".", name,
- con->username);
+ get_username(con));
+ else
cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" started by \"%s\".", name,
- con->username);
+ get_username(con));
cupsdCheckJobs();
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if ((name = cupsdValidateDest(host, resource, &dtype, &printer)) == NULL)
{
if (dtype & CUPS_PRINTER_CLASS)
cupsdLogMessage(CUPSD_LOG_INFO, "Class \"%s\" stopped by \"%s\".", name,
- con->username);
+ get_username(con));
else
cupsdLogMessage(CUPSD_LOG_INFO, "Printer \"%s\" stopped by \"%s\".", name,
- con->username);
+ get_username(con));
/*
* Everything was ok, so return OK status...
* doesn't support compression yet...
*/
- if ((attr = ippFindAttribute(con->request, "compression", IPP_TAG_KEYWORD)) != NULL &&
- strcmp(attr->values[0].string.text, "none") == 0)
+ if ((attr = ippFindAttribute(con->request, "compression",
+ IPP_TAG_KEYWORD)) != NULL &&
+ !strcmp(attr->values[0].string.text, "none"))
{
send_ipp_status(con, IPP_ATTRIBUTES,
_("Unsupported compression attribute %s!"),
return;
}
- if ((strcmp(super, "application") != 0 ||
- strcmp(type, "octet-stream") != 0) &&
- mimeType(MimeDatabase, super, type) == NULL)
+ if ((strcmp(super, "application") || strcmp(type, "octet-stream")) &&
+ !mimeType(MimeDatabase, super, type))
{
cupsdLogMessage(CUPSD_LOG_INFO,
"Hint: Do you have the raw file printing rules enabled?");
* Is the destination valid?
*/
- httpSeparateURI(uri->values[0].string.text, method, sizeof(method),
- username, sizeof(username), host, sizeof(host), &port,
- resource, sizeof(resource));
+ httpSeparateURI(HTTP_URI_CODING_ALL, uri->values[0].string.text, method,
+ sizeof(method), username, sizeof(username), host,
+ sizeof(host), &port, resource, sizeof(resource));
if (cupsdValidateDest(host, resource, &dtype, &printer) == NULL)
{
char *username, /* O - Authenticated username */
int userlen) /* I - Length of username */
{
- ipp_attribute_t *attr; /* requesting-user-name attribute */
cupsd_printer_t *printer; /* Printer for job */
* Get the best authenticated username that is available.
*/
- if (con->username[0])
- strlcpy(username, con->username, userlen);
- else if ((attr = ippFindAttribute(con->request, "requesting-user-name",
- IPP_TAG_NAME)) != NULL)
- strlcpy(username, attr->values[0].string.text, userlen);
- else
- strlcpy(username, "anonymous", userlen);
+ strlcpy(username, get_username(con), userlen);
/*
* Check the username against the owner...
/*
- * End of "$Id: ipp.c 4906 2006-01-10 20:53:28Z mike $".
+ * End of "$Id: ipp.c 5232 2006-03-05 17:59:19Z mike $".
*/