Skip to content

Commit

Permalink
Fix support for vendor text options (Issue #142)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Oct 8, 2022
1 parent 8332773 commit eea079f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes in v1.2.3

- Fixed a bug in the TLS upgrade logic.
- Fixed a potential memory underflow with USB device IDs.
- Fixed web interface support for vendor text options (Issue #142)


Changes in v1.2.2
Expand Down
32 changes: 19 additions & 13 deletions pappl/printer-webif.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,24 +665,25 @@ _papplPrinterWebDefaults(
char defname[128], // xxx-default name
defvalue[1024], // xxx-default value
supname[128]; // xxx-supported name
ipp_attribute_t *attr; // Attribute
ipp_attribute_t *defattr, // Default attribute
*supattr; // Supported attribute
int count; // Number of values

snprintf(defname, sizeof(defname), "%s-default", data.vendor[i]);
snprintf(supname, sizeof(defname), "%s-supported", data.vendor[i]);

if ((attr = ippFindAttribute(printer->driver_attrs, defname, IPP_TAG_ZERO)) != NULL)
ippAttributeString(attr, defvalue, sizeof(defvalue));
if ((defattr = ippFindAttribute(printer->driver_attrs, defname, IPP_TAG_ZERO)) != NULL)
ippAttributeString(defattr, defvalue, sizeof(defvalue));
else
defvalue[0] = '\0';

if ((attr = ippFindAttribute(printer->driver_attrs, supname, IPP_TAG_ZERO)) != NULL)
{
count = (int)ippGetCount(attr);
papplClientHTMLPrintf(client, " <tr><th>%s:</th><td>", papplClientGetLocString(client, data.vendor[i]));

papplClientHTMLPrintf(client, " <tr><th>%s:</th><td>", papplClientGetLocString(client, data.vendor[i]));
if ((supattr = ippFindAttribute(printer->driver_attrs, supname, IPP_TAG_ZERO)) != NULL)
{
count = (int)ippGetCount(supattr);

switch (ippGetValueTag(attr))
switch (ippGetValueTag(supattr))
{
case IPP_TAG_BOOLEAN :
papplClientHTMLPrintf(client, "<input type=\"checkbox\" name=\"%s\"%s>", data.vendor[i], !strcmp(defvalue, "true") ? " checked" : "");
Expand All @@ -692,7 +693,7 @@ _papplPrinterWebDefaults(
papplClientHTMLPrintf(client, "<select name=\"%s\">", data.vendor[i]);
for (j = 0; j < count; j ++)
{
int val = ippGetInteger(attr, (cups_len_t)j);
int val = ippGetInteger(supattr, (cups_len_t)j);

papplClientHTMLPrintf(client, "<option value=\"%d\"%s>%d</option>", val, val == (int)strtol(defvalue, NULL, 10) ? " selected" : "", val);
}
Expand All @@ -701,7 +702,7 @@ _papplPrinterWebDefaults(

case IPP_TAG_RANGE :
{
int upper, lower = ippGetRange(attr, 0, &upper);
int upper, lower = ippGetRange(supattr, 0, &upper);
// Range

papplClientHTMLPrintf(client, "<input type=\"number\" name=\"%s\" min=\"%d\" max=\"%d\" value=\"%s\">", data.vendor[i], lower, upper, defvalue);
Expand All @@ -712,7 +713,7 @@ _papplPrinterWebDefaults(
papplClientHTMLPrintf(client, "<select name=\"%s\">", data.vendor[i]);
for (j = 0; j < count; j ++)
{
const char *val = ippGetString(attr, (cups_len_t)j, NULL);
const char *val = ippGetString(supattr, (cups_len_t)j, NULL);

papplClientHTMLPrintf(client, "<option value=\"%s\"%s>%s</option>", val, !strcmp(val, defvalue) ? " selected" : "", localize_keyword(client, data.vendor[i], val, text, sizeof(text)));
}
Expand All @@ -723,9 +724,14 @@ _papplPrinterWebDefaults(
papplClientHTMLPuts(client, "Unsupported value syntax.");
break;
}

papplClientHTMLPuts(client, "</td></tr>\n");
}
else
{
// Text option
papplClientHTMLPrintf(client, "<input type=\"text\" name=\"%s\" value=\"%s\">", data.vendor[i], defvalue);
}

papplClientHTMLPuts(client, "</td></tr>\n");
}

pthread_rwlock_unlock(&printer->rwlock);
Expand Down

0 comments on commit eea079f

Please sign in to comment.