/*
* IPP backend for CUPS.
*
- * Copyright 2007-2016 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
static ipp_pstate_t check_printer_state(http_t *http, const char *uri,
const char *resource,
const char *user, int version);
+static void debug_attributes(ipp_t *ipp);
static void *monitor_printer(_cups_monitor_t *monitor);
static ipp_t *new_request(ipp_op_t op, int version, const char *uri,
const char *user, const char *title,
*compatfile = NULL; /* Compatibility filename */
off_t compatsize = 0; /* Size of compatibility file */
int port; /* Port number (not used) */
- char portname[255]; /* Port name */
char uri[HTTP_MAX_URI]; /* Updated URI without user/pass */
char print_job_name[1024]; /* Update job-name for Print-Job */
http_status_t http_status; /* Status of HTTP request */
start_time = time(NULL);
- sprintf(portname, "%d", port);
-
- update_reasons(NULL, "+connecting-to-device");
- fprintf(stderr, "DEBUG: Looking up \"%s\"...\n", hostname);
-
- while ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL)
- {
- _cupsLangPrintFilter(stderr, "INFO",
- _("Unable to locate printer \"%s\"."), hostname);
- sleep(10);
-
- if (getenv("CLASS") != NULL)
- {
- update_reasons(NULL, "-connecting-to-device");
- return (CUPS_BACKEND_STOP);
- }
-
- if (job_canceled)
- return (CUPS_BACKEND_OK);
- }
+ addrlist = backendLookup(hostname, port, &job_canceled);
http = httpConnect2(hostname, port, addrlist, AF_UNSPEC, cupsEncryption(), 1,
0, NULL);
trust = httpCredentialsGetTrust(creds, hostname);
httpCredentialsString(creds, credinfo, sizeof(credinfo));
- fprintf(stderr, "DEBUG: %s\n", trust_msgs[trust]);
+ fprintf(stderr, "DEBUG: %s (%s)\n", trust_msgs[trust], cupsLastErrorString());
fprintf(stderr, "DEBUG: Printer credentials: %s\n", credinfo);
if (!httpLoadCredentials(NULL, &lcreds, hostname))
while (!job_canceled && validate_job)
{
- request = new_request(IPP_VALIDATE_JOB, version, uri, argv[2],
+ request = new_request(IPP_OP_VALIDATE_JOB, version, uri, argv[2],
monitor.job_name, num_options, options, compression,
copies_sup ? copies : 1, document_format, pc, ppd,
media_col_sup, doc_handling_sup, print_color_mode_sup);
fprintf(stderr, "DEBUG: Validate-Job: %s (%s)\n",
ippErrorString(ipp_status), cupsLastErrorString());
+ debug_attributes(response);
if ((job_auth = ippFindAttribute(response, "job-authorization-uri",
IPP_TAG_URI)) != NULL)
else if (ipp_status < IPP_REDIRECTION_OTHER_SITE ||
ipp_status == IPP_BAD_REQUEST)
break;
+ else if (job_auth == NULL && ipp_status > IPP_BAD_REQUEST)
+ goto cleanup;
}
/*
fprintf(stderr, "DEBUG: %s: %s (%s)\n",
(num_files > 1 || create_job) ? "Create-Job" : "Print-Job",
ippErrorString(ipp_status), cupsLastErrorString());
+ debug_attributes(response);
if (ipp_status > IPP_OK_CONFLICT)
{
"compression", NULL, compression);
fprintf(stderr, "DEBUG: Sending file %d using chunking...\n", i + 1);
+ fprintf(stderr, "DEBUG: IPP/%d.%d %s #%d\n", version / 10, version % 10, ippOpString(ippGetOperation(request)), ippGetRequestId(request));
+ debug_attributes(request);
+
http_status = cupsSendRequest(http, request, resource, 0);
if (http_status == HTTP_CONTINUE && request->state == IPP_DATA)
{
fprintf(stderr, "DEBUG: Error writing document data for "
"Send-Document: %s\n", strerror(httpError(http)));
- ippDelete(cupsGetResponse(http, resource));
+ response = cupsGetResponse(http, resource);
ippDelete(request);
fprintf(stderr, "DEBUG: Send-Document: %s (%s)\n",
ippErrorString(cupsLastError()), cupsLastErrorString());
+ debug_attributes(response);
+ ippDelete(response);
if (cupsLastError() > IPP_OK_CONFLICT && !job_canceled)
{
"requested-attributes", sizeof(jattrs) / sizeof(jattrs[0]),
NULL, jattrs);
+ fprintf(stderr, "DEBUG: IPP/%d.%d %s #%d\n", version / 10, version % 10, ippOpString(ippGetOperation(request)), ippGetRequestId(request));
+ debug_attributes(request);
+
/*
* Do the request...
*/
fprintf(stderr, "DEBUG: Get-Job-Attributes: %s (%s)\n",
ippErrorString(ipp_status), cupsLastErrorString());
+ debug_attributes(response);
if (ipp_status <= IPP_OK_CONFLICT)
password_tries = 0;
return (CUPS_BACKEND_HOLD);
else if (ipp_status == IPP_INTERNAL_ERROR)
return (CUPS_BACKEND_STOP);
- else if (ipp_status == IPP_CONFLICT)
+ else if (ipp_status == IPP_CONFLICT || ipp_status == IPP_STATUS_ERROR_REQUEST_ENTITY || ipp_status == IPP_STATUS_ERROR_REQUEST_VALUE)
return (CUPS_BACKEND_FAILED);
else if (ipp_status == IPP_REQUEST_VALUE ||
ipp_status == IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES ||
"requested-attributes",
(int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
+ fprintf(stderr, "DEBUG: IPP/%d.%d %s #%d\n", version / 10, version % 10, ippOpString(ippGetOperation(request)), ippGetRequestId(request));
+ debug_attributes(request);
+
if ((response = cupsDoRequest(http, request, resource)) != NULL)
{
report_printer_state(response);
if ((attr = ippFindAttribute(response, "printer-state",
IPP_TAG_ENUM)) != NULL)
printer_state = (ipp_pstate_t)attr->values[0].integer;
-
- ippDelete(response);
}
fprintf(stderr, "DEBUG: Get-Printer-Attributes: %s (%s)\n",
ippErrorString(cupsLastError()), cupsLastErrorString());
+ debug_attributes(response);
+ ippDelete(response);
/*
* Return the printer-state value...
}
+/*
+ * 'debug_attributes()' - Print out the request or response attributes as DEBUG
+ * messages...
+ */
+
+static void
+debug_attributes(ipp_t *ipp) /* I - Request or response message */
+{
+ ipp_tag_t group; /* Current group */
+ ipp_attribute_t *attr; /* Current attribute */
+ char buffer[1024]; /* Value buffer */
+
+
+ for (group = IPP_TAG_ZERO, attr = ippFirstAttribute(ipp);
+ attr;
+ attr = ippNextAttribute(ipp))
+ {
+ const char *name = ippGetName(attr);
+
+ if (!name)
+ {
+ group = IPP_TAG_ZERO;
+ continue;
+ }
+
+ if (group != ippGetGroupTag(attr))
+ {
+ group = ippGetGroupTag(attr);
+ fprintf(stderr, "DEBUG: ---- %s ----\n", ippTagString(group));
+ }
+
+ if (!strcmp(name, "job-password"))
+ strlcpy(buffer, "---", sizeof(buffer));
+ else
+ ippAttributeString(attr, buffer, sizeof(buffer));
+
+ fprintf(stderr, "DEBUG: %s %s%s %s\n", name,
+ ippGetCount(attr) > 1 ? "1setOf " : "",
+ ippTagString(ippGetValueTag(attr)), buffer);
+ }
+
+ fprintf(stderr, "DEBUG: ---- %s ----\n", ippTagString(IPP_TAG_END));
+}
+
+
/*
* 'monitor_printer()' - Monitor the printer state.
*/
while (monitor->job_state < IPP_JOB_CANCELED && !job_canceled)
{
/*
- * Reconnect to the printer...
+ * Reconnect to the printer as needed...
*/
- if (!httpReconnect(http))
+ if (httpGetFd(http) < 0)
+ httpReconnect(http);
+
+ if (httpGetFd(http) >= 0)
{
/*
* Connected, so check on the printer state...
* No job-id yet, so continue...
*/
- goto monitor_disconnect;
+ goto monitor_sleep;
}
/*
(monitor->job_state == IPP_JOB_CANCELED ||
monitor->job_state == IPP_JOB_ABORTED))
job_canceled = -1;
-
- /*
- * Disconnect from the printer - we'll reconnect on the next poll...
- */
-
- monitor_disconnect:
-
- _httpDisconnect(http);
}
/*
* Sleep for N seconds...
*/
+ monitor_sleep:
+
sleep((unsigned)delay);
delay = _cupsNextDelay(delay, &prev_delay);
if (job_canceled > 0 && monitor->job_id > 0)
{
- if (!httpReconnect(http))
+ if (httpGetFd(http) < 0)
+ httpReconnect(http);
+
+ if (httpGetFd(http) >= 0)
{
cancel_job(http, monitor->uri, monitor->job_id, monitor->resource,
monitor->user, monitor->version);
{
ipp_t *request; /* Request data */
const char *keyword; /* PWG keyword */
- ipp_tag_t group; /* Current group */
- ipp_attribute_t *attr; /* Current attribute */
- char buffer[1024]; /* Value buffer */
/*
ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_INTEGER, "copies", copies);
}
- fprintf(stderr, "DEBUG: IPP/%d.%d %s #%d\n", version / 10, version % 10,
- ippOpString(ippGetOperation(request)), ippGetRequestId(request));
- for (group = IPP_TAG_ZERO, attr = ippFirstAttribute(request);
- attr;
- attr = ippNextAttribute(request))
- {
- const char *name = ippGetName(attr);
-
- if (!name)
- {
- group = IPP_TAG_ZERO;
- continue;
- }
-
- if (group != ippGetGroupTag(attr))
- {
- group = ippGetGroupTag(attr);
- fprintf(stderr, "DEBUG: ---- %s ----\n", ippTagString(group));
- }
-
- ippAttributeString(attr, buffer, sizeof(buffer));
- fprintf(stderr, "DEBUG: %s %s%s %s\n", name,
- ippGetCount(attr) > 1 ? "1setOf " : "",
- ippTagString(ippGetValueTag(attr)), buffer);
- }
-
- fprintf(stderr, "DEBUG: ---- %s ----\n", ippTagString(IPP_TAG_END));
+ fprintf(stderr, "DEBUG: IPP/%d.%d %s #%d\n", version / 10, version % 10, ippOpString(ippGetOperation(request)), ippGetRequestId(request));
+ debug_attributes(request);
return (request);
}