/*
- * "$Id: job.c 5974 2006-09-20 18:42:37Z mike $"
+ * "$Id: job.c 6318 2007-03-06 04:36:55Z mike $"
*
* Job management routines for the Common UNIX Printing System (CUPS).
*
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
* property of Easy Software Products and are protected by Federal
job->back_pipes[1] = -1;
job->print_pipes[0] = -1;
job->print_pipes[1] = -1;
+ job->side_pipes[0] = -1;
+ job->side_pipes[1] = -1;
job->status_pipes[0] = -1;
job->status_pipes[1] = -1;
pclass = printer;
- if (!(pclass->type & CUPS_PRINTER_REMOTE))
- {
- if (pclass->state != IPP_PRINTER_STOPPED)
- printer = cupsdFindAvailablePrinter(job->dest);
- else
- printer = NULL;
- }
+ if (!(pclass->type & CUPS_PRINTER_REMOTE) &&
+ pclass->state != IPP_PRINTER_STOPPED)
+ printer = cupsdFindAvailablePrinter(job->dest);
+ else
+ printer = NULL;
}
if (!printer && !pclass)
void
cupsdFinishJob(cupsd_job_t *job) /* I - Job */
{
- int job_history; /* Did cupsdCancelJob() keep the job? */
cupsd_printer_t *printer; /* Current printer */
* Close the pipe and clear the input bit.
*/
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdFinishJob: Removing fd %d from InputSet...",
- job->status_buffer->fd);
-
- FD_CLR(job->status_buffer->fd, InputSet);
+ cupsdRemoveSelect(job->status_buffer->fd);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"cupsdFinishJob: Closing status pipes [ %d %d ]...",
* Close out this job...
*/
- job_history = JobHistory && !(job->dtype & CUPS_PRINTER_REMOTE);
-
cupsdCancelJob(job, 0, IPP_JOB_COMPLETED);
cupsdCheckJobs();
}
cups_file_t *fp; /* Job file */
int fileid; /* Current file ID */
ipp_attribute_t *attr; /* Job attribute */
- char scheme[32], /* Scheme portion of URI */
- username[64], /* Username portion of URI */
- host[HTTP_MAX_HOST],
- /* Host portion of URI */
- resource[HTTP_MAX_URI];
- /* Resource portion of URI */
- int port; /* Port portion of URI */
const char *dest; /* Destination */
mime_type_t **filetypes; /* New filetypes array */
int *compressions; /* New compressions array */
return;
}
- httpSeparateURI(HTTP_URI_CODING_ALL, attr->values[0].string.text, scheme,
- sizeof(scheme), username, sizeof(username), host,
- sizeof(host), &port, resource, sizeof(resource));
-
- if ((dest = cupsdValidateDest(host, resource, &(job->dtype),
+ if ((dest = cupsdValidateDest(attr->values[0].string.text, &(job->dtype),
NULL)) == NULL)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
job->hold_until = curtime +
((17 - curdate->tm_hour) * 60 + 59 -
curdate->tm_min) * 60 + 60 - curdate->tm_sec;
- }
+ }
else if (!strcmp(when, "second-shift"))
{
/*
job->hold_until = curtime +
((15 - curdate->tm_hour) * 60 + 59 -
curdate->tm_min) * 60 + 60 - curdate->tm_sec;
- }
+ }
else if (!strcmp(when, "third-shift"))
{
/*
job->hold_until = curtime +
((23 - curdate->tm_hour) * 60 + 59 -
curdate->tm_min) * 60 + 60 - curdate->tm_sec;
- }
+ }
else if (!strcmp(when, "weekend"))
{
/*
*/
if (job->hold_until < curtime)
- job->hold_until += 24 * 60 * 60 * 60;
+ job->hold_until += 24 * 60 * 60;
}
cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSetJobHoldUntil: hold_until = %d",
cupsdClosePipe(job->back_pipes);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdStopJob: Closing side pipes [ %d %d ]...",
+ job->side_pipes[0], job->side_pipes[1]);
+
+ cupsdClosePipe(job->side_pipes);
+
if (job->status_buffer)
{
/*
* Close the pipe and clear the input bit.
*/
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "cupsdStopJob: Removing fd %d from InputSet...",
- job->status_buffer->fd);
-
- FD_CLR(job->status_buffer->fd, InputSet);
+ cupsdRemoveSelect(job->status_buffer->fd);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"cupsdStopJob: Closing status pipes [ %d %d ]...",
}
else if (!sscanf(message, "%*d%d", &copies))
copies = 1;
-
+
job->sheets->values[0].integer += copies;
if (job->printer->page_limit)
* Set attribute(s)...
*/
- /**** TODO ****/
+ int num_attrs; /* Number of attributes */
+ cups_option_t *attrs; /* Attributes */
+ const char *attr; /* Attribute */
+
+
+ num_attrs = cupsParseOptions(message, 0, &attrs);
+
+ if ((attr = cupsGetOption("auth-info-required", num_attrs,
+ attrs)) != NULL)
+ cupsdSetAuthInfoRequired(job->printer, attr, NULL);
+
+ cupsFreeOptions(num_attrs, attrs);
}
#ifdef __APPLE__
else if (!strncmp(message, "recoverable:", 12))
strlcpy(job->printer->state_message, message,
sizeof(job->printer->state_message));
cupsdAddPrinterHistory(job->printer);
+ event |= CUPSD_EVENT_PRINTER_STATE_CHANGED;
}
if (!strchr(job->status_buffer->buffer, '\n'))
{
cupsdClearString(&job->username);
cupsdClearString(&job->dest);
+#ifdef HAVE_GSSAPI
+ cupsdClearString(&job->ccname);
+#endif /* HAVE_GSSAPI */
if (job->num_files > 0)
{
/*
- * 'ipp_length()' - Compute the size of the buffer needed to hold
+ * 'ipp_length()' - Compute the size of the buffer needed to hold
* the textual IPP attributes.
*/
job->back_pipes[1] = -1;
job->print_pipes[0] = -1;
job->print_pipes[1] = -1;
+ job->side_pipes[0] = -1;
+ job->side_pipes[1] = -1;
job->status_pipes[0] = -1;
job->status_pipes[1] = -1;
job->back_pipes[1] = -1;
job->print_pipes[0] = -1;
job->print_pipes[1] = -1;
+ job->side_pipes[0] = -1;
+ job->side_pipes[1] = -1;
job->status_pipes[0] = -1;
job->status_pipes[1] = -1;
* 'set_hold_until()' - Set the hold time and update job-hold-until attribute...
*/
-static void
+static void
set_hold_until(cupsd_job_t *job, /* I - Job to update */
time_t holdtime) /* I - Hold until time */
{
*/
holddate = gmtime(&holdtime);
- snprintf(holdstr, sizeof(holdstr), "%d:%d:%d", holddate->tm_hour,
+ snprintf(holdstr, sizeof(holdstr), "%d:%d:%d", holddate->tm_hour,
holddate->tm_min, holddate->tm_sec);
if ((attr = ippFindAttribute(job->attrs, "job-hold-until",
{
int i; /* Looping var */
int slot; /* Pipe slot */
- cups_array_t *filters; /* Filters for job */
+ cups_array_t *filters, /* Filters for job */
+ *prefilters; /* Filters with prefilters */
mime_filter_t *filter, /* Current filter */
+ *prefilter, /* Prefilter */
port_monitor; /* Port monitor filter */
char method[255], /* Method for output */
*optptr, /* Pointer to options */
title[IPP_MAX_NAME],
/* Job title string */
copies[255], /* # copies string */
- *envp[MAX_ENV + 11],
+ *envp[MAX_ENV + 12],
/* Environment variables */
charset[255], /* CHARSET env variable */
class_name[255],/* CLASS env variable */
cupsArrayDelete(filters);
filters = NULL;
}
+
+ /*
+ * If this printer has any pre-filters, insert the required pre-filter
+ * in the filters array...
+ */
+
+ if (printer->prefiltertype && filters)
+ {
+ prefilters = cupsArrayNew(NULL, NULL);
+
+ for (filter = (mime_filter_t *)cupsArrayFirst(filters);
+ filter;
+ filter = (mime_filter_t *)cupsArrayNext(filters))
+ {
+ if ((prefilter = mimeFilterLookup(MimeDatabase, filter->src,
+ printer->prefiltertype)))
+ {
+ cupsArrayAdd(prefilters, prefilter);
+ job->cost += prefilter->cost;
+ }
+
+ cupsArrayAdd(prefilters, filter);
+ }
+
+ cupsArrayDelete(filters);
+ filters = prefilters;
+ }
}
/*
* Add gziptoany filter to the front of the list...
*/
+ if (!filters)
+ filters = cupsArrayNew(NULL, NULL);
+
if (!cupsArrayInsert(filters, &gziptoany_filter))
{
cupsdLogMessage(CUPSD_LOG_ERROR,
* Add port monitor to the end of the list...
*/
+ if (!filters)
+ filters = cupsArrayNew(NULL, NULL);
+
if (!cupsArrayAdd(filters, &port_monitor))
{
cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to add port monitor - %s",
fcntl(job->back_pipes[1], F_SETFL,
fcntl(job->back_pipes[1], F_GETFL) | O_NONBLOCK);
+
+ /*
+ * Create the side-channel pipes and make them non-blocking...
+ */
+
+ socketpair(AF_LOCAL, SOCK_STREAM, 0, job->side_pipes);
+
+ fcntl(job->side_pipes[0], F_SETFL,
+ fcntl(job->side_pipes[0], F_GETFL) | O_NONBLOCK);
+
+ fcntl(job->side_pipes[1], F_SETFL,
+ fcntl(job->side_pipes[1], F_GETFL) | O_NONBLOCK);
}
/*
envp[envc ++] = class_name;
}
+#ifdef HAVE_GSSAPI
+ if (job->ccname)
+ envp[envc ++] = job->ccname;
+#endif /* HAVE_GSSAPI */
+
envp[envc] = NULL;
for (i = 0; i < envc; i ++)
strerror(errno));
snprintf(printer->state_message, sizeof(printer->state_message),
"Unable to create status pipes - %s.", strerror(errno));
-
+
cupsdAddPrinterHistory(printer);
-
+
cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, job->printer, job,
"Job canceled because the server could not create the job "
"status pipes.");
-
+
goto abort_job;
}
-
+
cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job: status_pipes = [ %d %d ]",
job->status_pipes[0], job->status_pipes[1]);
-
+
job->status_buffer = cupsdStatBufNew(job->status_pipes[0], "[Job %d]",
job->id);
}
pid = cupsdStartProcess(command, argv, envp, filterfds[!slot][0],
filterfds[slot][1], job->status_pipes[1],
- job->back_pipes[0], 0, job->filters + i);
+ job->back_pipes[0], job->side_pipes[0], 0,
+ job->filters + i);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"start_job: Closing filter pipes for slot %d "
pid = cupsdStartProcess(command, argv, envp, filterfds[!slot][0],
filterfds[slot][1], job->status_pipes[1],
- job->back_pipes[1], backroot,
- &(job->backend));
+ job->back_pipes[1], job->side_pipes[1],
+ backroot, &(job->backend));
if (pid == 0)
{
cupsdClosePipe(job->back_pipes);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "start_job: Closing side pipes [ %d %d ]...",
+ job->side_pipes[0], job->side_pipes[1]);
+
+ cupsdClosePipe(job->side_pipes);
+
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"start_job: Closing status output pipe %d...",
job->status_pipes[1]);
free(argv);
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "start_job: Adding fd %d to InputSet...",
- job->status_buffer->fd);
-
- FD_SET(job->status_buffer->fd, InputSet);
+ cupsdAddSelect(job->status_buffer->fd, (cupsd_selfunc_t)cupsdUpdateJob, NULL,
+ job);
cupsdAddEvent(CUPSD_EVENT_JOB_STATE, job->printer, job, "Job #%d started.",
job->id);
/*
- * End of "$Id: job.c 5974 2006-09-20 18:42:37Z mike $".
+ * End of "$Id: job.c 6318 2007-03-06 04:36:55Z mike $".
*/