aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-03-20 18:28:05 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-03-20 18:28:05 +0100
commit5a35b6983ffa73000e26aa23714ce3625613ea79 (patch)
tree793ca03f3027e54aaeb0e05da7d779a9edf2a7e4 /src
parent05f0ede9aa38c7c274b8c23b5999f7906b3e39e6 (diff)
downloadayatana-indicator-printers-5a35b6983ffa73000e26aa23714ce3625613ea79.tar.gz
ayatana-indicator-printers-5a35b6983ffa73000e26aa23714ce3625613ea79.tar.bz2
ayatana-indicator-printers-5a35b6983ffa73000e26aa23714ce3625613ea79.zip
Set lease durations on cups subscription and renew periodically
This will stop indicator-printers-service from leaving stray subscriptions around when it doesn't exit gracefully. Fixes lp #959195.
Diffstat (limited to 'src')
-rw-r--r--src/indicator-printers-service.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/indicator-printers-service.c b/src/indicator-printers-service.c
index 5daf697..ad5ef88 100644
--- a/src/indicator-printers-service.c
+++ b/src/indicator-printers-service.c
@@ -26,6 +26,8 @@
#include "indicator-printers-menu.h"
#include "indicator-printer-state-notifier.h"
+#define NOTIFY_LEASE_DURATION (15 * 60)
+
static int
create_subscription ()
@@ -43,7 +45,7 @@ create_subscription ()
ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
"notify-recipient-uri", NULL, "dbus://");
ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
- "notify-lease-duration", 0);
+ "notify-lease-duration", NOTIFY_LEASE_DURATION);
resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
if (!resp || cupsLastError() != IPP_OK) {
@@ -64,6 +66,46 @@ create_subscription ()
}
+static gboolean
+renew_subscription (int id)
+{
+ ipp_t *req;
+ ipp_t *resp;
+
+ req = ippNewRequest (IPP_RENEW_SUBSCRIPTION);
+ ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
+ "notify-subscription-id", id);
+ ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
+ "printer-uri", NULL, "/");
+ ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
+ "notify-recipient-uri", NULL, "dbus://");
+ ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
+ "notify-lease-duration", NOTIFY_LEASE_DURATION);
+
+ resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
+ if (!resp || cupsLastError() != IPP_OK) {
+ g_warning ("Error renewing CUPS subscription %d: %s\n",
+ id, cupsLastErrorString ());
+ return FALSE;
+ }
+
+ ippDelete (resp);
+ return TRUE;
+}
+
+
+static gboolean
+renew_subscription_timeout (gpointer userdata)
+{
+ int *subscription_id = userdata;
+
+ if (*subscription_id <= 0 || !renew_subscription (*subscription_id))
+ *subscription_id = create_subscription ();
+
+ return TRUE;
+}
+
+
void
cancel_subscription (int id)
{
@@ -115,6 +157,9 @@ int main (int argc, char *argv[])
gtk_init (&argc, &argv);
subscription_id = create_subscription ();
+ g_timeout_add_seconds (NOTIFY_LEASE_DURATION - 60,
+ renew_subscription_timeout,
+ &subscription_id);
service = indicator_service_new_version (INDICATOR_PRINTERS_DBUS_NAME,
INDICATOR_PRINTERS_DBUS_VERSION);