summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Untz <vuntz@novell.com>2010-02-16 19:02:39 +0100
committerVincent Untz <vuntz@novell.com>2010-02-16 19:02:39 +0100
commit65e48f8f65f755db466f87ee581713c488eab59f (patch)
treee386567619255feb4aaf0b5795a38591fb0fa5e2
parent704638143f61fdabd60d2b3584ab97daea8957f6 (diff)
Use an array of strings for schemes arguments of DevicesGet
This will make the API work like the pycups one. Also, we start validating the schemes.
-rw-r--r--src/cups-pk-helper-mechanism.c12
-rw-r--r--src/cups-pk-helper-mechanism.h12
-rw-r--r--src/cups-pk-helper-mechanism.xml4
-rw-r--r--src/cups.c54
-rw-r--r--src/cups.h10
5 files changed, 62 insertions, 30 deletions
diff --git a/src/cups-pk-helper-mechanism.c b/src/cups-pk-helper-mechanism.c
index bc341f4..6f98eba 100644
--- a/src/cups-pk-helper-mechanism.c
+++ b/src/cups-pk-helper-mechanism.c
@@ -1168,12 +1168,12 @@ cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
}
gboolean
-cph_mechanism_devices_get (CphMechanism *mechanism,
- int timeout,
- int limit,
- const char *include_schemes,
- const char *exclude_schemes,
- DBusGMethodInvocation *context)
+cph_mechanism_devices_get (CphMechanism *mechanism,
+ int timeout,
+ int limit,
+ const char **include_schemes,
+ const char **exclude_schemes,
+ DBusGMethodInvocation *context)
{
GHashTable *devices;
diff --git a/src/cups-pk-helper-mechanism.h b/src/cups-pk-helper-mechanism.h
index 81ddb82..4b800a6 100644
--- a/src/cups-pk-helper-mechanism.h
+++ b/src/cups-pk-helper-mechanism.h
@@ -237,12 +237,12 @@ cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
DBusGMethodInvocation *context);
gboolean
-cph_mechanism_devices_get (CphMechanism *mechanism,
- int timeout,
- int limit,
- const char *include_schemes,
- const char *exclude_schemes,
- DBusGMethodInvocation *context);
+cph_mechanism_devices_get (CphMechanism *mechanism,
+ int timeout,
+ int limit,
+ const char **include_schemes,
+ const char **exclude_schemes,
+ DBusGMethodInvocation *context);
G_END_DECLS
diff --git a/src/cups-pk-helper-mechanism.xml b/src/cups-pk-helper-mechanism.xml
index 10b7eff..b7b9b6e 100644
--- a/src/cups-pk-helper-mechanism.xml
+++ b/src/cups-pk-helper-mechanism.xml
@@ -197,8 +197,8 @@
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="timeout" direction="in" type="i"/>
<arg name="limit" direction="in" type="i"/>
- <arg name="include_schemes" direction="in" type="s"/>
- <arg name="exclude_schemes" direction="in" type="s"/>
+ <arg name="include_schemes" direction="in" type="as"/>
+ <arg name="exclude_schemes" direction="in" type="as"/>
<arg name="error" direction="out" type="s"/>
<arg name="devices" direction="out" type="a{ss}"/>
</method>
diff --git a/src/cups.c b/src/cups.c
index 63058bf..2c1e81e 100644
--- a/src/cups.c
+++ b/src/cups.c
@@ -385,6 +385,10 @@ _CPH_CUPS_IS_VALID (location, "location", FALSE)
_CPH_CUPS_IS_VALID (reject_jobs_reason, "reason", FALSE)
_CPH_CUPS_IS_VALID (job_hold_until, "job hold until", FALSE)
+/* Check for scheme. Unless we hardcode all schemes, we can only check it's
+ * valid text. */
+_CPH_CUPS_IS_VALID (scheme, "scheme", TRUE)
+
/* For put/get file: this is some text, but we could potentially do more
* checks. We don't do them because cups will already do them.
* + for the resource, we could check that it starts with a /, for example.
@@ -1858,16 +1862,37 @@ _cph_cups_get_devices_cb (const char *device_class,
}
GHashTable *
-cph_cups_devices_get (CphCups *cups,
- int timeout,
- int limit,
- const char *include_schemes,
- const char *exclude_schemes)
+cph_cups_devices_get (CphCups *cups,
+ int timeout,
+ int limit,
+ const char **include_schemes,
+ const char **exclude_schemes)
{
struct _CphCupsGetDevices data;
+ int len_include;
+ int len_exclude;
g_return_val_if_fail (CPH_IS_CUPS (cups), NULL);
+ /* check the validity of values */
+ len_include = 0;
+ if (include_schemes) {
+ while (include_schemes[len_include] != NULL) {
+ if (!_cph_cups_is_scheme_valid (cups, include_schemes[len_include]))
+ return NULL;
+ len_include++;
+ }
+ }
+
+ len_exclude = 0;
+ if (exclude_schemes) {
+ while (exclude_schemes[len_exclude] != NULL) {
+ if (!_cph_cups_is_scheme_valid (cups, exclude_schemes[len_exclude]))
+ return NULL;
+ len_exclude++;
+ }
+ }
+
data.iter = 0;
data.limit = -1;
data.hash = g_hash_table_new_full (g_str_hash, g_str_equal,
@@ -1878,17 +1903,21 @@ cph_cups_devices_get (CphCups *cups,
#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1
ipp_status_t retval;
int timeout_param = CUPS_TIMEOUT_DEFAULT;
- const char *include_schemes_param = CUPS_INCLUDE_ALL;
- const char *exclude_schemes_param = CUPS_EXCLUDE_NONE;
+ char *include_schemes_param;
+ char *exclude_schemes_param;
if (timeout > 0)
timeout_param = timeout;
- if (include_schemes && strlen (include_schemes) > 0)
- include_schemes_param = include_schemes;
+ if (include_schemes && len_include > 0)
+ include_schemes_param = g_strjoin (",", include_schemes);
+ else
+ include_schemes_param = g_strdup (CUPS_INCLUDE_ALL);
- if (exclude_schemes && strlen (exclude_schemes) > 0)
- exclude_schemes_param = exclude_schemes;
+ if (exclude_schemes && len_exclude > 0)
+ exclude_schemes_param = g_strjoin (",", exclude_schemes);
+ else
+ exclude_schemes_param = g_strdup (CUPS_EXCLUDE_NONE);
retval = cupsGetDevices (cups->priv->connection,
timeout_param,
@@ -1897,6 +1926,9 @@ cph_cups_devices_get (CphCups *cups,
_cph_cups_get_devices_cb,
&data);
+ g_free (include_schemes_param);
+ g_free (exclude_schemes_param);
+
if (retval != IPP_OK)
goto out;
#else
diff --git a/src/cups.h b/src/cups.h
index 251bc26..6117d80 100644
--- a/src/cups.h
+++ b/src/cups.h
@@ -184,11 +184,11 @@ CphJobStatus cph_cups_job_get_status (CphCups *cups,
int job_id,
const char *user);
-GHashTable *cph_cups_devices_get (CphCups *cups,
- int timeout,
- int limit,
- const char *include_schemes,
- const char *exclude_schemes);
+GHashTable *cph_cups_devices_get (CphCups *cups,
+ int timeout,
+ int limit,
+ const char **include_schemes,
+ const char **exclude_schemes);
G_END_DECLS