Skip to content

Commit 1e6ca59

Browse files
committed
Quote PPD localized strings.
1 parent 97a2c17 commit 1e6ca59

1 file changed

Lines changed: 53 additions & 40 deletions

File tree

cups/ppd-cache.c

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
static int cups_connect(http_t **http, const char *url, char *resource, size_t ressize);
3333
static int cups_get_url(http_t **http, const char *url, char *name, size_t namesize);
3434
static const char *ppd_inputslot_for_keyword(_ppd_cache_t *pc, const char *keyword);
35+
static void ppd_put_string(cups_file_t *fp, cups_lang_t *lang, cups_array_t *strings, const char *ppd_option, const char *ppd_choice, const char *pwg_msgid);
3536
static void pwg_add_finishing(cups_array_t *finishings, ipp_finishings_t template, const char *name, const char *value);
3637
static void pwg_add_message(cups_array_t *a, const char *msg, const char *str);
3738
static int pwg_compare_finishings(_pwg_finishings_t *a, _pwg_finishings_t *b);
@@ -3393,7 +3394,7 @@ _ppdCreateFromIPP2(
33933394
if ((attr = ippFindAttribute(supported, "printer-charge-info-uri", IPP_TAG_URI)) != NULL && ippValidateAttribute(attr))
33943395
cupsFilePrintf(fp, "*cupsChargeInfoURI: \"%s\"\n", ippGetString(attr, 0, NULL));
33953396

3396-
if ((attr = ippFindAttribute(supported, "printer-strings-uri", IPP_TAG_URI)) != NULL)
3397+
if ((attr = ippFindAttribute(supported, "printer-strings-uri", IPP_TAG_URI)) != NULL && ippValidateAttribute(attr))
33973398
{
33983399
http_t *http = NULL; /* Connection to printer */
33993400
char stringsfile[1024]; /* Temporary strings file */
@@ -3437,7 +3438,7 @@ _ppdCreateFromIPP2(
34373438

34383439
response = cupsDoRequest(http, request, resource);
34393440

3440-
if ((attr = ippFindAttribute(response, "printer-strings-uri", IPP_TAG_URI)) != NULL)
3441+
if ((attr = ippFindAttribute(response, "printer-strings-uri", IPP_TAG_URI)) != NULL && ippValidateAttribute(attr))
34413442
cupsFilePrintf(fp, "*cupsStringsURI %s: \"%s\"\n", keyword, ippGetString(attr, 0, NULL));
34423443

34433444
ippDelete(response);
@@ -4043,18 +4044,16 @@ _ppdCreateFromIPP2(
40434044
cupsFilePrintf(fp, "*DefaultInputSlot: %s\n", ppdname);
40444045

40454046
for (j = 0; j < (int)(sizeof(sources) / sizeof(sources[0])); j ++)
4047+
{
40464048
if (!strcmp(sources[j], keyword))
40474049
{
40484050
snprintf(msgid, sizeof(msgid), "media-source.%s", keyword);
40494051

4050-
if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr))
4051-
if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid)
4052-
msgstr = keyword;
4053-
40544052
cupsFilePrintf(fp, "*InputSlot %s: \"<</MediaPosition %d>>setpagedevice\"\n", ppdname, j);
4055-
cupsFilePrintf(fp, "*%s.InputSlot %s/%s: \"\"\n", lang->language, ppdname, msgstr);
4053+
ppd_put_string(fp, lang, strings, "InputSlot", ppdname, msgid);
40564054
break;
40574055
}
4056+
}
40584057
}
40594058
cupsFilePuts(fp, "*CloseUI: *InputSlot\n");
40604059
}
@@ -4080,12 +4079,9 @@ _ppdCreateFromIPP2(
40804079
pwg_ppdize_name(keyword, ppdname, sizeof(ppdname));
40814080

40824081
snprintf(msgid, sizeof(msgid), "media-type.%s", keyword);
4083-
if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr))
4084-
if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid)
4085-
msgstr = keyword;
40864082

40874083
cupsFilePrintf(fp, "*MediaType %s: \"<</MediaType(%s)>>setpagedevice\"\n", ppdname, ppdname);
4088-
cupsFilePrintf(fp, "*%s.MediaType %s/%s: \"\"\n", lang->language, ppdname, msgstr);
4084+
ppd_put_string(fp, lang, strings, "MediaType", ppdname, msgid);
40894085
}
40904086
cupsFilePuts(fp, "*CloseUI: *MediaType\n");
40914087
}
@@ -4546,12 +4542,9 @@ _ppdCreateFromIPP2(
45464542
pwg_ppdize_name(keyword, ppdname, sizeof(ppdname));
45474543

45484544
snprintf(msgid, sizeof(msgid), "output-bin.%s", keyword);
4549-
if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr))
4550-
if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid)
4551-
msgstr = keyword;
45524545

