summaryrefslogtreecommitdiff
path: root/src/cups-pk-helper-mechanism.c
diff options
context:
space:
mode:
authorVincent Untz <vuntz@novell.com>2010-02-16 19:49:21 +0100
committerVincent Untz <vuntz@novell.com>2010-02-16 19:49:21 +0100
commit534efdda6a53ee2beaa025e6dc89ea477e4a98e8 (patch)
tree2d3bf1909edfd8c9e7a9c2096dbbba4ca68f64b2 /src/cups-pk-helper-mechanism.c
parentda98f819e8f8d2c8515073b364d997e509b6233e (diff)
Move lots of code around
We regroup the functions that work at the same level together.
Diffstat (limited to 'src/cups-pk-helper-mechanism.c')
-rw-r--r--src/cups-pk-helper-mechanism.c422
1 files changed, 211 insertions, 211 deletions
diff --git a/src/cups-pk-helper-mechanism.c b/src/cups-pk-helper-mechanism.c
index 6f98eba..990f123 100644
--- a/src/cups-pk-helper-mechanism.c
+++ b/src/cups-pk-helper-mechanism.c
@@ -567,6 +567,68 @@ cph_mechanism_file_put (CphMechanism *mechanism,
}
gboolean
+cph_mechanism_server_get_settings (CphMechanism *mechanism,
+ DBusGMethodInvocation *context)
+{
+ GHashTable *settings;
+
+ reset_killtimer (mechanism);
+
+ if (!_check_polkit_for_action (mechanism, context, "server-settings"))
+ return FALSE;
+
+ settings = cph_cups_server_get_settings (mechanism->priv->cups);
+ _cph_mechanism_return_error_and_value (mechanism, context,
+ settings == NULL, settings);
+
+ return TRUE;
+}
+
+gboolean
+cph_mechanism_server_set_settings (CphMechanism *mechanism,
+ GHashTable *settings,
+ DBusGMethodInvocation *context)
+{
+ gboolean ret;
+
+ reset_killtimer (mechanism);
+
+ if (!_check_polkit_for_action (mechanism, context, "server-settings"))
+ return FALSE;
+
+ ret = cph_cups_server_set_settings (mechanism->priv->cups, settings);
+ _cph_mechanism_return_error (mechanism, context, !ret);
+
+ return TRUE;
+}
+
+gboolean
+cph_mechanism_devices_get (CphMechanism *mechanism,
+ int timeout,
+ int limit,
+ const char **include_schemes,
+ const char **exclude_schemes,
+ DBusGMethodInvocation *context)
+{
+ GHashTable *devices;
+
+ reset_killtimer (mechanism);
+
+ if (!_check_polkit_for_action (mechanism, context, "devices-get"))
+ return FALSE;
+
+ devices = cph_cups_devices_get (mechanism->priv->cups,
+ timeout,
+ limit,
+ include_schemes,
+ exclude_schemes);
+ _cph_mechanism_return_error_and_value (mechanism, context,
+ devices == NULL, devices);
+
+ return TRUE;
+}
+
+gboolean
cph_mechanism_printer_add (CphMechanism *mechanism,
const char *name,
const char *uri,
@@ -634,151 +696,178 @@ cph_mechanism_printer_set_device (CphMechanism *mechanism,
}
gboolean
-cph_mechanism_printer_set_info (CphMechanism *mechanism,
- const char *name,
- const char *info,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_default (CphMechanism *mechanism,
+ const char *name,
+ DBusGMethodInvocation *context)
{
- gboolean ret;
+ gboolean ret;
+ const char *last_action;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer_class (mechanism, context, name))
+ last_action = _cph_mechanism_get_action_for_name (mechanism, name);
+ if (!_check_polkit_for_action_v (mechanism, context,
+ "printeraddremove",
+ /* this is not the last check because
+ * it's likely most useful to the user
+ * to give "printer-X-edit" powers */
+ "printer-default",
+ /* quite important, since it's
+ * automatically called after adding a
+ * printer */
+ last_action,
+ NULL))
return FALSE;
- ret = cph_cups_printer_class_set_info (mechanism->priv->cups,
- name, info);
+ ret = cph_cups_printer_set_default (mechanism->priv->cups, name);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_set_location (CphMechanism *mechanism,
- const char *name,
- const char *location,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_enabled (CphMechanism *mechanism,
+ const char *name,
+ gboolean enabled,
+ DBusGMethodInvocation *context)
{
- gboolean ret;
+ gboolean ret;
+ const char *last_action;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer_class (mechanism, context, name))
+ last_action = _cph_mechanism_get_action_for_name (mechanism, name);
+ if (!_check_polkit_for_action_v (mechanism, context,
+ "printeraddremove",
+ /* this is not the last check because
+ * it's likely most useful to the user
+ * to give "printer-X-edit" powers */
+ "printer-enable",
+ /* quite important, since it's
+ * automatically called after adding a
+ * printer */
+ last_action,
+ NULL))
return FALSE;
- ret = cph_cups_printer_class_set_location (mechanism->priv->cups,
- name, location);
+ ret = cph_cups_printer_set_enabled (mechanism->priv->cups,
+ name, enabled);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_set_shared (CphMechanism *mechanism,
- const char *name,
- gboolean shared,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_accept_jobs (CphMechanism *mechanism,
+ const char *name,
+ gboolean enabled,
+ const char *reason,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer_class (mechanism, context, name))
+ if (!_check_polkit_for_printer (mechanism, context, name, NULL))
return FALSE;
- ret = cph_cups_printer_class_set_shared (mechanism->priv->cups,
- name, shared);
+ if (reason && reason[0] == '\0')
+ reason = NULL;
+
+ ret = cph_cups_printer_set_accept_jobs (mechanism->priv->cups,
+ name, enabled, reason);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_set_job_sheets (CphMechanism *mechanism,
- const char *name,
- const char *start,
- const char *end,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_delete (CphMechanism *mechanism,
+ const char *name,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer_class (mechanism, context, name))
+ if (!_check_polkit_for_printer (mechanism, context, name, NULL))
return FALSE;
- ret = cph_cups_printer_class_set_job_sheets (mechanism->priv->cups,
- name, start, end);
+ ret = cph_cups_printer_delete (mechanism->priv->cups, name);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_set_error_policy (CphMechanism *mechanism,
- const char *name,
- const char *policy,
- DBusGMethodInvocation *context)
+cph_mechanism_class_add_printer (CphMechanism *mechanism,
+ const char *name,
+ const char *printer,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer_class (mechanism, context, name))
+ if (!_check_polkit_for_action_v (mechanism, context,
+ "printeraddremove", "class-edit",
+ NULL))
return FALSE;
- ret = cph_cups_printer_class_set_error_policy (mechanism->priv->cups,
- name, policy);
+ ret = cph_cups_class_add_printer (mechanism->priv->cups,
+ name, printer);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_set_op_policy (CphMechanism *mechanism,
- const char *name,
- const char *policy,
- DBusGMethodInvocation *context)
+cph_mechanism_class_delete_printer (CphMechanism *mechanism,
+ const char *name,
+ const char *printer,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer_class (mechanism, context, name))
+ if (!_check_polkit_for_action_v (mechanism, context,
+ "printeraddremove", "class-edit",
+ NULL))
return FALSE;
- ret = cph_cups_printer_class_set_op_policy (mechanism->priv->cups,
- name, policy);
+ ret = cph_cups_class_delete_printer (mechanism->priv->cups,
+ name, printer);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_set_users_allowed (CphMechanism *mechanism,
- const char *name,
- const char **users,
- DBusGMethodInvocation *context)
+cph_mechanism_class_delete (CphMechanism *mechanism,
+ const char *name,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer_class (mechanism, context, name))
+ if (!_check_polkit_for_action_v (mechanism, context,
+ "printeraddremove", "class-edit",
+ NULL))
return FALSE;
- ret = cph_cups_printer_class_set_users_allowed (mechanism->priv->cups,
- name, users);
+ ret = cph_cups_class_delete (mechanism->priv->cups, name);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_set_users_denied (CphMechanism *mechanism,
- const char *name,
- const char **users,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_info (CphMechanism *mechanism,
+ const char *name,
+ const char *info,
+ DBusGMethodInvocation *context)
{
gboolean ret;
@@ -787,20 +876,18 @@ cph_mechanism_printer_set_users_denied (CphMechanism *mechanism,
if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_printer_class_set_users_denied (mechanism->priv->cups,
- name, users);
+ ret = cph_cups_printer_class_set_info (mechanism->priv->cups,
+ name, info);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
-
gboolean
-cph_mechanism_printer_add_option_default (CphMechanism *mechanism,
- const char *name,
- const char *option,
- const char **values,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_location (CphMechanism *mechanism,
+ const char *name,
+ const char *location,
+ DBusGMethodInvocation *context)
{
gboolean ret;
@@ -809,18 +896,18 @@ cph_mechanism_printer_add_option_default (CphMechanism *mechanism,
if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_printer_class_set_option_default (mechanism->priv->cups,
- name, option, values);
+ ret = cph_cups_printer_class_set_location (mechanism->priv->cups,
+ name, location);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_delete_option_default (CphMechanism *mechanism,
- const char *name,
- const char *option,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_shared (CphMechanism *mechanism,
+ const char *name,
+ gboolean shared,
+ DBusGMethodInvocation *context)
{
gboolean ret;
@@ -829,212 +916,151 @@ cph_mechanism_printer_delete_option_default (CphMechanism *mechanism,
if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_printer_class_set_option_default (mechanism->priv->cups,
- name, option, NULL);
+ ret = cph_cups_printer_class_set_shared (mechanism->priv->cups,
+ name, shared);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_delete (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_job_sheets (CphMechanism *mechanism,
+ const char *name,
+ const char *start,
+ const char *end,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer (mechanism, context, name, NULL))
+ if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_printer_delete (mechanism->priv->cups, name);
+ ret = cph_cups_printer_class_set_job_sheets (mechanism->priv->cups,
+ name, start, end);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_class_add_printer (CphMechanism *mechanism,
- const char *name,
- const char *printer,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_error_policy (CphMechanism *mechanism,
+ const char *name,
+ const char *policy,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_action_v (mechanism, context,
- "printeraddremove", "class-edit",
- NULL))
+ if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_class_add_printer (mechanism->priv->cups,
- name, printer);
+ ret = cph_cups_printer_class_set_error_policy (mechanism->priv->cups,
+ name, policy);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_class_delete_printer (CphMechanism *mechanism,
- const char *name,
- const char *printer,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_op_policy (CphMechanism *mechanism,
+ const char *name,
+ const char *policy,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_action_v (mechanism, context,
- "printeraddremove", "class-edit",
- NULL))
+ if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_class_delete_printer (mechanism->priv->cups,
- name, printer);
+ ret = cph_cups_printer_class_set_op_policy (mechanism->priv->cups,
+ name, policy);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_class_delete (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_users_allowed (CphMechanism *mechanism,
+ const char *name,
+ const char **users,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_action_v (mechanism, context,
- "printeraddremove", "class-edit",
- NULL))
+ if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_class_delete (mechanism->priv->cups, name);
+ ret = cph_cups_printer_class_set_users_allowed (mechanism->priv->cups,
+ name, users);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_printer_set_default (CphMechanism *mechanism,
- const char *name,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_set_users_denied (CphMechanism *mechanism,
+ const char *name,
+ const char **users,
+ DBusGMethodInvocation *context)
{
- gboolean ret;
- const char *last_action;
+ gboolean ret;
reset_killtimer (mechanism);
- last_action = _cph_mechanism_get_action_for_name (mechanism, name);
- if (!_check_polkit_for_action_v (mechanism, context,
- "printeraddremove",
- /* this is not the last check because
- * it's likely most useful to the user
- * to give "printer-X-edit" powers */
- "printer-default",
- /* quite important, since it's
- * automatically called after adding a
- * printer */
- last_action,
- NULL))
+ if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_printer_set_default (mechanism->priv->cups, name);
+ ret = cph_cups_printer_class_set_users_denied (mechanism->priv->cups,
+ name, users);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
-gboolean
-cph_mechanism_printer_set_enabled (CphMechanism *mechanism,
- const char *name,
- gboolean enabled,
- DBusGMethodInvocation *context)
-{
- gboolean ret;
- const char *last_action;
-
- reset_killtimer (mechanism);
-
- last_action = _cph_mechanism_get_action_for_name (mechanism, name);
- if (!_check_polkit_for_action_v (mechanism, context,
- "printeraddremove",
- /* this is not the last check because
- * it's likely most useful to the user
- * to give "printer-X-edit" powers */
- "printer-enable",
- /* quite important, since it's
- * automatically called after adding a
- * printer */
- last_action,
- NULL))
- return FALSE;
-
- ret = cph_cups_printer_set_enabled (mechanism->priv->cups,
- name, enabled);
- _cph_mechanism_return_error (mechanism, context, !ret);
-
- return TRUE;
-}
gboolean
-cph_mechanism_printer_set_accept_jobs (CphMechanism *mechanism,
- const char *name,
- gboolean enabled,
- const char *reason,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_add_option_default (CphMechanism *mechanism,
+ const char *name,
+ const char *option,
+ const char **values,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_printer (mechanism, context, name, NULL))
+ if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- if (reason && reason[0] == '\0')
- reason = NULL;
-
- ret = cph_cups_printer_set_accept_jobs (mechanism->priv->cups,
- name, enabled, reason);
+ ret = cph_cups_printer_class_set_option_default (mechanism->priv->cups,
+ name, option, values);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
}
gboolean
-cph_mechanism_server_get_settings (CphMechanism *mechanism,
- DBusGMethodInvocation *context)
-{
- GHashTable *settings;
-
- reset_killtimer (mechanism);
-
- if (!_check_polkit_for_action (mechanism, context, "server-settings"))
- return FALSE;
-
- settings = cph_cups_server_get_settings (mechanism->priv->cups);
- _cph_mechanism_return_error_and_value (mechanism, context,
- settings == NULL, settings);
-
- return TRUE;
-}
-
-gboolean
-cph_mechanism_server_set_settings (CphMechanism *mechanism,
- GHashTable *settings,
- DBusGMethodInvocation *context)
+cph_mechanism_printer_delete_option_default (CphMechanism *mechanism,
+ const char *name,
+ const char *option,
+ DBusGMethodInvocation *context)
{
gboolean ret;
reset_killtimer (mechanism);
- if (!_check_polkit_for_action (mechanism, context, "server-settings"))
+ if (!_check_polkit_for_printer_class (mechanism, context, name))
return FALSE;
- ret = cph_cups_server_set_settings (mechanism->priv->cups, settings);
+ ret = cph_cups_printer_class_set_option_default (mechanism->priv->cups,
+ name, option, NULL);
_cph_mechanism_return_error (mechanism, context, !ret);
return TRUE;
@@ -1166,29 +1192,3 @@ cph_mechanism_job_set_hold_until (CphMechanism *mechanism,
return TRUE;
}
-
-gboolean
-cph_mechanism_devices_get (CphMechanism *mechanism,
- int timeout,
- int limit,
- const char **include_schemes,
- const char **exclude_schemes,
- DBusGMethodInvocation *context)
-{
- GHashTable *devices;
-
- reset_killtimer (mechanism);
-
- if (!_check_polkit_for_action (mechanism, context, "devices-get"))
- return FALSE;
-
- devices = cph_cups_devices_get (mechanism->priv->cups,
- timeout,
- limit,
- include_schemes,
- exclude_schemes);
- _cph_mechanism_return_error_and_value (mechanism, context,
- devices == NULL, devices);
-
- return TRUE;
-}