diff options
author | Vincent Untz <vuntz@novell.com> | 2010-02-16 19:49:21 +0100 |
---|---|---|
committer | Vincent Untz <vuntz@novell.com> | 2010-02-16 19:49:21 +0100 |
commit | 534efdda6a53ee2beaa025e6dc89ea477e4a98e8 (patch) | |
tree | 2d3bf1909edfd8c9e7a9c2096dbbba4ca68f64b2 | |
parent | da98f819e8f8d2c8515073b364d997e509b6233e (diff) |
Move lots of code around
We regroup the functions that work at the same level together.
-rw-r--r-- | src/cups-pk-helper-mechanism.c | 422 | ||||
-rw-r--r-- | src/cups-pk-helper-mechanism.h | 112 | ||||
-rw-r--r-- | src/cups-pk-helper-mechanism.xml | 121 | ||||
-rw-r--r-- | src/cups.c | 730 | ||||
-rw-r--r-- | src/cups.h | 30 | ||||
-rw-r--r-- | src/org.opensuse.cupspkhelper.mechanism.policy.in | 36 |
6 files changed, 732 insertions, 719 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; -} diff --git a/src/cups-pk-helper-mechanism.h b/src/cups-pk-helper-mechanism.h index 4b800a6..03e579f 100644 --- a/src/cups-pk-helper-mechanism.h +++ b/src/cups-pk-helper-mechanism.h @@ -87,6 +87,23 @@ cph_mechanism_file_put (CphMechanism *mechanism, DBusGMethodInvocation *context); gboolean +cph_mechanism_server_get_settings (CphMechanism *mechanism, + DBusGMethodInvocation *context); + +gboolean +cph_mechanism_server_set_settings (CphMechanism *mechanism, + GHashTable *settings, + DBusGMethodInvocation *context); + +gboolean +cph_mechanism_devices_get (CphMechanism *mechanism, + int timeout, + int limit, + const char **include_schemes, + const char **exclude_schemes, + DBusGMethodInvocation *context); + +gboolean cph_mechanism_printer_add (CphMechanism *mechanism, const char *name, const char *uri, @@ -111,6 +128,45 @@ cph_mechanism_printer_set_device (CphMechanism *mechanism, DBusGMethodInvocation *context); gboolean +cph_mechanism_printer_set_default (CphMechanism *mechanism, + const char *name, + DBusGMethodInvocation *context); + +gboolean +cph_mechanism_printer_set_enabled (CphMechanism *mechanism, + const char *name, + gboolean enabled, + DBusGMethodInvocation *context); + + +gboolean +cph_mechanism_printer_set_accept_jobs (CphMechanism *mechanism, + const char *name, + gboolean enabled, + const char *reason, + DBusGMethodInvocation *context); + +gboolean +cph_mechanism_printer_delete (CphMechanism *mechanism, + const char *name, + DBusGMethodInvocation *context); + +gboolean +cph_mechanism_class_add_printer (CphMechanism *mechanism, + const char *name, + const char *printer, + DBusGMethodInvocation *context); +gboolean +cph_mechanism_class_delete_printer (CphMechanism *mechanism, + const char *name, + const char *printer, + DBusGMethodInvocation *context); +gboolean +cph_mechanism_class_delete (CphMechanism *mechanism, + const char *name, + DBusGMethodInvocation *context); + +gboolean cph_mechanism_printer_set_info (CphMechanism *mechanism, const char *name, const char *info, @@ -173,54 +229,6 @@ cph_mechanism_printer_delete_option_default (CphMechanism *mechanism, DBusGMethodInvocation *context); gboolean -cph_mechanism_printer_delete (CphMechanism *mechanism, - const char *name, - DBusGMethodInvocation *context); - -gboolean -cph_mechanism_class_add_printer (CphMechanism *mechanism, - const char *name, - const char *printer, - DBusGMethodInvocation *context); -gboolean -cph_mechanism_class_delete_printer (CphMechanism *mechanism, - const char *name, - const char *printer, - DBusGMethodInvocation *context); -gboolean -cph_mechanism_class_delete (CphMechanism *mechanism, - const char *name, - DBusGMethodInvocation *context); - -gboolean -cph_mechanism_printer_set_default (CphMechanism *mechanism, - const char *name, - DBusGMethodInvocation *context); - -gboolean -cph_mechanism_printer_set_enabled (CphMechanism *mechanism, - const char *name, - gboolean enabled, - DBusGMethodInvocation *context); - - -gboolean -cph_mechanism_printer_set_accept_jobs (CphMechanism *mechanism, - const char *name, - gboolean enabled, - const char *reason, - DBusGMethodInvocation *context); - -gboolean -cph_mechanism_server_get_settings (CphMechanism *mechanism, - DBusGMethodInvocation *context); - -gboolean -cph_mechanism_server_set_settings (CphMechanism *mechanism, - GHashTable *settings, - DBusGMethodInvocation *context); - -gboolean cph_mechanism_job_cancel (CphMechanism *mechanism, int id, DBusGMethodInvocation *context); @@ -236,14 +244,6 @@ cph_mechanism_job_set_hold_until (CphMechanism *mechanism, const char *job_hold_until, DBusGMethodInvocation *context); -gboolean -cph_mechanism_devices_get (CphMechanism *mechanism, - int timeout, - int limit, - const char **include_schemes, - const char **exclude_schemes, - DBusGMethodInvocation *context); - G_END_DECLS #endif /* CPH_MECHANISM_H */ diff --git a/src/cups-pk-helper-mechanism.xml b/src/cups-pk-helper-mechanism.xml index b7b9b6e..b911ff1 100644 --- a/src/cups-pk-helper-mechanism.xml +++ b/src/cups-pk-helper-mechanism.xml @@ -2,6 +2,8 @@ <node name="/"> <interface name="org.opensuse.CupsPkHelper.Mechanism"> + <!-- Very low-level methods --> + <method name="FileGet"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="resource" direction="in" type="s"/> @@ -16,6 +18,32 @@ <arg name="error" direction="out" type="s"/> </method> + <!-- Methods for the server in general --> + + <method name="ServerGetSettings"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="error" direction="out" type="s"/> + <arg name="settings" direction="out" type="a{ss}"/> + </method> + + <method name="ServerSetSettings"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="settings" direction="in" type="a{ss}"/> + <arg name="error" direction="out" type="s"/> + </method> + + <method name="DevicesGet"> + <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="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> + + <!-- Methods for printers --> + <method name="PrinterAdd"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> @@ -43,136 +71,130 @@ <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetInfo"> + <method name="PrinterSetDefault"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="info" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetLocation"> + <method name="PrinterSetEnabled"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="location" direction="in" type="s"/> + <arg name="enabled" direction="in" type="b"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetShared"> + <method name="PrinterSetAcceptJobs"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="shared" direction="in" type="b"/> + <arg name="enabled" direction="in" type="b"/> + <arg name="reason" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetJobSheets"> + <method name="PrinterDelete"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="start" direction="in" type="s"/> - <arg name="end" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetErrorPolicy"> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <arg name="name" direction="in" type="s"/> - <arg name="policy" direction="in" type="s"/> - <arg name="error" direction="out" type="s"/> - </method> + <!-- Methods for classes --> - <method name="PrinterSetOpPolicy"> + <method name="ClassAddPrinter"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="policy" direction="in" type="s"/> + <arg name="printer" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetUsersAllowed"> + <method name="ClassDeletePrinter"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="users" direction="in" type="as"/> + <arg name="printer" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetUsersDenied"> + <method name="ClassDelete"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="users" direction="in" type="as"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterAddOptionDefault"> + <!-- Methods for printers or classes --> + + <method name="PrinterSetInfo"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="option" direction="in" type="s"/> - <arg name="values" direction="in" type="as"/> + <arg name="info" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterDeleteOptionDefault"> + <method name="PrinterSetLocation"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="option" direction="in" type="s"/> + <arg name="location" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterDelete"> + <method name="PrinterSetShared"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> + <arg name="shared" direction="in" type="b"/> <arg name="error" direction="out" type="s"/> </method> - <method name="ClassAddPrinter"> + <method name="PrinterSetJobSheets"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="printer" direction="in" type="s"/> + <arg name="start" direction="in" type="s"/> + <arg name="end" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="ClassDeletePrinter"> + <method name="PrinterSetErrorPolicy"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="printer" direction="in" type="s"/> + <arg name="policy" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="ClassDelete"> + <method name="PrinterSetOpPolicy"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> + <arg name="policy" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetDefault"> + <method name="PrinterSetUsersAllowed"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> + <arg name="users" direction="in" type="as"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetEnabled"> + <method name="PrinterSetUsersDenied"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="enabled" direction="in" type="b"/> + <arg name="users" direction="in" type="as"/> <arg name="error" direction="out" type="s"/> </method> - <method name="PrinterSetAcceptJobs"> + <method name="PrinterAddOptionDefault"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="name" direction="in" type="s"/> - <arg name="enabled" direction="in" type="b"/> - <arg name="reason" direction="in" type="s"/> + <arg name="option" direction="in" type="s"/> + <arg name="values" direction="in" type="as"/> <arg name="error" direction="out" type="s"/> </method> - <method name="ServerGetSettings"> + <method name="PrinterDeleteOptionDefault"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="name" direction="in" type="s"/> + <arg name="option" direction="in" type="s"/> <arg name="error" direction="out" type="s"/> - <arg name="settings" direction="out" type="a{ss}"/> </method> - <method name="ServerSetSettings"> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <arg name="settings" direction="in" type="a{ss}"/> - <arg name="error" direction="out" type="s"/> - </method> + <!-- Methods for jobs --> <method name="JobCancel"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> @@ -193,14 +215,5 @@ <arg name="error" direction="out" type="s"/> </method> - <method name="DevicesGet"> - <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="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> </interface> </node> @@ -1010,6 +1010,371 @@ cph_cups_file_put (CphCups *cups, cups->priv->last_status == HTTP_CREATED); } +/* Functions that are for the server in general */ + +GHashTable * +cph_cups_server_get_settings (CphCups *cups) +{ + int retval; + GHashTable *hash; + cups_option_t *settings; + int num_settings, i; + + g_return_val_if_fail (CPH_IS_CUPS (cups), NULL); + + retval = cupsAdminGetServerSettings (cups->priv->connection, + &num_settings, &settings); + + if (retval == 0) { + _cph_cups_set_internal_status (cups, + "Cannot get server settings."); + + return NULL; + } + + hash = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, g_free); + + for (i = 0; i < num_settings; i++) + g_hash_table_replace (hash, + g_strdup (settings[i].name), + g_strdup (settings[i].value)); + + cupsFreeOptions (num_settings, settings); + + return hash; +} + +gboolean +cph_cups_server_set_settings (CphCups *cups, + GHashTable *settings) +{ + int retval; + GHashTableIter iter; + /* key and value are strings, but we want to avoid compiler warnings */ + gpointer key; + gpointer value; + cups_option_t *cups_settings; + int num_settings; + + g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE); + g_return_val_if_fail (settings != NULL, FALSE); + + /* First pass to check the validity of the hashtable content */ + g_hash_table_iter_init (&iter, settings); + while (g_hash_table_iter_next (&iter, &key, &value)) { + if (!_cph_cups_is_option_valid (cups, key)) + return FALSE; + if (!_cph_cups_is_option_value_valid (cups, value)) + return FALSE; + } + + /* Second pass to actually set the settings */ + cups_settings = NULL; + num_settings = 0; + + g_hash_table_iter_init (&iter, settings); + while (g_hash_table_iter_next (&iter, &key, &value)) + num_settings = cupsAddOption (key, value, + num_settings, &cups_settings); + + retval = cupsAdminSetServerSettings (cups->priv->connection, + num_settings, cups_settings); + + /* CUPS is being restarted, so we need to reconnect */ + cph_cups_reconnect (cups); + + cupsFreeOptions (num_settings, cups_settings); + + if (retval == 0) { + _cph_cups_set_internal_status (cups, + "Cannot set server settings."); + + return FALSE; + } + + return TRUE; +} + +typedef struct { + int iter; + int limit; + GHashTable *hash; +} CphCupsGetDevices; + +static void +_cph_cups_get_devices_cb (const char *device_class, + const char *device_id, + const char *device_info, + const char *device_make_and_model, + const char *device_uri, + const char *device_location, + void *user_data) +{ + CphCupsGetDevices *data = user_data; + + g_return_if_fail (data != NULL); + + if (data->limit > 0 && data->iter >= data->limit) + return; + + if (device_class && device_class[0] != '\0') + g_hash_table_replace (data->hash, + g_strdup_printf ("device-class:%d", + data->iter), + g_strdup (device_class)); + if (device_id && device_id[0] != '\0') + g_hash_table_replace (data->hash, + g_strdup_printf ("device-id:%d", + data->iter), + g_strdup (device_id)); + if (device_info && device_info[0] != '\0') + g_hash_table_replace (data->hash, + g_strdup_printf ("device-info:%d", + data->iter), + g_strdup (device_info)); + if (device_make_and_model && device_make_and_model[0] != '\0') + g_hash_table_replace (data->hash, + g_strdup_printf ("device-make-and-model:%d", + data->iter), + g_strdup (device_make_and_model)); + if (device_uri && device_uri[0] != '\0') + g_hash_table_replace (data->hash, + g_strdup_printf ("device-uri:%d", + data->iter), + g_strdup (device_uri)); + if (device_location && device_location[0] != '\0') + g_hash_table_replace (data->hash, + g_strdup_printf ("device-location:%d ", + data->iter), + g_strdup (device_location)); + + data->iter++; +} + +#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1 +static gboolean +_cph_cups_devices_get_14 (CphCups *cups, + int timeout, + int limit, + const char **include_schemes, + const char **exclude_schemes, + int len_include, + int len_exclude, + CphCupsGetDevices *data) +{ + ipp_status_t retval; + int timeout_param = CUPS_TIMEOUT_DEFAULT; + char *include_schemes_param; + char *exclude_schemes_param; + + if (timeout > 0) + timeout_param = timeout; + + 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 && 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, + include_schemes_param, + exclude_schemes_param, + _cph_cups_get_devices_cb, + data); + + g_free (include_schemes_param); + g_free (exclude_schemes_param); + + if (retval != IPP_OK) { + _cph_cups_set_internal_status (cups, + "Cannot get devices."); + return FALSE; + } + + return TRUE; +} +#else +static gboolean +_cph_cups_devices_get_old (CphCups *cups, + int timeout, + int limit, + const char **include_schemes, + const char **exclude_schemes, + int len_include, + int len_exclude, + CphCupsGetDevices *data) +{ + ipp_t *request; + const char *resource_char; + ipp_t *reply; + ipp_attribute_t *attr; + const char *device_class; + const char *device_id; + const char *device_info; + const char *device_location; + const char *device_make_and_model; + const char *device_uri; + + request = ippNewRequest (CUPS_GET_DEVICES); + + if (timeout > 0) + ippAddInteger (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, + "timeout", timeout); + if (limit > 0) + ippAddInteger (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, + "limit", limit); + + if (include_schemes && len_include > 0) { + int i; + + attr = ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_NAME, + "include-schemes", len_include, NULL, NULL); + for (i = 0; i < len_include; i++) + attr->values[i].string.text = g_strdup (include_schemes[i]); + } + + if (exclude_schemes && len_exclude > 0) { + int i; + + attr = ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_NAME, + "exclude-schemes", len_exclude, NULL, NULL); + for (i = 0; i < len_exclude; i++) + attr->values[i].string.text = g_strdup (exclude_schemes[i]); + } + + resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT); + reply = cupsDoRequest (cups->priv->connection, + request, resource_char); + + if (!reply || reply->request.status.status_code > IPP_OK_CONFLICT) { + _cph_cups_set_error_from_reply (cups, reply); + return FALSE; + } + + for (attr = reply->attrs; attr; attr = attr->next) { + while (attr && attr->group_tag != IPP_TAG_PRINTER) + attr = attr->next; + + if (attr == NULL) + break; + + device_class = NULL; + device_id = NULL; + device_info = NULL; + device_location = NULL; + device_make_and_model = NULL; + device_uri = NULL; + + while (attr && attr->group_tag == IPP_TAG_PRINTER) { + if (attr->name == NULL) + /* nothing, just skip */; + else if (strcmp (attr->name, "device-class") == 0 && + attr->value_tag == IPP_TAG_KEYWORD) + device_class = g_strdup (attr->values[0].string.text); + else if (strcmp (attr->name, "device-id") == 0 && + attr->value_tag == IPP_TAG_TEXT) + device_id = g_strdup (attr->values[0].string.text); + else if (strcmp (attr->name, "device-info") == 0 && + attr->value_tag == IPP_TAG_TEXT) + device_info = g_strdup (attr->values[0].string.text); + else if (strcmp (attr->name, "device-location") == 0 && + attr->value_tag == IPP_TAG_TEXT) + device_location = g_strdup (attr->values[0].string.text); + else if (strcmp (attr->name, "device-make-and-model") == 0 && + attr->value_tag == IPP_TAG_TEXT) + device_make_and_model = g_strdup (attr->values[0].string.text); + else if (strcmp (attr->name, "device-uri") == 0 && + attr->value_tag == IPP_TAG_URI) + device_uri = g_strdup (attr->values[0].string.text); + + attr = attr->next; + } + + if (device_uri) + _cph_cups_get_devices_cb (device_class, + device_id, + device_info, + device_make_and_model, + device_uri, + device_location, + data); + + if (attr == NULL) + break; + } + + ippDelete (reply); + + return TRUE; +} +#endif + +GHashTable * +cph_cups_devices_get (CphCups *cups, + int timeout, + int limit, + const char **include_schemes, + const char **exclude_schemes) +{ + CphCupsGetDevices data; + int len_include; + int len_exclude; + gboolean retval; + + 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, + g_free, g_free); + if (limit > 0) + data.limit = limit; + +#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1 + retval = _cph_cups_devices_get_14 (cups, timeout, limit, + include_schemes, exclude_schemes, + len_include, len_exclude, + &data); +#else + retval = _cph_cups_devices_get_old (cups, timeout, limit, + include_schemes, exclude_schemes, + len_include, len_exclude, + &data); +#endif + + if (retval) + return data.hash; + else { + g_hash_table_destroy (data.hash); + return NULL; + } +} + /* Functions that work on a printer */ gboolean @@ -1667,92 +2032,6 @@ out: return retval; } -/* Functions that are for the server in general */ - -GHashTable * -cph_cups_server_get_settings (CphCups *cups) -{ - int retval; - GHashTable *hash; - cups_option_t *settings; - int num_settings, i; - - g_return_val_if_fail (CPH_IS_CUPS (cups), NULL); - - retval = cupsAdminGetServerSettings (cups->priv->connection, - &num_settings, &settings); - - if (retval == 0) { - _cph_cups_set_internal_status (cups, - "Cannot get server settings."); - - return NULL; - } - - hash = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, g_free); - - for (i = 0; i < num_settings; i++) - g_hash_table_replace (hash, - g_strdup (settings[i].name), - g_strdup (settings[i].value)); - - cupsFreeOptions (num_settings, settings); - - return hash; -} - -gboolean -cph_cups_server_set_settings (CphCups *cups, - GHashTable *settings) -{ - int retval; - GHashTableIter iter; - /* key and value are strings, but we want to avoid compiler warnings */ - gpointer key; - gpointer value; - cups_option_t *cups_settings; - int num_settings; - - g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE); - g_return_val_if_fail (settings != NULL, FALSE); - - /* First pass to check the validity of the hashtable content */ - g_hash_table_iter_init (&iter, settings); - while (g_hash_table_iter_next (&iter, &key, &value)) { - if (!_cph_cups_is_option_valid (cups, key)) - return FALSE; - if (!_cph_cups_is_option_value_valid (cups, value)) - return FALSE; - } - - /* Second pass to actually set the settings */ - cups_settings = NULL; - num_settings = 0; - - g_hash_table_iter_init (&iter, settings); - while (g_hash_table_iter_next (&iter, &key, &value)) - num_settings = cupsAddOption (key, value, - num_settings, &cups_settings); - - retval = cupsAdminSetServerSettings (cups->priv->connection, - num_settings, cups_settings); - - /* CUPS is being restarted, so we need to reconnect */ - cph_cups_reconnect (cups); - - cupsFreeOptions (num_settings, cups_settings); - - if (retval == 0) { - _cph_cups_set_internal_status (cups, - "Cannot set server settings."); - - return FALSE; - } - - return TRUE; -} - /* Functions that work on jobs */ gboolean @@ -1844,285 +2123,6 @@ cph_cups_job_get_status (CphCups *cups, return status; } -typedef struct { - int iter; - int limit; - GHashTable *hash; -} CphCupsGetDevices; - -static void -_cph_cups_get_devices_cb (const char *device_class, - const char *device_id, - const char *device_info, - const char *device_make_and_model, - const char *device_uri, - const char *device_location, - void *user_data) -{ - CphCupsGetDevices *data = user_data; - - g_return_if_fail (data != NULL); - - if (data->limit > 0 && data->iter >= data->limit) - return; - - if (device_class && device_class[0] != '\0') - g_hash_table_replace (data->hash, - g_strdup_printf ("device-class:%d", - data->iter), - g_strdup (device_class)); - if (device_id && device_id[0] != '\0') - g_hash_table_replace (data->hash, - g_strdup_printf ("device-id:%d", - data->iter), - g_strdup (device_id)); - if (device_info && device_info[0] != '\0') - g_hash_table_replace (data->hash, - g_strdup_printf ("device-info:%d", - data->iter), - g_strdup (device_info)); - if (device_make_and_model && device_make_and_model[0] != '\0') - g_hash_table_replace (data->hash, - g_strdup_printf ("device-make-and-model:%d", - data->iter), - g_strdup (device_make_and_model)); - if (device_uri && device_uri[0] != '\0') - g_hash_table_replace (data->hash, - g_strdup_printf ("device-uri:%d", - data->iter), - g_strdup (device_uri)); - if (device_location && device_location[0] != '\0') - g_hash_table_replace (data->hash, - g_strdup_printf ("device-location:%d ", - data->iter), - g_strdup (device_location)); - - data->iter++; -} - -#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1 -static gboolean -_cph_cups_devices_get_14 (CphCups *cups, - int timeout, - int limit, - const char **include_schemes, - const char **exclude_schemes, - int len_include, - int len_exclude, - CphCupsGetDevices *data) -{ - ipp_status_t retval; - int timeout_param = CUPS_TIMEOUT_DEFAULT; - char *include_schemes_param; - char *exclude_schemes_param; - - if (timeout > 0) - timeout_param = timeout; - - 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 && 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, - include_schemes_param, - exclude_schemes_param, - _cph_cups_get_devices_cb, - data); - - g_free (include_schemes_param); - g_free (exclude_schemes_param); - - if (retval != IPP_OK) { - _cph_cups_set_internal_status (cups, - "Cannot get devices."); - return FALSE; - } - - return TRUE; -} -#else -static gboolean -_cph_cups_devices_get_old (CphCups *cups, - int timeout, - int limit, - const char **include_schemes, - const char **exclude_schemes, - int len_include, - int len_exclude, - CphCupsGetDevices *data) -{ - ipp_t *request; - const char *resource_char; - ipp_t *reply; - ipp_attribute_t *attr; - const char *device_class; - const char *device_id; - const char *device_info; - const char *device_location; - const char *device_make_and_model; - const char *device_uri; - - request = ippNewRequest (CUPS_GET_DEVICES); - - if (timeout > 0) - ippAddInteger (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, - "timeout", timeout); - if (limit > 0) - ippAddInteger (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, - "limit", limit); - - if (include_schemes && len_include > 0) { - int i; - - attr = ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_NAME, - "include-schemes", len_include, NULL, NULL); - for (i = 0; i < len_include; i++) - attr->values[i].string.text = g_strdup (include_schemes[i]); - } - - if (exclude_schemes && len_exclude > 0) { - int i; - - attr = ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_NAME, - "exclude-schemes", len_exclude, NULL, NULL); - for (i = 0; i < len_exclude; i++) - attr->values[i].string.text = g_strdup (exclude_schemes[i]); - } - - resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT); - reply = cupsDoRequest (cups->priv->connection, - request, resource_char); - - if (!reply || reply->request.status.status_code > IPP_OK_CONFLICT) { - _cph_cups_set_error_from_reply (cups, reply); - return FALSE; - } - - for (attr = reply->attrs; attr; attr = attr->next) { - while (attr && attr->group_tag != IPP_TAG_PRINTER) - attr = attr->next; - - if (attr == NULL) - break; - - device_class = NULL; - device_id = NULL; - device_info = NULL; - device_location = NULL; - device_make_and_model = NULL; - device_uri = NULL; - - while (attr && attr->group_tag == IPP_TAG_PRINTER) { - if (attr->name == NULL) - /* nothing, just skip */; - else if (strcmp (attr->name, "device-class") == 0 && - attr->value_tag == IPP_TAG_KEYWORD) - device_class = g_strdup (attr->values[0].string.text); - else if (strcmp (attr->name, "device-id") == 0 && - attr->value_tag == IPP_TAG_TEXT) - device_id = g_strdup (attr->values[0].string.text); - else if (strcmp (attr->name, "device-info") == 0 && - attr->value_tag == IPP_TAG_TEXT) - device_info = g_strdup (attr->values[0].string.text); - else if (strcmp (attr->name, "device-location") == 0 && - attr->value_tag == IPP_TAG_TEXT) - device_location = g_strdup (attr->values[0].string.text); - else if (strcmp (attr->name, "device-make-and-model") == 0 && - attr->value_tag == IPP_TAG_TEXT) - device_make_and_model = g_strdup (attr->values[0].string.text); - else if (strcmp (attr->name, "device-uri") == 0 && - attr->value_tag == IPP_TAG_URI) - device_uri = g_strdup (attr->values[0].string.text); - - attr = attr->next; - } - - if (device_uri) - _cph_cups_get_devices_cb (device_class, - device_id, - device_info, - device_make_and_model, - device_uri, - device_location, - data); - - if (attr == NULL) - break; - } - - ippDelete (reply); - - return TRUE; -} -#endif - -GHashTable * -cph_cups_devices_get (CphCups *cups, - int timeout, - int limit, - const char **include_schemes, - const char **exclude_schemes) -{ - CphCupsGetDevices data; - int len_include; - int len_exclude; - gboolean retval; - - 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, - g_free, g_free); - if (limit > 0) - data.limit = limit; - -#if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1 - retval = _cph_cups_devices_get_14 (cups, timeout, limit, - include_schemes, exclude_schemes, - len_include, len_exclude, - &data); -#else - retval = _cph_cups_devices_get_old (cups, timeout, limit, - include_schemes, exclude_schemes, - len_include, len_exclude, - &data); -#endif - - if (retval) - return data.hash; - else { - g_hash_table_destroy (data.hash); - return NULL; - } -} - /****************************************************** * Non-object functions ******************************************************/ @@ -67,6 +67,9 @@ gboolean cph_cups_is_class (CphCups *cups, char *cph_cups_printer_get_uri (CphCups *cups, const char *printer_name); +gboolean cph_cups_is_printer_local (CphCups *cups, + const char *printer_name); + gboolean cph_cups_file_get (CphCups *cups, const char *resource, const char *filename); @@ -75,6 +78,17 @@ gboolean cph_cups_file_put (CphCups *cups, const char *resource, const char *filename); +GHashTable *cph_cups_server_get_settings (CphCups *cups); + +gboolean cph_cups_server_set_settings (CphCups *cups, + GHashTable *settings); + +GHashTable *cph_cups_devices_get (CphCups *cups, + int timeout, + int limit, + const char **include_schemes, + const char **exclude_schemes); + gboolean cph_cups_printer_add (CphCups *cups, const char *printer_name, const char *printer_uri, @@ -157,16 +171,6 @@ gboolean cph_cups_printer_class_set_option_default (CphCups *cups, const char *option, const char **values); -GHashTable *cph_cups_server_get_settings (CphCups *cups); - -gboolean cph_cups_server_set_settings (CphCups *cups, - GHashTable *settings); - -gboolean cph_cups_is_printer_local (CphCups *cups, - const char *printer_name); - -gboolean cph_cups_is_printer_uri_local (const char *uri); - gboolean cph_cups_job_cancel (CphCups *cups, int job_id, const char *user_name); @@ -184,11 +188,7 @@ 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); +gboolean cph_cups_is_printer_uri_local (const char *uri); G_END_DECLS diff --git a/src/org.opensuse.cupspkhelper.mechanism.policy.in b/src/org.opensuse.cupspkhelper.mechanism.policy.in index de6abab..858d329 100644 --- a/src/org.opensuse.cupspkhelper.mechanism.policy.in +++ b/src/org.opensuse.cupspkhelper.mechanism.policy.in @@ -8,6 +8,24 @@ <vendor_url>http://www.opensuse.org/</vendor_url> <icon_name>printer</icon_name> + <action id="org.opensuse.cupspkhelper.mechanism.server-settings"> + <_description>Get/Set server settings</_description> + <_message>Privileges are required to get/set server settings.</_message> + <defaults> + <allow_inactive>no</allow_inactive> + <allow_active>auth_admin</allow_active> + </defaults> + </action> + + <action id="org.opensuse.cupspkhelper.mechanism.devices-get"> + <_description>Get devices</_description> + <_message>Privileges are required to get devices.</_message> + <defaults> + <allow_inactive>no</allow_inactive> + <allow_active>auth_admin</allow_active> + </defaults> + </action> + <!-- Exists mainly so that it's possible to not require a password for this operation: if some authorization is required, then the PolicyKit helper will fallback on printer-X-edit. --> @@ -59,15 +77,6 @@ </defaults> </action> - <action id="org.opensuse.cupspkhelper.mechanism.server-settings"> - <_description>Get/Set server settings</_description> - <_message>Privileges are required to get/set server settings.</_message> - <defaults> - <allow_inactive>no</allow_inactive> - <allow_active>auth_admin</allow_active> - </defaults> - </action> - <action id="org.opensuse.cupspkhelper.mechanism.job-edit"> <_description>Restart/Cancel/Edit a job</_description> <_message>Privileges are required to restart/cancel/edit a job.</_message> @@ -86,15 +95,6 @@ </defaults> </action> - <action id="org.opensuse.cupspkhelper.mechanism.devices-get"> - <_description>Get devices</_description> - <_message>Privileges are required to get devices.</_message> - <defaults> - <allow_inactive>no</allow_inactive> - <allow_active>auth_admin</allow_active> - </defaults> - </action> - <!-- Deprecated --> <action id="org.opensuse.cupspkhelper.mechanism.printeraddremove"> <_description>Add/Remove/Edit a printer</_description> |