45534546
cupsFilePrintf(fp, "*OutputBin %s: \"\"\n", ppdname);
4554-
cupsFilePrintf(fp, "*%s.OutputBin %s/%s: \"\"\n", lang->language, ppdname, msgstr);
4547+
ppd_put_string(fp, lang, strings, "OutputBin", ppdname, msgid);
45554548

45564549
if ((tray_ptr = ippGetOctetString(trays, i, &tray_len)) != NULL)
45574550
{
@@ -4670,9 +4663,6 @@ _ppdCreateFromIPP2(
46704663
cupsArrayAdd(names, (char *)keyword);
46714664

46724665
snprintf(msgid, sizeof(msgid), "finishings.%d", value);
4673-
if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr))
4674-
if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid)
4675-
msgstr = keyword;
46764666

46774667
if (value >= IPP_FINISHINGS_NONE && value <= IPP_FINISHINGS_LAMINATE)
46784668
ppd_keyword = base_keywords[value - IPP_FINISHINGS_NONE];
@@ -4687,7 +4677,7 @@ _ppdCreateFromIPP2(
46874677
continue;
46884678

46894679
cupsFilePrintf(fp, "*StapleLocation %s: \"\"\n", ppd_keyword);
4690-
cupsFilePrintf(fp, "*%s.StapleLocation %s/%s: \"\"\n", lang->language, ppd_keyword, msgstr);
4680+
ppd_put_string(fp, lang, strings, "StapleLocation", ppd_keyword, msgid);
46914681
cupsFilePrintf(fp, "*cupsIPPFinishings %d/%s: \"*StapleLocation %s\"\n", value, keyword, ppd_keyword);
46924682
}
46934683

@@ -4750,9 +4740,6 @@ _ppdCreateFromIPP2(
47504740
cupsArrayAdd(names, (char *)keyword);
47514741

47524742
snprintf(msgid, sizeof(msgid), "finishings.%d", value);
4753-
if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr))
4754-
if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid)
4755-
msgstr = keyword;
47564743

47574744
if (value >= IPP_FINISHINGS_NONE && value <= IPP_FINISHINGS_LAMINATE)
47584745
ppd_keyword = base_keywords[value - IPP_FINISHINGS_NONE];
@@ -4767,7 +4754,7 @@ _ppdCreateFromIPP2(
47674754
continue;
47684755

47694756
cupsFilePrintf(fp, "*FoldType %s: \"\"\n", ppd_keyword);
4770-
cupsFilePrintf(fp, "*%s.FoldType %s/%s: \"\"\n", lang->language, ppd_keyword, msgstr);
4757+
ppd_put_string(fp, lang, strings, "FoldType", ppd_keyword, msgid);
47714758
cupsFilePrintf(fp, "*cupsIPPFinishings %d/%s: \"*FoldType %s\"\n", value, keyword, ppd_keyword);
47724759
}
47734760

@@ -4838,9 +4825,6 @@ _ppdCreateFromIPP2(
48384825
cupsArrayAdd(names, (char *)keyword);
48394826

48404827
snprintf(msgid, sizeof(msgid), "finishings.%d", value);
4841-
if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr))
4842-
if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid)
4843-
msgstr = keyword;
48444828

48454829
if (value >= IPP_FINISHINGS_NONE && value <= IPP_FINISHINGS_LAMINATE)
48464830
ppd_keyword = base_keywords[value - IPP_FINISHINGS_NONE];
@@ -4855,7 +4839,7 @@ _ppdCreateFromIPP2(
48554839
continue;
48564840

48574841
cupsFilePrintf(fp, "*PunchMedia %s: \"\"\n", ppd_keyword);
4858-
cupsFilePrintf(fp, "*%s.PunchMedia %s/%s: \"\"\n", lang->language, ppd_keyword, msgstr);
4842+
ppd_put_string(fp, lang, strings, "PunchMedia", ppd_keyword, msgid);
48594843
cupsFilePrintf(fp, "*cupsIPPFinishings %d/%s: \"*PunchMedia %s\"\n", value, keyword, ppd_keyword);
48604844
}
48614845

