Skip to content

Commit

Permalink
Fix handling of finishings/finishings-col and media/media-col in ippe…
Browse files Browse the repository at this point in the history
…veprinter.
  • Loading branch information
michaelrsweet committed Dec 18, 2024
1 parent 260d48a commit 61c0c8e
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 27 deletions.
6 changes: 6 additions & 0 deletions cups/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ cups_globals_alloc(void)
*/

cg->thread_id = ++ cups_global_index;

fprintf(stderr, "T%d cups_globals_alloc\n", cg->thread_id);
#endif /* DEBUG */

/*
Expand Down Expand Up @@ -410,6 +412,10 @@ cups_globals_free(_cups_globals_t *cg) /* I - Pointer to global data */
*next; /* Next buffer */


#ifdef DEBUG
fprintf(stderr, "T%d cups_globals_free\n", cg->thread_id);
#endif // DEBUG

if (cg->last_status_message)
_cupsStrFree(cg->last_status_message);

Expand Down
159 changes: 132 additions & 27 deletions tools/ippeveprinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -6112,7 +6112,8 @@ respond_ipp(ippeve_client_t *client, // I - Client
const char *formatted = NULL; // Formatted message


ippSetStatusCode(client->response, status);
if (ippGetStatusCode(client->response) == IPP_STATUS_OK)
ippSetStatusCode(client->response, status);

if (message)
{
Expand Down Expand Up @@ -7063,6 +7064,7 @@ valid_job_attributes(
bool fidelity, // "ipp-attribute-fidelity" value
valid = true; // Valid attributes?
ipp_attribute_t *attr, // Current attribute
*attr_col, // xxx-col attribute
*supported; // xxx-supported attribute


Expand Down Expand Up @@ -7099,6 +7101,97 @@ valid_job_attributes(
}
}

attr_col = ippFindAttribute(client->request, "finishings-col", IPP_TAG_ZERO);

if ((attr = ippFindAttribute(client->request, "finishings", IPP_TAG_ZERO)) != NULL)
{
if (attr_col)
{
// Cannot specify both finishings and finishings-col...
respond_unsupported(client, attr);
respond_unsupported(client, attr_col);
ippSetStatusCode(client->response, IPP_STATUS_ERROR_BAD_REQUEST);
valid = false;
}
else if (ippGetValueTag(attr) != IPP_TAG_ENUM)
{
if (fidelity)
{
respond_unsupported(client, attr);
valid = false;
}
else
{
respond_ignored(client, attr);
ippDeleteAttribute(client->request, attr);
}
}
else
{
supported = ippFindAttribute(client->printer->attrs, "finishings-supported", IPP_TAG_ENUM);

for (i = 0, count = ippGetCount(attr); i < count; i ++)
{
if (!ippContainsInteger(supported, ippGetInteger(attr, i)))
break;
}

if (i < count)
{
if (fidelity)
{
respond_unsupported(client, attr);
valid = false;
}
else
{
respond_ignored(client, attr);
ippDeleteAttribute(client->request, attr);
}
}
}
}
else if (attr_col)
{
if (ippGetValueTag(attr_col) != IPP_TAG_BEGIN_COLLECTION)
{
if (fidelity)
{
respond_unsupported(client, attr_col);
valid = false;
}
else
{
respond_ignored(client, attr_col);
ippDeleteAttribute(client->request, attr_col);
}
}
else
{
supported = ippFindAttribute(client->printer->attrs, "finishing-template-supported", IPP_TAG_ZERO);

for (i = 0, count = ippGetCount(attr_col); i < count; i ++)
{
if (!ippContainsString(supported, ippGetString(ippFindAttribute(ippGetCollection(attr_col, i), "finishing-template", IPP_TAG_ZERO), 0, NULL)))
break;
}

if (i < count)
{
if (fidelity)
{
respond_unsupported(client, attr_col);
valid = false;
}
else
{
respond_ignored(client, attr_col);
ippDeleteAttribute(client->request, attr_col);
}
}
}
}

if ((attr = ippFindAttribute(client->request, "job-hold-until", IPP_TAG_ZERO)) != NULL)
{
if (ippGetCount(attr) != 1 ||
Expand Down Expand Up @@ -7161,12 +7254,20 @@ valid_job_attributes(
}
}

attr_col = ippFindAttribute(client->request, "media-col", IPP_TAG_ZERO);

if ((attr = ippFindAttribute(client->request, "media", IPP_TAG_ZERO)) != NULL)
{
if (ippGetCount(attr) != 1 ||
(ippGetValueTag(attr) != IPP_TAG_NAME &&
ippGetValueTag(attr) != IPP_TAG_NAMELANG &&
ippGetValueTag(attr) != IPP_TAG_KEYWORD))
if (attr_col)
{
// Cannot send both media and media-col in the same request, this is a
// bad request...
respond_unsupported(client, attr);
respond_unsupported(client, attr_col);
ippSetStatusCode(client->response, IPP_STATUS_ERROR_BAD_REQUEST);
valid = false;
}
else if (ippGetCount(attr) != 1 || (ippGetValueTag(attr) != IPP_TAG_NAME && ippGetValueTag(attr) != IPP_TAG_NAMELANG && ippGetValueTag(attr) != IPP_TAG_KEYWORD))
{
respond_unsupported(client, attr);
valid = false;
Expand All @@ -7190,60 +7291,64 @@ valid_job_attributes(
}
}
}

if ((attr = ippFindAttribute(client->request, "media-col", IPP_TAG_ZERO)) != NULL)
else if (attr_col)
{
ipp_t *col, // media-col collection
*size; // media-size collection
ipp_attribute_t *member, // Member attribute
*size_name, // "media-size-name" member attribute
*x_dim, // x-dimension
*y_dim; // y-dimension
int x_value, // y-dimension value
y_value; // x-dimension value

if (ippGetCount(attr) != 1 ||
ippGetValueTag(attr) != IPP_TAG_BEGIN_COLLECTION)
if (ippGetCount(attr_col) != 1 || ippGetValueTag(attr_col) != IPP_TAG_BEGIN_COLLECTION)
{
respond_unsupported(client, attr);
respond_unsupported(client, attr_col);
valid = false;
}

col = ippGetCollection(attr, 0);
col = ippGetCollection(attr_col, 0);

if ((member = ippFindAttribute(col, "media-size-name", IPP_TAG_ZERO)) != NULL)
member = ippFindAttribute(col, "media-size", IPP_TAG_BEGIN_COLLECTION);
if ((size_name = ippFindAttribute(col, "media-size-name", IPP_TAG_ZERO)) != NULL)
{
if (ippGetCount(member) != 1 ||
(ippGetValueTag(member) != IPP_TAG_NAME &&
ippGetValueTag(member) != IPP_TAG_NAMELANG &&
ippGetValueTag(member) != IPP_TAG_KEYWORD))
if (member)
{
respond_unsupported(client, attr);
// Cannot specify both media-size and media-size-name...
respond_unsupported(client, attr_col);
ippSetStatusCode(client->response, IPP_STATUS_ERROR_BAD_REQUEST);
valid = false;
}
else if (ippGetCount(size_name) != 1 || (ippGetValueTag(size_name) != IPP_TAG_NAME && ippGetValueTag(size_name) != IPP_TAG_NAMELANG && ippGetValueTag(size_name) != IPP_TAG_KEYWORD))
{
respond_unsupported(client, attr_col);
valid = false;
}
else
{
supported = ippFindAttribute(client->printer->attrs, "media-supported", IPP_TAG_KEYWORD);

if (!ippContainsString(supported, ippGetString(member, 0, NULL)))
if (!ippContainsString(supported, ippGetString(size_name, 0, NULL)))
{
if (fidelity)
{
respond_unsupported(client, attr);
respond_unsupported(client, attr_col);
valid = false;
}
else
{
respond_ignored(client, attr);
ippDeleteAttribute(client->request, attr);
respond_ignored(client, attr_col);
ippDeleteAttribute(client->request, attr_col);
}
}
}
}
else if ((member = ippFindAttribute(col, "media-size", IPP_TAG_BEGIN_COLLECTION)) != NULL)
else if (member)
{
if (ippGetCount(member) != 1)
{
respond_unsupported(client, attr);
respond_unsupported(client, attr_col);
valid = false;
}
else
Expand All @@ -7253,7 +7358,7 @@ valid_job_attributes(
if ((x_dim = ippFindAttribute(size, "x-dimension", IPP_TAG_INTEGER)) == NULL || ippGetCount(x_dim) != 1 ||
(y_dim = ippFindAttribute(size, "y-dimension", IPP_TAG_INTEGER)) == NULL || ippGetCount(y_dim) != 1)
{
respond_unsupported(client, attr);
respond_unsupported(client, attr_col);
valid = false;
}
else
Expand Down Expand Up @@ -7300,13 +7405,13 @@ valid_job_attributes(
{
if (fidelity)
{
respond_unsupported(client, attr);
respond_unsupported(client, attr_col);
valid = false;
}
else
{
respond_ignored(client, attr);
ippDeleteAttribute(client->request, attr);
respond_ignored(client, attr_col);
ippDeleteAttribute(client->request, attr_col);
}
}
}
Expand Down

0 comments on commit 61c0c8e

Please sign in to comment.