]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Merge Apple changes to pap backend and lpstat command (to show printer-state-reasons)
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 18 Jun 2007 21:09:03 +0000 (21:09 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 18 Jun 2007 21:09:03 +0000 (21:09 +0000)
More launchd changes.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@6559 7a7537e8-13f0-0310-91df-b6672ffda945

backend/pap.c
init/org.cups.cups-lpd.plist
init/org.cups.cupsd.plist
systemv/lpstat.c

index bc7e0e17bd587db54d775988296c6518a02bc893..bd43f6c9c2eb664baad6302b65142915dba51fe5 100644 (file)
 *
 * Contents:
 *
-*  main()              - Send a file to the specified Appletalk printer.
-*  listDevices()       - List all LaserWriter printers in the local zone.
-*  printFile()         - Print file.
-*  papOpen()           - Open a pap session to a printer.
-*  papClose()          - Close a pap session.
-*  papWrite()          - Write bytes to a printer.
-*  papCloseResp()      - Send a pap close response.
-*  papSendRequest()    - Fomrat and send a pap packet.
-*  papCancelRequest()  - Cancel a pending pap request.
-*  statusUpdate()      - Print printer status to stderr.
-*  parseUri()          - Extract the print name and zone from a uri.
-*  addPercentEscapes() - Encode a string with percent escapes.
-*  removePercentEscapes        - Remove percent escape sequences from a string.
-*  nbptuple_compare()  - Compare routine for qsort.
-*  okayToUseAppleTalk() - Returns true if AppleTalk is available and enabled.
-*  packet_name()       - Returns packet name string.
-*  connectTimeout()    - Returns the connect timeout preference value.
-*  signalHandler()     - handle SIGINT to close the session before quiting.
+*  main()               - Send a file to the specified Appletalk printer.
+*  listDevices()        - List all LaserWriter printers in the local zone.
+*  printFile()          - Print file.
+*  papOpen()            - Open a pap session to a printer.
+*  papClose()           - Close a pap session.
+*  papWrite()           - Write bytes to a printer.
+*  papCloseResp()       - Send a pap close response.
+*  papSendRequest()     - Fomrat and send a pap packet.
+*  papCancelRequest()   - Cancel a pending pap request.
+*  sidechannel_request() - Handle side-channel requests.
+*  statusUpdate()       - Print printer status to stderr.
+*  parseUri()           - Extract the print name and zone from a uri.
+*  addPercentEscapes()  - Encode a string with percent escapes.
+*  removePercentEscapes         - Remove percent escape sequences from a string.
+*  nbptuple_compare()   - Compare routine for qsort.
+*  okayToUseAppleTalk()  - Returns true if AppleTalk is available and enabled.
+*  packet_name()        - Returns packet name string.
+*  connectTimeout()     - Returns the connect timeout preference value.
+*  signalHandler()      - handle SIGINT to close the session before quiting.
 */
 
 #include <config.h>
@@ -92,6 +93,8 @@
 
 #include <cups/cups.h>
 #include <cups/backend.h>
+#include <cups/sidechannel.h>
+#include <cups/i18n.h>
 
 #include <libkern/OSByteOrder.h>
 
@@ -167,6 +170,7 @@ static int papCloseResp(int sockfd, at_inet_t* dest, int xo, u_short tid,
 static int papSendRequest(int sockfd, at_inet_t* dest, u_char connID, 
                          int function, u_char bitmap, int xo, int seqno);
 static int papCancelRequest(int sockfd, u_short tid);
+static void sidechannel_request();
 static void statusUpdate(char* status, u_char statusLen);
 static int parseUri(const char* argv0, char* name, char* type, char* zone);
 static int addPercentEscapes(const char* src, char* dst, int dstMax);
@@ -392,6 +396,7 @@ static int printFile(char* name, char* type, char* zone, int fdin, int fdout, in
   char sockBuffer[4096 + 1];    /* Socket buffer with room for nul */
   char atpReqBuf[AT_PAP_DATA_SIZE];
   fd_set readSet;
+  int  use_sidechannel;        /* Use side channel? */
 
   at_nbptuple_t        tuple;
   at_inet_t    sendDataAddr;
@@ -418,6 +423,22 @@ static int printFile(char* name, char* type, char* zone, int fdin, int fdout, in
   struct sigaction action;  /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
 
+ /*
+  * Test the side channel descriptor before calling papOpen() since it may open
+  * an unused fd 4 (a.k.a. CUPS_SC_FD)...
+  */
+
+  FD_ZERO(&readSet);
+  FD_SET(CUPS_SC_FD, &readSet);
+
+  timeout.tv_sec  = 0;
+  timeout.tv_usec = 0;
+
+  if ((select(CUPS_SC_FD+1, &readSet, NULL, NULL, &timeout)) >= 0)
+    use_sidechannel = 1;
+  else
+    use_sidechannel = 0;
+
   /* try to find our printer */
   if ((err = nbp_make_entity(&entity, name, type, zone)) != noErr)
   {
@@ -559,8 +580,12 @@ static int printFile(char* name, char* type, char* zone, int fdin, int fdout, in
   fileBufferNbytes = 0;
   fileTbytes = 0;
   fileEOFRead = fileEOFSent = false;
+
   maxfdp1 = MAX(fdin, gSockfd) + 1;
 
+  if (use_sidechannel && CUPS_SC_FD >= maxfdp1)
+    maxfdp1 = CUPS_SC_FD + 1;
+
   if (gStatusInterval != 0)
   {
     timeout.tv_usec  = 0;
@@ -580,6 +605,9 @@ static int printFile(char* name, char* type, char* zone, int fdin, int fdout, in
     if (fileBufferNbytes == 0 && fileEOFRead == false)
       FD_SET(fdin, &readSet);
 
+    if (use_sidechannel)
+      FD_SET(CUPS_SC_FD, &readSet);
+
     /* Set the select timeout value based on the next status interval */
     if (gStatusInterval != 0)
     {
@@ -604,6 +632,13 @@ static int printFile(char* name, char* type, char* zone, int fdin, int fdout, in
         nextStatusTime = time(NULL) + gStatusInterval;
     }
 
+   /*
+    * Check if we have a side-channel request ready...
+    */
+
+    if (use_sidechannel && FD_ISSET(CUPS_SC_FD, &readSet))
+      sidechannel_request();
+
     /* Was there an event on the input stream? */
     if (FD_ISSET(fdin, &readSet))
     {
@@ -1229,6 +1264,50 @@ int papCancelRequest(int sockfd, u_short tid)
 }
 
 
+/*
+ * 'sidechannel_request()' - Handle side-channel requests.
+ */
+
+static void
+sidechannel_request()
+{
+  cups_sc_command_t    command;        /* Request command */
+  cups_sc_status_t     status;         /* Request/response status */
+  char                 data[2048];     /* Request/response data */
+  int                  datalen;        /* Request/response data size */
+
+  datalen = sizeof(data);
+
+  if (cupsSideChannelRead(&command, &status, data, &datalen, 1.0))
+  {
+    fputs(_("WARNING: Failed to read side-channel request!\n"), stderr);
+    return;
+  }
+
+  switch (command)
+  {
+    case CUPS_SC_CMD_GET_BIDI:         /* Is the connection bidirectional? */
+       data[0] = 1;
+       cupsSideChannelWrite(command, CUPS_SC_STATUS_OK, data, 1, 1.0);
+       break;
+
+    case CUPS_SC_CMD_GET_STATE:                /* Return device state */
+       data[0] = CUPS_SC_STATE_ONLINE;
+       cupsSideChannelWrite(command, CUPS_SC_STATUS_OK, data, 1, 1.0);
+       break;
+
+    case CUPS_SC_CMD_DRAIN_OUTPUT:     /* Drain all pending output */
+    case CUPS_SC_CMD_SOFT_RESET:       /* Do a soft reset */
+    case CUPS_SC_CMD_GET_DEVICE_ID:    /* Return IEEE-1284 device ID */
+    default:
+       cupsSideChannelWrite(command, CUPS_SC_STATUS_NOT_IMPLEMENTED, 
+                            NULL, 0, 1.0);
+       break;
+  }
+  return;
+}
+
+
 #pragma mark -
 /*!
  * @function  statusUpdate
index f768e333884b55041c8b57d6012ce1028fce8f1d..9020d067ee0fe95fee77c6eacadd9a23096b51de 100644 (file)
@@ -12,6 +12,8 @@
                <string>-o</string>
                <string>document-format=application/octet-stream</string>
        </array>
+       <key>SHAuthorizationRight</key>
+       <string>system.preferences</string>
        <key>Sockets</key>
        <dict>
                <key>Listeners</key>
index 89bcab309f0c2ed3d2baaca5f5192c5ba93c4f55..74bcce6c3b57d1d6d30f7f045c4498d15cac1a0b 100644 (file)
@@ -4,8 +4,6 @@
 <dict>
        <key>Label</key>
        <string>org.cups.cupsd</string>
-       <key>OnDemand</key>
-       <true/>
        <key>KeepAlive</key>
        <dict>
                <key>PathState</key>
@@ -14,8 +12,6 @@
                        <true/>
                </dict>
        </dict>
-       <key>RunAtLoad</key>
-       <false/>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/sbin/cupsd</string>
@@ -23,6 +19,8 @@
        </array>
        <key>ServiceIPC</key>
        <true/>
+       <key>SHAuthorizationRight</key>
+       <string>system.preferences</string>
        <key>Sockets</key>
        <dict>
                <key>Listeners</key>
index 867124cfe6dec44712e5cf17767ae0f1663a946b..77b8675c307bc0a2864df72434d19cf9615918bd 100644 (file)
@@ -1397,9 +1397,11 @@ show_jobs(http_t     *http,              /* I - HTTP connection to server */
           int        ranking,          /* I - Show job ranking? */
          const char *which)            /* I - Show which jobs? */
 {
+  int          i;                      /* Looping var */
   ipp_t                *request,               /* IPP Request */
                *response;              /* IPP Response */
-  ipp_attribute_t *attr;               /* Current attribute */
+  ipp_attribute_t *attr,               /* Current attribute */
+               *reasons;               /* Job state reasons attribute */
   const char   *dest,                  /* Pointer into job-printer-uri */
                *username,              /* Pointer to job-originating-user-name */
                *title;                 /* Pointer to job-name */
@@ -1420,7 +1422,8 @@ show_jobs(http_t     *http,               /* I - HTTP connection to server */
                  "job-name",
                  "time-at-creation",
                  "job-printer-uri",
-                 "job-originating-user-name"
+                 "job-originating-user-name",
+                 "job-state-reasons"
                };
 
 
@@ -1495,6 +1498,7 @@ show_jobs(http_t     *http,               /* I - HTTP connection to server */
       dest     = NULL;
       jobtime  = 0;
       title    = "no title";
+      reasons  = NULL;
 
       while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
       {
@@ -1523,6 +1527,10 @@ show_jobs(http_t     *http,              /* I - HTTP connection to server */
            attr->value_tag == IPP_TAG_NAME)
          title = attr->values[0].string.text;
 
+        if (!strcmp(attr->name, "job-state-reasons") &&
+           attr->value_tag == IPP_TAG_KEYWORD)
+         reasons = attr;
+
         attr = attr->next;
       }
 
@@ -1665,7 +1673,17 @@ show_jobs(http_t     *http,              /* I - HTTP connection to server */
                            temp, username ? username : "unknown",
                            1024.0 * size, date);
           if (long_status)
+          {
+           if (reasons)
+           {
+             _cupsLangPuts(stdout, _("\tAlerts:"));
+             for (i = 0; i < reasons->num_values; i ++)
+               _cupsLangPrintf(stdout, " %s",
+                               reasons->values[i].string.text);
+             _cupsLangPuts(stdout, "\n");
+           }
            _cupsLangPrintf(stdout, _("\tqueued for %s\n"), dest);
+         }
        }
       }