@@ -4926,17 +4910,14 @@ _ppdCreateFromIPP2(
49264910
cupsArrayAdd(names, (char *)keyword);
49274911

49284912
snprintf(msgid, sizeof(msgid), "finishings.%d", value);
4929-
if ((msgstr = _cupsLangString(lang, msgid)) == msgid || !strcmp(msgid, msgstr))
4930-
if ((msgstr = _cupsMessageLookup(strings, msgid)) == msgid)
4931-
msgstr = keyword;
49324913

49334914
if (value == IPP_FINISHINGS_TRIM)
49344915
ppd_keyword = "Auto";
49354916
else
49364917
ppd_keyword = trim_keywords[value - IPP_FINISHINGS_TRIM_AFTER_PAGES];
49374918

49384919
cupsFilePrintf(fp, "*CutMedia %s: \"\"\n", ppd_keyword);
4939-
cupsFilePrintf(fp, "*%s.CutMedia %s/%s: \"\"\n", lang->language, ppd_keyword, msgstr);
4920+
ppd_put_string(fp, lang, strings, "CutMedia", ppd_keyword, msgid);
49404921
cupsFilePrintf(fp, "*cupsIPPFinishings %d/%s: \"*CutMedia %s\"\n", value, keyword, ppd_keyword);
49414922
}
49424923

@@ -4978,9 +4959,6 @@ _ppdCreateFromIPP2(
49784959
pwg_ppdize_name(keyword, ppdname, sizeof(ppdname));
49794960

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

49854963
cupsFilePrintf(fp, "*cupsFinishingTemplate %s: \"\n", ppdname);
49864964
for (finishing_attr = ippFirstAttribute(finishing_col); finishing_attr; finishing_attr = ippNextAttribute(finishing_col))
@@ -4995,7 +4973,7 @@ _ppdCreateFromIPP2(
49954973
}
49964974
}
49974975
cupsFilePuts(fp, "\"\n");
4998-
cupsFilePrintf(fp, "*%s.cupsFinishingTemplate %s/%s: \"\"\n", lang->language, ppdname, msgstr);
4976+
ppd_put_string(fp, lang, strings, "cupsFinishingTemplate", ppdname, msgid);
49994977
cupsFilePuts(fp, "*End\n");
50004978
}
50014979

@@ -5164,11 +5142,9 @@ _ppdCreateFromIPP2(
51645142

51655143
cupsFilePuts(fp, "\"\n*End\n");
51665144

5167-
if ((localized_name = _cupsMessageLookup(strings, preset_name)) != preset_name)
5168-
{
5169-
pwg_ppdize_name(preset_name, ppdname, sizeof(ppdname));
5170-
cupsFilePrintf(fp, "*%s.APPrinterPreset %s/%s: \"\"\n", lang->language, ppdname, localized_name);
5171-
}
5145+
snprintf(msgid, sizeof(msgid), "preset-name.%s", preset_name);
5146+
pwg_ppdize_name(preset_name, ppdname, sizeof(ppdname));
5147+
ppd_put_string(fp, lang, strings, "APPrinterPreset", ppdname, msgid);
51725148
}
51735149
}
51745150

@@ -5439,6 +5415,43 @@ cups_get_url(http_t **http, /* IO - Current HTTP connection */
54395415
}
54405416

54415417

5418+
/*
5419+
* 'ppd_put_strings()' - Write localization attributes to a PPD file.
5420+
*/
5421+
5422+
static void
5423+
ppd_put_string(cups_file_t *fp, /* I - PPD file */
5424+
cups_lang_t *lang, /* I - Language */
5425+
cups_array_t *strings, /* I - Strings */
5426+
const char *ppd_option,/* I - PPD option */
5427+
const char *ppd_choice,/* I - PPD choice */
5428+
const char *pwg_msgid) /* I - PWG message ID */
5429+
{
5430+
const char *text; /* Localized text */
5431+
5432+
5433+
if ((text = _cupsLangString(lang, pwg_msgid)) == pwg_msgid || !strcmp(pwg_msgid, text))
5434+
{
5435+
if ((text = _cupsMessageLookup(strings, pwg_msgid)) == pwg_msgid)
5436+
return;
5437+
}
5438+
5439+
// Add the first line of localized text...
5440+
cupsFilePrintf(fp, "*%s.%s %s/", lang->language, ppd_option, ppd_choice);
5441+
while (*text && *text != '\n')
5442+
{
5443+
// Escape ":" and "<"...
5444+
if (*text == ':' || *text == '<')
5445+
cupsFilePrintf(fp, "<%02X>", *text);
5446+
else
5447+
cupsFilePutChar(fp, *text);
5448+
5449+
text ++;
5450+
}
5451+
cupsFilePuts(fp, ": \"\"\n");
5452+
}
5453+
5454+
54425455
/*
54435456
* 'pwg_add_finishing()' - Add a finishings value.
54445457
*/

0 commit comments

Comments
 (0)