/*
- * "$Id: ipp-var.c 7940 2008-09-16 00:45:16Z mike $"
+ * "$Id$"
*
- * CGI <-> IPP variable routines for the Common UNIX Printing System (CUPS).
+ * CGI <-> IPP variable routines for CUPS.
*
- * Copyright 2007-2008 by Apple Inc.
+ * Copyright 2007-2012 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
*nameptr = '\0';
if (!strncmp(name, "printer_state_history", 21))
- strcpy(name, "printer_state_history");
+ strlcpy(name, "printer_state_history", sizeof(name));
/*
* Possibly add it to the list of attributes...
/*
- * See who is logged in...
+ * Make sure we have a username...
*/
if ((user = getenv("REMOTE_USER")) == NULL)
- user = "guest";
+ {
+ puts("Status: 401\n");
+ exit(0);
+ }
/*
* See if the user has already selected a new destination...
NULL, job_uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", NULL, "job-printer-uri");
-
+
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
if ((attr = ippFindAttribute(response, "job-printer-uri",
*/
cgiStartHTML(cgiText(_("Move Job")));
- cgiShowIPPError(_("Unable to find destination for job!"));
+ cgiShowIPPError(_("Unable to find destination for job"));
cgiEndHTML();
return;
}
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", NULL, "printer-uri-supported");
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- "requesting-user-name", NULL, user);
+ if (user)
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+ "requesting-user-name", NULL, user);
+
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type",
+ CUPS_PRINTER_LOCAL);
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type-mask",
+ CUPS_PRINTER_SCANNER);
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
* If the name is not the same as the current destination, add it!
*/
- if (strcasecmp(name, dest))
+ if (_cups_strcasecmp(name, dest))
{
cgiSetArray("JOB_PRINTER_URI", i, attr->values[0].string.text);
cgiSetArray("JOB_PRINTER_NAME", i, name);
else
cgiStartHTML(cgiText(_("Move All Jobs")));
- cgiCopyTemplateLang("job-move.tmpl");
+ if (cgiGetSize("JOB_PRINTER_NAME") > 0)
+ cgiCopyTemplateLang("job-move.tmpl");
+ else
+ {
+ if (job_id)
+ cgiSetVariable("MESSAGE", cgiText(_("Unable to move job")));
+ else
+ cgiSetVariable("MESSAGE", cgiText(_("Unable to move jobs")));
+
+ cgiSetVariable("ERROR", cgiText(_("No destinations added.")));
+ cgiCopyTemplateLang("error.tmpl");
+ }
}
else
{
{
const char *path = strstr(job_printer_uri, "/printers/");
if (!path)
+ {
path = strstr(job_printer_uri, "/classes/");
+ cgiSetVariable("IS_CLASS", "YES");
+ }
if (path)
{
ipp_t *request, /* Get-Job-Attributes request */
*response; /* Get-Job-Attributes response */
ipp_attribute_t *attr; /* Current job attribute */
- static const char const *job_attrs[] =/* Job attributes we want */
+ static const char * const job_attrs[] =/* Job attributes we want */
{
"job-state",
"job-printer-state-message"
* Show status...
*/
- cgiStartMultipart();
- cgiStartHTML(title);
- cgiCopyTemplateLang("command.tmpl");
- cgiEndHTML();
- fflush(stdout);
+ if (cgiSupportsMultipart())
+ {
+ cgiStartMultipart();
+ cgiStartHTML(title);
+ cgiCopyTemplateLang("command.tmpl");
+ cgiEndHTML();
+ fflush(stdout);
+ }
/*
* Send the command file job...
if ((job_id = cupsCreateJob(http, dest, title,
1, &hold_option)) < 1)
{
- cgiSetVariable("MESSAGE", cgiText(_("Unable to send command to printer driver!")));
+ cgiSetVariable("MESSAGE", cgiText(_("Unable to send command to printer driver")));
cgiSetVariable("ERROR", cupsLastErrorString());
cgiStartHTML(title);
cgiCopyTemplateLang("error.tmpl");
cgiEndHTML();
- cgiEndMultipart();
+
+ if (cgiSupportsMultipart())
+ cgiEndMultipart();
return;
}
if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE)
{
- cgiSetVariable("MESSAGE", cgiText(_("Unable to send command to printer driver!")));
+ cgiSetVariable("MESSAGE", cgiText(_("Unable to send command to printer driver")));
cgiSetVariable("ERROR", cupsLastErrorString());
cgiStartHTML(title);
cgiCopyTemplateLang("error.tmpl");
cgiEndHTML();
- cgiEndMultipart();
+
+ if (cgiSupportsMultipart())
+ cgiEndMultipart();
cupsCancelJob(dest, job_id);
return;
* Wait for the job to complete...
*/
- for (;;)
+ if (cgiSupportsMultipart())
{
- /*
- * Get the current job state...
- */
+ for (;;)
+ {
+ /*
+ * Get the current job state...
+ */
- snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
- request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES);
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
- NULL, uri);
- if (user)
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- "requesting-user-name", NULL, user);
- ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
- "requested-attributes", 2, NULL, job_attrs);
+ snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id);
+ request = ippNewRequest(IPP_GET_JOB_ATTRIBUTES);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri",
+ NULL, uri);
+ if (user)
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+ "requesting-user-name", NULL, user);
+ ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "requested-attributes", 2, NULL, job_attrs);
- if ((response = cupsDoRequest(http, request, "/")) != NULL)
- cgiSetIPPVars(response, NULL, NULL, NULL, 0);
+ if ((response = cupsDoRequest(http, request, "/")) != NULL)
+ cgiSetIPPVars(response, NULL, NULL, NULL, 0);
- attr = ippFindAttribute(response, "job-state", IPP_TAG_ENUM);
- if (!attr || attr->values[0].integer >= IPP_JOB_STOPPED)
- {
- ippDelete(response);
- break;
- }
+ attr = ippFindAttribute(response, "job-state", IPP_TAG_ENUM);
+ if (!attr || attr->values[0].integer >= IPP_JOB_STOPPED ||
+ attr->values[0].integer == IPP_JOB_HELD)
+ {
+ ippDelete(response);
+ break;
+ }
- /*
- * Job not complete, so update the status...
- */
+ /*
+ * Job not complete, so update the status...
+ */
- ippDelete(response);
+ ippDelete(response);
- cgiStartHTML(title);
- cgiCopyTemplateLang("command.tmpl");
- cgiEndHTML();
- fflush(stdout);
+ cgiStartHTML(title);
+ cgiCopyTemplateLang("command.tmpl");
+ cgiEndHTML();
+ fflush(stdout);
- sleep(5);
+ sleep(5);
+ }
}
/*
cgiStartHTML(title);
cgiCopyTemplateLang("command.tmpl");
cgiEndHTML();
- cgiEndMultipart();
+
+ if (cgiSupportsMultipart())
+ cgiEndMultipart();
}
cgiStartHTML(cgiText(_("Print Test Page")));
if (cupsLastError() > IPP_OK_CONFLICT)
- cgiShowIPPError(_("Unable to print test page:"));
+ cgiShowIPPError(_("Unable to print test page"));
else
{
cgiSetVariable("PRINTER_NAME", dest);
* Map local access to a local URI...
*/
- if (!strcasecmp(hostname, "127.0.0.1") ||
- !strcasecmp(hostname, "[::1]") ||
- !strcasecmp(hostname, "localhost") ||
- !strncasecmp(hostname, "localhost.", 10) ||
- !strcasecmp(hostname, server) ||
- !strcasecmp(hostname, servername))
+ if (!_cups_strcasecmp(hostname, "127.0.0.1") ||
+ !_cups_strcasecmp(hostname, "[::1]") ||
+ !_cups_strcasecmp(hostname, "localhost") ||
+ !_cups_strncasecmp(hostname, "localhost.", 10) ||
+ !_cups_strcasecmp(hostname, server) ||
+ !_cups_strcasecmp(hostname, servername))
{
/*
* Make URI relative to the current server...
ishttps ? "https" : "http",
userpass, hostname, port, resource);
else
- snprintf(url, urlsize, "%s://%s:%d%s",
+ snprintf(url, urlsize, "%s://%s:%d%s",
ishttps ? "https" : "http",
hostname, port, resource);
}
"%dx%d%s", attr->values[i].resolution.xres,
attr->values[i].resolution.yres,
attr->values[i].resolution.units == IPP_RES_PER_INCH ?
- "dpi" : "dpc");
+ "dpi" : "dpcm");
break;
case IPP_TAG_URI :
(filter->value_tag >= IPP_TAG_TEXTLANG &&
filter->value_tag <= IPP_TAG_MIMETYPE)) &&
filter->values[0].string.text != NULL &&
- !strcasecmp(filter->values[0].string.text, filter_value))
+ !_cups_strcasecmp(filter->values[0].string.text, filter_value))
break;
if (!filter)
int ascending, /* Order of jobs (0 = descending) */
first, /* First job to show */
count; /* Number of jobs */
- const char *var; /* Form variable */
+ const char *var, /* Form variable */
+ *query, /* Query string */
+ *section; /* Section in web interface */
void *search; /* Search data */
char url[1024], /* Printer URI */
val[1024]; /* Form variable */
NULL, url);
}
else
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL,
- "ipp://localhost/jobs");
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
+ "ipp://localhost/");
- if ((which_jobs = cgiGetVariable("which_jobs")) != NULL)
+ if ((which_jobs = cgiGetVariable("which_jobs")) != NULL && *which_jobs)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs",
NULL, which_jobs);
* Get a list of matching job objects.
*/
- if ((var = cgiGetVariable("QUERY")) != NULL &&
+ if ((query = cgiGetVariable("QUERY")) != NULL &&
!cgiGetVariable("CLEAR"))
- search = cgiCompileSearch(var);
+ search = cgiCompileSearch(query);
else
+ {
+ query = NULL;
search = NULL;
+ }
jobs = cgiGetIPPObjects(response, search);
count = cupsArrayCount(jobs);
if (first < 0)
first = 0;
+ if ((var = cgiGetVariable("ORDER")) != NULL && *var)
+ ascending = !_cups_strcasecmp(var, "asc");
+ else
+ ascending = !which_jobs || !*which_jobs ||
+ !_cups_strcasecmp(which_jobs, "not-completed");
+
+ section = cgiGetVariable("SECTION");
+
+ cgiClearVariables();
+
+ if (query)
+ cgiSetVariable("QUERY", query);
+
+ cgiSetVariable("ORDER", ascending ? "asc" : "dec");
+
+ cgiSetVariable("SECTION", section);
+
sprintf(val, "%d", count);
cgiSetVariable("TOTAL", val);
- if ((var = cgiGetVariable("ORDER")) != NULL)
- ascending = !strcasecmp(var, "asc");
- else
- {
- ascending = !which_jobs || !strcasecmp(which_jobs, "not-completed");
- cgiSetVariable("ORDER", ascending ? "asc" : "dec");
- }
+ if (which_jobs)
+ cgiSetVariable("WHICH_JOBS", which_jobs);
if (ascending)
{
*/
if (dest)
- snprintf(val, sizeof(val), "/%s/%s", cgiGetVariable("SECTION"), dest);
+ {
+ snprintf(val, sizeof(val), "/%s/%s", section, dest);
+ cgiSetVariable("PRINTER_NAME", dest);
+ cgiSetVariable("PRINTER_URI_SUPPORTED", val);
+ }
else
strlcpy(val, "/jobs/", sizeof(val));
/*
- * End of "$Id: ipp-var.c 7940 2008-09-16 00:45:16Z mike $".
+ * End of "$Id$".
*/