]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/subscriptions.c
Merge changes from CUPS 1.4svn-r7696.
[thirdparty/cups.git] / scheduler / subscriptions.c
index d0e05d9bec08e5c4b2324f40a967dd0114fa55a6..4f92f873b74662e955bc3418ab41ed8418145215 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: subscriptions.c 5991 2006-09-29 02:26:29Z mike $"
+ * "$Id: subscriptions.c 7673 2008-06-18 22:31:26Z mike $"
  *
  *   Subscription routines for the Common UNIX Printing System (CUPS) scheduler.
  *
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   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:
  *
  *   cupsdLoadAllSubscriptions()   - Load all subscriptions from the .conf file.
  *   cupsdSaveAllSubscriptions()   - Save all subscriptions to the .conf file.
  *   cupsdStopAllNotifiers()       - Stop all notifier processes.
- *   cupsdUpdateNotifierStatus()   - Read messages from notifiers.
  *   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.
  */
 
 /*
@@ -52,8 +43,8 @@
 #  include <dbus/dbus.h>
 #  ifdef HAVE_DBUS_MESSAGE_ITER_INIT_APPEND
 #    define dbus_message_append_iter_init dbus_message_iter_init_append
-#    define dbus_message_iter_append_string(i,v) dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, v)
-#    define dbus_message_iter_append_uint32(i,v) dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, v)
+#    define dbus_message_iter_append_string(i,v) dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &(v))
+#    define dbus_message_iter_append_uint32(i,v) dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &(v))
 #  endif /* HAVE_DBUS_MESSAGE_ITER_INIT_APPEND */
 #endif /* HAVE_DBUS */
 
@@ -73,6 +64,7 @@ static void   cupsd_send_dbus(cupsd_eventmask_t event, cupsd_printer_t *dest,
 static void    cupsd_send_notification(cupsd_subscription_t *sub,
                                        cupsd_event_t *event);
 static void    cupsd_start_notifier(cupsd_subscription_t *sub);
+static void    cupsd_update_notifier(void);
 
 
 /*
@@ -305,7 +297,7 @@ cupsdAddEvent(
   }
 
   if (temp)
-    cupsdSaveAllSubscriptions();
+    cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
   else
     cupsdLogMessage(CUPSD_LOG_DEBUG, "Discarding unused %s event...",
                     cupsdEventName(event));
@@ -331,7 +323,7 @@ cupsdAddSubscription(
                   "cupsdAddSubscription(mask=%x, dest=%p(%s), job=%p(%d), "
                  "uri=\"%s\")",
                   mask, dest, dest ? dest->name : "", job, job ? job->id : 0,
-                 uri);
+                 uri ? uri : "(null)");
 
   if (!Subscriptions)
     Subscriptions = cupsArrayNew((cups_array_func_t)cupsd_compare_subscriptions,
@@ -471,7 +463,7 @@ cupsdDeleteSubscription(
   */
 
   if (update)
-    cupsdSaveAllSubscriptions();
+    cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
 }
 
 
@@ -512,9 +504,14 @@ cupsdEventName(
     case CUPSD_EVENT_PRINTER_MODIFIED :
         return ("printer-modified");
 
+    case CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED :
+        return ("printer-queue-order-changed");
+
+    case CUPSD_EVENT_PRINTER_STATE :
     case CUPSD_EVENT_PRINTER_STATE_CHANGED :
         return ("printer-state-changed");
 
+    case CUPSD_EVENT_PRINTER_CONFIG :
     case CUPSD_EVENT_PRINTER_CONFIG_CHANGED :
         return ("printer-config-changed");
 
@@ -537,8 +534,6 @@ cupsdEventName(
         return ("job-progress");
 
     case CUPSD_EVENT_JOB_STATE :
-        return ("job-state");
-
     case CUPSD_EVENT_JOB_STATE_CHANGED :
         return ("job-state-changed");
 
@@ -585,14 +580,14 @@ cupsdEventValue(const char *name) /* I - Name of event */
     return (CUPSD_EVENT_PRINTER_DELETED);
   else if (!strcmp(name, "printer-modified"))
     return (CUPSD_EVENT_PRINTER_MODIFIED);
+  else if (!strcmp(name, "printer-queue-order-changed"))
+    return (CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED);
   else if (!strcmp(name, "printer-state-changed"))
     return (CUPSD_EVENT_PRINTER_STATE_CHANGED);
   else if (!strcmp(name, "printer-config-changed"))
     return (CUPSD_EVENT_PRINTER_CONFIG_CHANGED);
   else if (!strcmp(name, "printer-changed"))
     return (CUPSD_EVENT_PRINTER_CHANGED);
-  else if (!strcmp(name, "job-state"))
-    return (CUPSD_EVENT_JOB_STATE);
   else if (!strcmp(name, "job-created"))
     return (CUPSD_EVENT_JOB_CREATED);
   else if (!strcmp(name, "job-completed"))
@@ -651,7 +646,7 @@ cupsdExpireSubscriptions(
     }
 
   if (update)
-    cupsdSaveAllSubscriptions();
+    cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
 }
 
 
@@ -739,7 +734,7 @@ cupsdLoadAllSubscriptions(void)
         cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-        return;
+        break;
       }
     }
     else if (!strcasecmp(line, "</Subscription>"))
