Skip to content

Commit

Permalink
PPDize preset and template names.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Sep 9, 2024
1 parent 04bb2af commit e0630cd
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions cups/ppd-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -4975,12 +4975,14 @@ _ppdCreateFromIPP2(

cupsArrayAdd(templates, (void *)keyword);

pwg_ppdize_name(keyword, ppdname, sizeof(ppdname));

snprintf(msgid, sizeof(msgid), "finishing-template.%s", keyword);
if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr))
if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid)
msgstr = keyword;

cupsFilePrintf(fp, "*cupsFinishingTemplate %s: \"\n", keyword);
cupsFilePrintf(fp, "*cupsFinishingTemplate %s: \"\n", ppdname);
for (finishing_attr = ippFirstAttribute(finishing_col); finishing_attr; finishing_attr = ippNextAttribute(finishing_col))
{
if (ippGetValueTag(finishing_attr) == IPP_TAG_BEGIN_COLLECTION)
Expand All @@ -4993,7 +4995,7 @@ _ppdCreateFromIPP2(
}
}
cupsFilePuts(fp, "\"\n");
cupsFilePrintf(fp, "*%s.cupsFinishingTemplate %s/%s: \"\"\n", lang->language, keyword, msgstr);
cupsFilePrintf(fp, "*%s.cupsFinishingTemplate %s/%s: \"\"\n", lang->language, ppdname, msgstr);
cupsFilePuts(fp, "*End\n");
}

Expand Down Expand Up @@ -5039,7 +5041,8 @@ _ppdCreateFromIPP2(
if (!preset || !preset_name)
continue;

cupsFilePrintf(fp, "*APPrinterPreset %s: \"\n", preset_name);
pwg_ppdize_name(preset_name, ppdname, sizeof(ppdname));
cupsFilePrintf(fp, "*APPrinterPreset %s: \"\n", ppdname);
for (member = ippFirstAttribute(preset); member; member = ippNextAttribute(preset))
{
member_name = ippGetName(member);
Expand Down Expand Up @@ -5080,7 +5083,10 @@ _ppdCreateFromIPP2(
fin_col = ippGetCollection(member, i);

if ((keyword = ippGetString(ippFindAttribute(fin_col, "finishing-template", IPP_TAG_ZERO), 0, NULL)) != NULL)
cupsFilePrintf(fp, "*cupsFinishingTemplate %s\n", keyword);
{
pwg_ppdize_name(keyword, ppdname, sizeof(ppdname));
cupsFilePrintf(fp, "*cupsFinishingTemplate %s\n", ppdname);
}
}
}
else if (!strcmp(member_name, "media"))
Expand All @@ -5107,13 +5113,13 @@ _ppdCreateFromIPP2(
if ((keyword = ippGetString(ippFindAttribute(media_col, "media-source", IPP_TAG_ZERO), 0, NULL)) != NULL)
{
pwg_ppdize_name(keyword, ppdname, sizeof(ppdname));
cupsFilePrintf(fp, "*InputSlot %s\n", keyword);
cupsFilePrintf(fp, "*InputSlot %s\n", ppdname);
}

if ((keyword = ippGetString(ippFindAttribute(media_col, "media-type", IPP_TAG_ZERO), 0, NULL)) != NULL)
{
pwg_ppdize_name(keyword, ppdname, sizeof(ppdname));
cupsFilePrintf(fp, "*MediaType %s\n", keyword);
cupsFilePrintf(fp, "*MediaType %s\n", ppdname);
}
}
else if (!strcmp(member_name, "print-quality"))
Expand Down Expand Up @@ -5159,7 +5165,10 @@ _ppdCreateFromIPP2(
cupsFilePuts(fp, "\"\n*End\n");

if ((localized_name = _cupsMessageLookup(strings, preset_name)) != preset_name)
cupsFilePrintf(fp, "*%s.APPrinterPreset %s/%s: \"\"\n", lang->language, preset_name, localized_name);
{
pwg_ppdize_name(preset_name, ppdname, sizeof(ppdname));
cupsFilePrintf(fp, "*%s.APPrinterPreset %s/%s: \"\"\n", lang->language, ppdname, localized_name);
}
}
}

Expand Down Expand Up @@ -5543,7 +5552,7 @@ pwg_ppdize_name(const char *ipp, /* I - IPP keyword */
*end; /* End of name buffer */


if (!ipp)
if (!ipp || !_cups_isalnum(*ipp))
{
*name = '\0';
return;
Expand All @@ -5558,8 +5567,14 @@ pwg_ppdize_name(const char *ipp, /* I - IPP keyword */
ipp ++;
*ptr++ = (char)toupper(*ipp++ & 255);
}
else
else if (*ipp == '_' || *ipp == '.' || *ipp == '-' || _cups_isalnum(*ipp))
{
*ptr++ = *ipp++;
}
else
{
ipp ++;
}
}

*ptr = '\0';
Expand Down

0 comments on commit e0630cd

Please sign in to comment.