Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Support AllowedChars for String/Password type custom PPD options #2814
Comments
|
CUPS.org User: larsuebernickel I have a patch ready which adds a 5th parameter to *ParamCustom, using the same syntax as scanf(2) for character ranges. For example: *CustomUserId True:
|
|
CUPS.org User: till.kamppeter I am not sure whether I am right, but the min, max, allowed characters, ... should be enforced once by the driver (as foomatic-rip does it already for the Foomatic string and password options), and second, by the client-side GUIs, like the web interfaces, and all printing dialogs which support custom options. So it should be done the following:
Mike, am I right? Or does the CUPS core (scheduler, libcups, ...) also enforce the restrictions of these options? And if yes, where? |
|
CUPS.org User: mike I am hesitant to extend the custom option syntax in 1.4 without some more discussion. In particular, it seems like using the POSIX regular expression syntax would be better than a simple set of allowed characters and open up more robust string validation. As for range limiting the custom input, that is the responsibility of the caller/application - the custom parameter data is provided so that the UI can map the limits appropriately to UI controls/feedback. Like UIConstraints, they aren't enforced by the library because the recovery mode (what to do when a custom parameter is out of range or when a conflicting choice is made) cannot be described in the PPD. |
|
CUPS.org User: till.kamppeter Mike, I agree with you to use Posix regexps for restricting the allowed characters. This is much more flexible and even allows a basic syntax check of the input. AFAIR there is also a C library for parsing POSIX regexps (Lars, you have probably used that for foomatic-rip). So let's settle on that. As the CUPS core is not involved in the enforcing of the restrictions, we should go the way of my previous posting. So we can delegate most of the fix to Lars: Lars, can you update the patch for the web interface, foomatic-rip, and also implement this in the Common Printing Dialog (if it falls into your area, otherwise it is Alex' task). Mike, your part of the implementation will be to update the documentation, and perhaps some rasterto... drivers of CUPS, CUPS DDK, and perhaps Gutenprint. But at first we have to agree on the syntax. My suggestion is to follow Lars' suggestion but replacing the character list by a POSIX regexp. Lars, then this will be more or less an equivalent of "_FoomaticRIPOptionAllowedRegExp" keyword. A Character lis as supplied with the "_FoomaticRIPOptionAllowedChars" keyword has to be surrounded by "^[...]*$". |
|
CUPS.org User: larsuebernickel Okay, the patch was a bit more work than I hoped it would be ... It includes the following: *ParamCustom commands of type string and password can have a POSIX extended regular expression as a 5th parameter. For a custom option value to be valid, it must be matched by the regexp. The web interface exposes a "Custom" choice for all options which can be set to custom values (this is the patch from STR #1729). It accepts only valid values (i.e. correct type, between range, matches regexp) and displays a detailed error message for invalid entries on the top of the "Set Printer Options" page. The user then has the chance to modify the values according to the restrictions. The patch compiles fine against latest svn (r7563). Hope you like it ;)
|
|
CUPS.org User: larsuebernickel Mike, did you have a chance to look at my patch, yet?
|
|
CUPS.org User: mike I did not, but you can be sure that this patch will not be incorporated into CUPS before version 1.5... |
|
CUPS.org User: mike Given the limited usefulness of even regular expressions for validating what are supposed to be user-defined (custom) strings, we have decided not to implement this. |
|
"cups-coptions.patch": diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c /*
@@ -2754,13 +2756,219 @@ do_set_allowed_users(http_t http) / I - HTTP connection */ +#define INV_VALUE_HASH_SIZE 32
+void add_invalid_value(cups_array_t *a,
+int compare_invalid_values(invalid_value_t *v1,
+int hash_invalid_value(invalid_value_t *v, void *user_data)
+int /* O - Non-zero on success. /
+void
+int /* O - True if 'value' is valid /
+/*
/*
static void
title = cgiText(is_class ? _("Set Class Options") : _("Set Printer Options")); @@ -2875,7 +3087,7 @@ do_set_options(http_t http, / I - HTTP connection */ ppdConflicts(ppd) = %d\n", ppdConflicts(ppd)));
- */
- continue;
@@ -2954,6 +3177,83 @@ do_set_options(http_t http, / I - HTTP connection */
@@ -3176,6 +3482,9 @@ do_set_options(http_t http, / I - HTTP connection */
@@ -3276,6 +3593,21 @@ do_set_options(http_t http, / I - HTTP connection */
if (filename)
diff --git a/cups/ppd.c b/cups/ppd.c /*
diff --git a/doc/cups.css b/doc/cups.css +TH.sublabel {
HR {
+}
+:} diff --git a/templates/set-printer-options-header.tmpl b/templates/set-printer-options-header.tmpl index 864f9f0..c5ff5a0 100644 --- a/templates/set-printer-options-header.tmpl +++ b/templates/set-printer-options-header.tmpl @@ -1,3 +1,16 @@ + +<script type="text/javascript"> +function update_paramtable(option) +{ - var cb = document.getElementById("select-" + option) - var paramstable = document.getElementById(option + "-params"); - if (cb.value == "Custom") - paramstable.style.display = "table"; - else - paramstable.style.display = "none"; +} +</script> + diff --git a/templates/set-printer-options-trailer.tmpl b/templates/set-printer-options-trailer.tmpl index a3d1e1f..309256e 100644 --- a/templates/set-printer-options-trailer.tmpl +++ b/templates/set-printer-options-trailer.tmpl @@ -1 +1,15 @@ + +<script type="text/javascript"> + +// hide custom options parameters for browsers that understand javascript +var paramtables = document.getElementsByName("paramtable"); +for (var i = 0; i < paramtables.length; i++) { - var opt = paramtables[i].id.substr(0, paramtables[i].id.lastIndexOf("-")); - var cb = document.getElementById("select-" + opt); - if (cb.value != "Custom") - paramtables[i].style.display = "none"; +} + +</script> + |
michaelrsweet commentedMay 2, 2008
Version: -feature
CUPS.org User: georgeliuyue
I'd like to further propose a new syntax to specify allowed characters for string and password type PPD options.
For example, allowed chars for phone numbers is (0-9, '-' and space)
Allowed chars for userid is (0-9a-zA-Z and '_')
A password type with allowe chars "0-9" is equivalent to passcode type.