/*
- * "$Id$"
- *
* Sample IPP Everywhere server for CUPS.
*
- * Copyright 2010-2015 by Apple Inc.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Copyright © 2010-2018 by Apple Inc.
*
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*/
/*
#endif /* HAVE_DNSSD */
static int KeepFiles = 0,
+ MaxVersion = 20,
Verbosity = 0;
pin = 1;
break;
+ case 'V' : /* -V max-version */
+ i ++;
+ if (i >= argc)
+ usage(1);
+
+ if (!strcmp(argv[i], "2.2"))
+ MaxVersion = 22;
+ else if (!strcmp(argv[i], "2.1"))
+ MaxVersion = 21;
+ else if (!strcmp(argv[i], "2.0"))
+ MaxVersion = 20;
+ else if (!strcmp(argv[i], "1.1"))
+ MaxVersion = 11;
+ else
+ usage(1);
+ break;
+
case 'a' : /* -a attributes-file */
i ++;
if (i >= argc)
#ifdef WIN32
if ((tmpdir = getenv("TEMP")) == NULL)
tmpdir = "C:/TEMP";
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) && !TARGET_OS_IOS
if ((tmpdir = getenv("TMPDIR")) == NULL)
tmpdir = "/private/tmp";
#else
* Only accept a single job at a time...
*/
- _cupsRWLockWrite(&(client->printer->rwlock));
+ _cupsRWUnlock(&(client->printer->rwlock));
return (NULL);
}
ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL, uri);
ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-uuid", NULL, uuid);
- ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", NULL, client->printer->uri);
+ if ((attr = ippFindAttribute(client->request, "printer-uri", IPP_TAG_URI)) != NULL)
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", NULL, ippGetString(attr, 0, NULL));
+ else
+ ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_URI, "job-printer-uri", NULL, client->printer->uri);
ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation", (int)(job->created - client->printer->start_time));
cupsArrayAdd(client->printer->jobs, job);
};
static const char * const versions[] =/* ipp-versions-supported values */
{
- "1.0",
"1.1",
- "2.0"
+ "2.0",
+ "2.1",
+ "2.2"
};
static const char * const features[] =/* ipp-features-supported values */
{
/* ipp-versions-supported */
if (!ippFindAttribute(printer->attrs, "ipp-versions-supported", IPP_TAG_ZERO))
- ippAddStrings(printer->attrs, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_KEYWORD), "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]), NULL, versions);
+ {
+ int num_versions = MaxVersion == 11 ? 1 : MaxVersion == 20 ? 2 : MaxVersion == 21 ? 3 : 4;
+ /* Number of supported versions */
+
+ ippAddStrings(printer->attrs, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_KEYWORD), "ipp-versions-supported", num_versions, NULL, versions);
+ }
/* job-account-id-default */
if (!ippFindAttribute(printer->attrs, "job-account-id-default", IPP_TAG_ZERO))
if (!ippFindAttribute(printer->attrs, "job-password-supported", IPP_TAG_ZERO))
ippAddInteger(printer->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "job-password-supported", 4);
- /* job-preferred-attributes-supported */
- ippAddBoolean(printer->attrs, IPP_TAG_PRINTER, "job-preferred-attributes-supported", 0);
-
/* job-priority-default */
if (!ippFindAttribute(printer->attrs, "job-priority-default", IPP_TAG_ZERO))
ippAddInteger(printer->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "job-priority-default", 50);
if (!ippFindAttribute(printer->attrs, "pdl-override-supported", IPP_TAG_ZERO))
ippAddString(printer->attrs, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_KEYWORD), "pdl-override-supported", NULL, "attempted");
+ /* preferred-attributes-supported */
+ ippAddBoolean(printer->attrs, IPP_TAG_PRINTER, "preferred-attributes-supported", 0);
+
/* print-color-mode-default */
if (!ippFindAttribute(printer->attrs, "print-color-mode-default", IPP_TAG_ZERO))
ippAddString(printer->attrs, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_KEYWORD), "print-color-mode-default", NULL, "auto");
{
if (printer->state_reasons & bit)
{
- snprintf(reason, sizeof(reason), "%s-%s", _ipp_preason_strings[0], printer->state == IPP_PSTATE_IDLE ? "report" : printer->state == IPP_PSTATE_PROCESSING ? "warning" : "error");
+ snprintf(reason, sizeof(reason), "%s-%s", _ipp_preason_strings[i], printer->state == IPP_PSTATE_IDLE ? "report" : printer->state == IPP_PSTATE_PROCESSING ? "warning" : "error");
if (attr)
ippSetString(client->response, &attr, ippGetCount(attr), reason);
else
buffer[4096]; /* Copy buffer */
ssize_t bytes; /* Bytes read */
cups_array_t *ra; /* Attributes to send in response */
+ _cups_thread_t t; /* Thread */
/*
* Process the job...
*/
- if (!_cupsThreadCreate((_cups_thread_func_t)process_job, job))
+ t = _cupsThreadCreate((_cups_thread_func_t)process_job, job);
+
+ if (t)
+ {
+ _cupsThreadDetach(t);
+ }
+ else
{
job->state = IPP_JSTATE_ABORTED;
respond_ipp(client, IPP_STATUS_ERROR_INTERNAL, "Unable to process job.");
* Process the job...
*/
-#if 0
- if (!_cupsThreadCreate((_cups_thread_func_t)process_job, job))
- {
- job->state = IPP_JSTATE_ABORTED;
- respond_ipp(client, IPP_STATUS_ERROR_INTERNAL, "Unable to process job.");
- return;
- }
-
-#else
process_job(job);
-#endif /* 0 */
/*
* Return the job info...
* Process the job...
*/
-#if 0
- if (!_cupsThreadCreate((_cups_thread_func_t)process_job, job))
- {
- job->state = IPP_JSTATE_ABORTED;
- respond_ipp(client, IPP_STATUS_ERROR_INTERNAL, "Unable to process job.");
- return;
- }
-
-#else
process_job(job);
-#endif /* 0 */
/*
* Return the job info...
* Process the job...
*/
-#if 0
- if (!_cupsThreadCreate((_cups_thread_func_t)process_job, job))
- {
- job->state = IPP_JSTATE_ABORTED;
- respond_ipp(client, IPP_STATUS_ERROR_INTERNAL, "Unable to process job.");
- return;
- }
-
-#else
process_job(job);
-#endif /* 0 */
/*
* Return the job info...
break;
ippSetCollection(attrs, &attrptr, ippGetCount(attrptr), col);
- lastcol = attrptr;
}
while (!strcmp(token, "{"));
break;
* Return an error, since we only support IPP 1.x and 2.x.
*/
- respond_ipp(client, IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED,
- "Bad request version number %d.%d.", major, minor);
+ respond_ipp(client, IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED, "Bad request version number %d.%d.", major, minor);
+ }
+ else if ((major * 10 + minor) > MaxVersion)
+ {
+ if (httpGetState(client->http) != HTTP_STATE_POST_SEND)
+ httpFlush(client->http); /* Flush trailing (junk) data */
+
+ respond_http(client, HTTP_STATUS_BAD_REQUEST, NULL, NULL, 0);
+ return (0);
}
else if (ippGetRequestId(client->request) <= 0)
- respond_ipp(client, IPP_STATUS_ERROR_BAD_REQUEST, "Bad request-id %d.",
- ippGetRequestId(client->request));
+ {
+ respond_ipp(client, IPP_STATUS_ERROR_BAD_REQUEST, "Bad request-id %d.", ippGetRequestId(client->request));
+ }
else if (!ippFirstAttribute(client->request))
- respond_ipp(client, IPP_STATUS_ERROR_BAD_REQUEST,
- "No attributes in request.");
+ {
+ respond_ipp(client, IPP_STATUS_ERROR_BAD_REQUEST, "No attributes in request.");
+ }
else
{
/*
{
if ((client = create_client(printer, printer->ipv4)) != NULL)
{
- if (!_cupsThreadCreate((_cups_thread_func_t)process_client, client))
+ _cups_thread_t t = _cupsThreadCreate((_cups_thread_func_t)process_client, client);
+
+ if (t)
+ {
+ _cupsThreadDetach(t);
+ }
+ else
{
perror("Unable to create client thread");
delete_client(client);
{
if ((client = create_client(printer, printer->ipv6)) != NULL)
{
- if (!_cupsThreadCreate((_cups_thread_func_t)process_client, client))
+ _cups_thread_t t = _cupsThreadCreate((_cups_thread_func_t)process_client, client);
+
+ if (t)
+ {
+ _cupsThreadDetach(t);
+ }
+ else
{
perror("Unable to create client thread");
delete_client(client);
{
if (!status)
{
- puts(CUPS_SVERSION " - Copyright 2010-2015 by Apple Inc. All rights "
- "reserved.");
+ puts(CUPS_SVERSION " - Copyright (c) 2010-2018 by Apple Inc. All rights reserved.");
puts("");
}
puts("-2 Supports 2-sided printing (default=1-sided)");
puts("-M manufacturer Manufacturer name (default=Test)");
puts("-P PIN printing mode");
+ puts("-V max-version Set maximum supported IPP version");
puts("-a attributes-file Load printer attributes from file");
puts("-c command Run command for every print job");
printf("-d spool-directory Spool directory "
attr = ippAddString(client->request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, format);
}
- if (!strcmp(format, "application/octet-stream") && (ippGetOperation(client->request) == IPP_OP_PRINT_JOB || ippGetOperation(client->request) == IPP_OP_SEND_DOCUMENT))
+ if (format && !strcmp(format, "application/octet-stream") && (ippGetOperation(client->request) == IPP_OP_PRINT_JOB || ippGetOperation(client->request) == IPP_OP_SEND_DOCUMENT))
{
/*
* Auto-type the file using the first 8 bytes of the file...
return (valid);
}
-
-
-/*
- * End of "$Id$".
- */