]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/subscriptions.c
Rework idle exit fix after some discussion.
[thirdparty/cups.git] / scheduler / subscriptions.c
index 3ffb54659a6f67428a0e998c61c0f9e11f8540e6..0908f3c0cedc76a6f9ac88f561a9f46e47e0a38d 100644 (file)
@@ -1,37 +1,10 @@
 /*
- * "$Id: subscriptions.c 7824 2008-08-01 21:11:55Z mike $"
+ * Subscription routines for the CUPS scheduler.
  *
- *   Subscription routines for the CUPS scheduler.
+ * Copyright 2007-2019 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- *   cupsdAddEvent()               - Add an event to the global event cache.
- *   cupsdAddSubscription()        - Add a new subscription object.
- *   cupsdDeleteAllSubscriptions() - Delete all subscriptions.
- *   cupsdDeleteSubscription()     - Delete a subscription object.
- *   cupsdEventName()              - Return a single event name.
- *   cupsdEventValue()             - Return the event mask value for a name.
- *   cupsdExpireSubscriptions()    - Expire old subscription objects.
- *   cupsdFindSubscription()       - Find a subscription by ID.
- *   cupsdLoadAllSubscriptions()   - Load all subscriptions from the .conf file.
- *   cupsdSaveAllSubscriptions()   - Save all subscriptions to the .conf file.
- *   cupsdStopAllNotifiers()       - Stop all notifier processes.
- *   cupsd_compare_subscriptions() - Compare two subscriptions.
- *   cupsd_delete_event()          - Delete a single event...
- *   cupsd_send_dbus()             - Send a DBUS notification...
- *   cupsd_send_notification()     - Send a notification for the specified
- *                                   event.
- *   cupsd_start_notifier()        - Start a notifier subprocess...
- *   cupsd_update_notifier()       - Read messages from notifiers.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -126,9 +99,7 @@ cupsdAddEvent(
     * Check if this subscription requires this event...
     */
 
-    if ((sub->mask & event) != 0 &&
-        (sub->dest == dest || !sub->dest) &&
-       (sub->job == job || !sub->job))
+    if ((sub->mask & event) != 0 && (sub->dest == dest || !sub->dest || sub->job == job))
     {
      /*
       * Need this event, so create a new event record...
@@ -146,7 +117,11 @@ cupsdAddEvent(
       temp->time  = time(NULL);
       temp->attrs = ippNew();
       temp->job   = job;
-      temp->dest  = dest;
+
+      if (dest)
+        temp->dest = dest;
+      else if (job)
+        temp->dest = dest = cupsdFindPrinter(job->dest);
 
      /*
       * Add common event notification attributes...
@@ -208,7 +183,7 @@ cupsdAddEvent(
                        (const char * const *)dest->reasons);
 
        ippAddBoolean(temp->attrs, IPP_TAG_EVENT_NOTIFICATION,
-                     "printer-is-accepting-jobs", dest->accepting);
+                     "printer-is-accepting-jobs", (char)dest->accepting);
       }
 
       if (job)
@@ -673,9 +648,14 @@ cupsdExpireSubscriptions(
   time_t               curtime;        /* Current time */
 
 
+  if (cupsArrayCount(Subscriptions) == 0)
+    return;
+
   curtime = time(NULL);
   update  = 0;
 
+  cupsdLogMessage(CUPSD_LOG_INFO, "Expiring subscriptions...");
+
   for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
        sub;
        sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
@@ -941,9 +921,9 @@ cupsdLoadAllSubscriptions(void)
            if (isxdigit(valueptr[0]) && isxdigit(valueptr[1]))
            {
              if (isdigit(valueptr[0]))
-               sub->user_data[i] = (valueptr[0] - '0') << 4;
+               sub->user_data[i] = (unsigned char)((valueptr[0] - '0') << 4);
              else
-               sub->user_data[i] = (tolower(valueptr[0]) - 'a' + 10) << 4;
+               sub->user_data[i] = (unsigned char)((tolower(valueptr[0]) - 'a' + 10) << 4);
 
              if (isdigit(valueptr[1]))
                sub->user_data[i] |= valueptr[1] - '0';
@@ -962,7 +942,7 @@ cupsdLoadAllSubscriptions(void)
              break;
          }
          else
-           sub->user_data[i] = *valueptr++;
+           sub->user_data[i] = (unsigned char)*valueptr++;
        }
 
        if (*valueptr)
@@ -1631,8 +1611,3 @@ cupsd_update_notifier(void)
       break;
   }
 }
-
-
-/*
- * End of "$Id: subscriptions.c 7824 2008-08-01 21:11:55Z mike $".
- */