@@ -749,7 +744,7 @@ cupsdLoadAllSubscriptions(void)
         cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-        return;
+        break;
       }
 
       if (delete_sub)
@@ -763,7 +758,7 @@ cupsdLoadAllSubscriptions(void)
       cupsdLogMessage(CUPSD_LOG_ERROR,
                       "Syntax error on line %d of subscriptions.conf.",
                      linenum);
-      return;
+      break;
     }
     else if (!strcasecmp(line, "Events"))
     {
@@ -777,7 +772,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
 
       while (*value)
@@ -800,7 +795,7 @@ cupsdLoadAllSubscriptions(void)
          cupsdLogMessage(CUPSD_LOG_ERROR,
                          "Unknown event name \'%s\' on line %d of subscriptions.conf.",
                          value, linenum);
-         return;
+         break;
        }
 
        value = valueptr;
@@ -819,7 +814,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "Recipient"))
@@ -835,7 +830,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "JobId"))
@@ -859,7 +854,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "PrinterName"))
@@ -883,7 +878,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "UserData"))
@@ -945,7 +940,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "LeaseDuration"))
@@ -964,7 +959,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "Interval"))
@@ -980,7 +975,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "ExpirationTime"))
@@ -996,7 +991,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else if (!strcasecmp(line, "NextEventId"))
@@ -1012,7 +1007,7 @@ cupsdLoadAllSubscriptions(void)
        cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Syntax error on line %d of subscriptions.conf.",
                        linenum);
-       return;
+       break;
       }
     }
     else
@@ -1226,10 +1221,7 @@ cupsdStopAllNotifiers(void)
 
   if (NotifierPipes[0] >= 0)
   {
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "cupsdStopAllNotifiers: Removing fd %d from InputSet...",
-                   NotifierPipes[0]);
-    FD_CLR(NotifierPipes[0], InputSet);
+    cupsdRemoveSelect(NotifierPipes[0]);
 
     cupsdStatBufDelete(NotifierStatusBuffer);
 
@@ -1243,24 +1235,6 @@ cupsdStopAllNotifiers(void)
 }
 
 
-/*
- * 'cupsdUpdateNotifierStatus()' - Read messages from notifiers.
- */
-
-void
-cupsdUpdateNotifierStatus(void)
-{
-  char         message[1024];          /* Pointer to message text */
-  int          loglevel;               /* Log level for message */
-
-
-  while (cupsdStatBufUpdate(NotifierStatusBuffer, &loglevel,
-                            message, sizeof(message)))
-    if (!strchr(NotifierStatusBuffer->buffer, '\n'))
-      break;
-}
-
-
 /*
  * 'cupsd_compare_subscriptions()' - Compare two subscriptions.
  */
@@ -1362,11 +1336,11 @@ cupsd_send_dbus(cupsd_eventmask_t event,/* I - Event to send */
 
   dbus_message_append_iter_init(message, &iter);
   if (dest)
-    dbus_message_iter_append_string(&iter, &(dest->name));
+    dbus_message_iter_append_string(&iter, dest->name);
   if (job)
   {
-    dbus_message_iter_append_uint32(&iter, &(job->id));
-    dbus_message_iter_append_string(&iter, &(job->username));
+    dbus_message_iter_append_uint32(&iter, job->id);
+    dbus_message_iter_append_string(&iter, job->username);
   }
 
   dbus_connection_send(con, message, NULL);
@@ -1389,7 +1363,7 @@ cupsd_send_notification(
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsd_send_notification(sub=%p(%d), event=%p(%s))\n",
+                  "cupsd_send_notification(sub=%p(%d), event=%p(%s))",
                   sub, sub->id, event, cupsdEventName(event->event));
 
  /*
@@ -1571,11 +1545,8 @@ cupsd_start_notifier(
 
     NotifierStatusBuffer = cupsdStatBufNew(NotifierPipes[0], "[Notifier]");
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "start_notifier: Adding fd %d to InputSet...",
-                   NotifierPipes[0]);
-
-    FD_SET(NotifierPipes[0], InputSet);
+    cupsdAddSelect(NotifierPipes[0], (cupsd_selfunc_t)cupsd_update_notifier,
+                   NULL, NULL);
   }
 
   if (cupsdOpenPipe(fds))
@@ -1597,7 +1568,7 @@ cupsd_start_notifier(
   */
 
   if (cupsdStartProcess(command, argv, envp, fds[0], -1, NotifierPipes[1],
-                       -1, 0, &pid) < 0)
+                       -1, -1, 0, DefaultProfile, &pid) < 0)
   {
    /*
     * Error - can't fork!
@@ -1627,5 +1598,23 @@ cupsd_start_notifier(
 
 
 /*
- * End of "$Id: subscriptions.c 5991 2006-09-29 02:26:29Z mike $".
+ * 'cupsd_update_notifier()' - Read messages from notifiers.
+ */
+
+void
+cupsd_update_notifier(void)
+{
+  char         message[1024];          /* Pointer to message text */
+  int          loglevel;               /* Log level for message */
+
+
+  while (cupsdStatBufUpdate(NotifierStatusBuffer, &loglevel,
+                            message, sizeof(message)))
+    if (!strchr(NotifierStatusBuffer->buffer, '\n'))
+      break;
+}
+
+
+/*
+ * End of "$Id: subscriptions.c 7673 2008-06-18 22:31:26Z mike $".
  */