From d1cf03383a481675a2458d6ffc95bca7f495eff8 Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Thu, 27 Jan 2011 15:45:50 +0100 Subject: Imported Upstream version 4.0.6 --- options.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 106 insertions(+), 36 deletions(-) (limited to 'options.c') diff --git a/options.c b/options.c index 777ba50..9a4b116 100644 --- a/options.c +++ b/options.c @@ -34,14 +34,19 @@ /* Values from foomatic keywords in the ppd file */ char printer_model [256]; -char printer_id [128]; +char printer_id [256]; char driver [128]; -char cmd [1024]; -char cmd_pdf [1024]; +char cmd [4096]; +char cmd_pdf [4096]; dstr_t *postpipe = NULL; /* command into which the output of this filter should be piped */ int ps_accounting = 1; char cupsfilter [256]; +int jobentitymaxlen = 0; +int userentitymaxlen = 0; +int hostentitymaxlen = 0; +int titleentitymaxlen = 0; +int optionsentitymaxlen = 0; /* JCL prefix to put before the JCL options (Can be modified by a "*JCLBegin:" keyword in the ppd file): */ @@ -677,7 +682,8 @@ char * get_valid_value_string(option_t *opt, const char *value) /* Check if "value" is a predefined choice (except for "Custom", which is * not really a predefined choice, but an error if used without further * parameters) */ - if (strcmp(value, "Custom") != 0 && (choice = option_find_choice(opt, value))) + if ((strcmp(value, "Custom") != 0 || strcmp(opt->name, "PageSize") == 0) && + (choice = option_find_choice(opt, value))) return strdup(choice->value); if (opt->type == TYPE_ENUM) { @@ -751,7 +757,7 @@ void build_foomatic_custom_command(dstr_t *cmd, option_t *opt, const char *value { choice_t *choice = option_find_choice(opt, "Custom"); char ** paramvalues = paramvalues_from_string(opt, values); - char width[30], height[20]; + char width[30], height[30]; int pos; assert(choice); @@ -765,7 +771,7 @@ void build_foomatic_custom_command(dstr_t *cmd, option_t *opt, const char *value if ((pos = dstrreplace(cmd, "%0", width, 0)) < 0) pos = dstrreplace(cmd, "0", width, 0); - if ((pos = dstrreplace(cmd, "%1", height, pos) < 0)) + if (dstrreplace(cmd, "%1", height, pos) < 0) dstrreplace(cmd, "0", height, pos); free_paramvalues(opt, paramvalues); @@ -1083,79 +1089,123 @@ static void unhtmlify(char *dest, size_t size, const char *src) { jobparams_t *job = get_current_job(); char *pdest = dest; - const char *psrc = src; + const char *psrc = src, *p = NULL; const char *repl; struct tm *t = localtime(&job->time); char tmpstr[10]; + size_t s, l, n; - while (*psrc && pdest - dest < size) { + while (*psrc && pdest - dest < size - 1) { if (*psrc == '&') { psrc++; repl = NULL; + p = NULL; + l = 0; /* Replace HTML/XML entities by the original characters */ - if (!prefixcmp(psrc, "apos;")) + if (!prefixcmp(psrc, "apos")) { repl = "\'"; - else if (!prefixcmp(psrc, "quot;")) + p = psrc + 4; + } else if (!prefixcmp(psrc, "quot")) { repl = "\""; - else if (!prefixcmp(psrc, "gt;")) + p = psrc + 4; + } else if (!prefixcmp(psrc, "gt")) { repl = ">"; - else if (!prefixcmp(psrc, "lt;")) + p = psrc + 2; + } else if (!prefixcmp(psrc, "lt")) { repl = "<"; - else if (!prefixcmp(psrc, "amp;")) + p = psrc + 2; + } else if (!prefixcmp(psrc, "amp")) { repl = "&"; + p = psrc + 3; /* Replace special entities by job->data */ - else if (!prefixcmp(psrc, "job;")) + } else if (!prefixcmp(psrc, "job")) { repl = job->id; - else if (!prefixcmp(psrc, "user;")) + p = psrc + 3; + if (jobentitymaxlen != 0) + l = jobentitymaxlen; + } else if (!prefixcmp(psrc, "user")) { repl = job->user; - else if (!prefixcmp(psrc, "host;")) + p = psrc + 4; + if (userentitymaxlen != 0) + l = userentitymaxlen; + } else if (!prefixcmp(psrc, "host")) { repl = job->host; - else if (!prefixcmp(psrc, "title;")) + p = psrc + 4; + if (hostentitymaxlen != 0) + l = hostentitymaxlen; + } else if (!prefixcmp(psrc, "title")) { repl = job->title; - else if (!prefixcmp(psrc, "copies;")) + p = psrc + 5; + if (titleentitymaxlen != 0) + l = titleentitymaxlen; + } else if (!prefixcmp(psrc, "copies")) { repl = job->copies; - else if (!prefixcmp(psrc, "rbinumcopies;")) { + p = psrc + 6; + } else if (!prefixcmp(psrc, "rbinumcopies")) { if (job->rbinumcopies > 0) { snprintf(tmpstr, 10, "%d", job->rbinumcopies); repl = tmpstr; } else repl = job->copies; + p = psrc + 12; } - else if (!prefixcmp(psrc, "options;")) + else if (!prefixcmp(psrc, "options")) { repl = job->optstr->data; - else if (!prefixcmp(psrc, "year;")) { + p = psrc + 7; + if (optionsentitymaxlen != 0) + l = optionsentitymaxlen; + } else if (!prefixcmp(psrc, "year")) { sprintf(tmpstr, "%04d", t->tm_year + 1900); repl = tmpstr; + p = psrc + 4; } - else if (!prefixcmp(psrc, "month;")) { + else if (!prefixcmp(psrc, "month")) { sprintf(tmpstr, "%02d", t->tm_mon + 1); repl = tmpstr; + p = psrc + 5; } - else if (!prefixcmp(psrc, "date;")) { + else if (!prefixcmp(psrc, "date")) { sprintf(tmpstr, "%02d", t->tm_mday); repl = tmpstr; + p = psrc + 4; } - else if (!prefixcmp(psrc, "hour;")) { + else if (!prefixcmp(psrc, "hour")) { sprintf(tmpstr, "%02d", t->tm_hour); repl = tmpstr; + p = psrc + 4; } - else if (!prefixcmp(psrc, "min;")) { + else if (!prefixcmp(psrc, "min")) { sprintf(tmpstr, "%02d", t->tm_min); repl = tmpstr; + p = psrc + 3; } - else if (!prefixcmp(psrc, "sec;")) { + else if (!prefixcmp(psrc, "sec")) { sprintf(tmpstr, "%02d", t->tm_sec); repl = tmpstr; + p = psrc + 3; } - + if (p) { + n = strtol(p, (char **)(&p), 0); + if (n != 0) + l = n; + if (*p != ';') + repl = NULL; + } else + repl = NULL; if (repl) { - strncpy(pdest, repl, size - (pdest - dest)); - pdest += strlen(repl); - psrc = strchr(psrc, ';') +1; + if ((l == 0) || (l > strlen(repl))) + l = strlen(repl); + s = size - (pdest - dest) - 1; + strncpy(pdest, repl, s); + if (s < l) + pdest += s; + else + pdest += l; + psrc = p + 1; } else { *pdest = '&'; @@ -1215,7 +1265,7 @@ void option_set_choice(option_t *opt, const char *name, const char *text, } if (!startswith(code, "%% FoomaticRIPOptionSetting")) - unhtmlify(choice->command, 1024, code); + unhtmlify(choice->command, 65536, code); } /* @@ -1529,10 +1579,10 @@ void read_ppd_file(const char *filename) unhtmlify(postpipe->data, postpipe->alloc, value->data); } else if (strcmp(key, "FoomaticRIPCommandLine") == 0) { - unhtmlify(cmd, 1024, value->data); + unhtmlify(cmd, 4096, value->data); } else if (strcmp(key, "FoomaticRIPCommandLinePDF") == 0) { - unhtmlify(cmd_pdf, 1024, value->data); + unhtmlify(cmd_pdf, 4096, value->data); } else if (strcmp(key, "FoomaticRIPNoPageAccounting") == 0) { /* Boolean value */ @@ -1600,8 +1650,8 @@ void read_ppd_file(const char *filename) /* "*FoomaticRIPOptionPrototype