summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Untz <vuntz@novell.com>2008-11-13 15:49:56 +0100
committerVincent Untz <vuntz@novell.com>2008-11-13 15:49:56 +0100
commit5d5a4ba3f1f166a5295c7f771edd6d2e0e241f2e (patch)
tree2bd3e212312932e5aeaf26788a314495d3e78632
parent93a7cae10e94216c6060dc87c6807399c8a46da2 (diff)
Validity check for printer URI.
-rw-r--r--src/cups.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/cups.c b/src/cups.c
index 66a1942..d817256 100644
--- a/src/cups.c
+++ b/src/cups.c
@@ -205,6 +205,24 @@ cph_cups_new (void)
******************************************************/
static gboolean
+_cph_cups_is_string_printable (const char *str)
+{
+ int i;
+
+ /* no NULL string */
+ if (!str)
+ return FALSE;
+
+ /* only printable characters */
+ for (i = 0; i < strlen (str); i++) {
+ if (!g_ascii_isprint (str[i]))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
_cph_cups_is_printer_name_valid_internal (const char *name)
{
int i;
@@ -242,6 +260,22 @@ _cph_cups_is_printer_name_valid (CphCups *cups,
return FALSE;
}
+static gboolean
+_cph_cups_is_printer_uri_valid (CphCups *cups,
+ const char *uri)
+{
+ char *error;
+
+ if (_cph_cups_is_string_printable (uri))
+ return TRUE;
+
+ error = g_strdup_printf ("\"%s\" is not a valid printer URI.", uri);
+ _cph_cups_set_internal_status (cups, error);
+ g_free (error);
+
+ return FALSE;
+}
+
/******************************************************
* Helpers
******************************************************/
@@ -440,6 +474,8 @@ cph_cups_printer_add (CphCups *cups,
/* FIXME check arguments are fine */
if (!_cph_cups_is_printer_name_valid (cups, printer_name))
return FALSE;
+ if (!_cph_cups_is_printer_uri_valid (cups, printer_uri))
+ return FALSE;
request = ippNewRequest (CUPS_ADD_MODIFY_PRINTER);
_cph_cups_add_printer_uri (request, printer_name);
@@ -478,6 +514,8 @@ cph_cups_printer_add_with_ppd_file (CphCups *cups,
/* FIXME check arguments are fine */
if (!_cph_cups_is_printer_name_valid (cups, printer_name))
return FALSE;
+ if (!_cph_cups_is_printer_uri_valid (cups, printer_uri))
+ return FALSE;
request = ippNewRequest (CUPS_ADD_MODIFY_PRINTER);
_cph_cups_add_printer_uri (request, printer_name);
@@ -546,9 +584,10 @@ cph_cups_printer_set_uri (CphCups *cups,
g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
- /* FIXME check arguments are fine */
if (!_cph_cups_is_printer_name_valid (cups, printer_name))
return FALSE;
+ if (!_cph_cups_is_printer_uri_valid (cups, printer_uri))
+ return FALSE;
request = ippNewRequest (CUPS_ADD_MODIFY_PRINTER);
_cph_cups_add_printer_uri (request, printer_name);