]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/lpd.c
Merge changes from CUPS 1.4svn-r8177 (tentative CUPS 1.4b2)
[thirdparty/cups.git] / backend / lpd.c
index 100868f980522367399827bc5d8961e9b71d1166..b39394c611739e0192ea7e76243826c400854a1a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: lpd.c 6910 2007-09-04 20:34:29Z mike $"
+ * "$Id: lpd.c 7740 2008-07-14 23:58:05Z mike $"
  *
  *   Line Printer Daemon backend for the Common UNIX Printing System (CUPS).
  *
  * Include necessary headers.
  */
 
-#include <cups/backend.h>
 #include <cups/http-private.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include "backend-private.h"
 #include <stdarg.h>
-#include <ctype.h>
-#include <cups/string.h>
-#include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <signal.h>
 
 #ifdef WIN32
 #  include <winsock.h>
@@ -120,31 +112,32 @@ int                                       /* O - Exit status */
 main(int  argc,                                /* I - Number of command-line arguments (6 or 7) */
      char *argv[])                     /* I - Command-line arguments */
 {
-  char                 method[255],    /* Method in URI */
-                       hostname[1024], /* Hostname */
-                       username[255],  /* Username info */
-                       resource[1024], /* Resource info (printer name) */
-                       *options,       /* Pointer to options */
-                       *name,          /* Name of option */
-                       *value,         /* Value of option */
-                       sep,            /* Separator character */
-                       *filename,      /* File to print */
-                       title[256];     /* Title string */
-  int                  port;           /* Port number */
-  int                  fd;             /* Print file */
-  int                  status;         /* Status of LPD job */
-  int                  mode;           /* Print mode */
-  int                  banner;         /* Print banner page? */
-  int                  format;         /* Print format */
-  int                  order;          /* Order of control/data files */
-  int                  reserve;        /* Reserve priviledged port? */
-  int                  sanitize_title; /* Sanitize title string? */
-  int                  manual_copies,  /* Do manual copies? */
-                       timeout,        /* Timeout */
-                       contimeout,     /* Connection timeout */
-                       copies;         /* Number of copies */
+  const char   *device_uri;            /* Device URI */
+  char         method[255],            /* Method in URI */
+               hostname[1024],         /* Hostname */
+               username[255],          /* Username info */
+               resource[1024],         /* Resource info (printer name) */
+               *options,               /* Pointer to options */
+               *name,                  /* Name of option */
+               *value,                 /* Value of option */
+               sep,                    /* Separator character */
+               *filename,              /* File to print */
+               title[256];             /* Title string */
+  int          port;                   /* Port number */
+  int          fd;                     /* Print file */
+  int          status;                 /* Status of LPD job */
+  int          mode;                   /* Print mode */
+  int          banner;                 /* Print banner page? */
+  int          format;                 /* Print format */
+  int          order;                  /* Order of control/data files */
+  int          reserve;                /* Reserve priviledged port? */
+  int          sanitize_title;         /* Sanitize title string? */
+  int          manual_copies,          /* Do manual copies? */
+               timeout,                /* Timeout */
+               contimeout,             /* Connection timeout */
+               copies;                 /* Number of copies */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
-  struct sigaction     action;         /* Actions for POSIX signals */
+  struct sigaction action;             /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
 
 
@@ -181,7 +174,8 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
 
   if (argc == 1)
   {
-    puts("network lpd \"Unknown\" \"LPD/LPR Host or Printer\"");
+    printf("network lpd \"Unknown\" \"%s\"\n",
+           _cupsLangString(cupsLangDefault(), _("LPD/LPR Host or Printer")));
     return (CUPS_BACKEND_OK);
   }
   else if (argc < 6 || argc > 7)
@@ -196,7 +190,10 @@ main(int  argc,                            /* I - Number of command-line arguments (6 or 7) */
   * Extract the hostname and printer name from the URI...
   */
 
-  httpSeparateURI(HTTP_URI_CODING_ALL, cupsBackendDeviceURI(argv),
+  if ((device_uri = cupsBackendDeviceURI(argv)) == NULL)
+    return (CUPS_BACKEND_FAILED);
+
+  httpSeparateURI(HTTP_URI_CODING_ALL, device_uri,
                   method, sizeof(method), username, sizeof(username),
                  hostname, sizeof(hostname), &port,
                  resource, sizeof(resource));
@@ -445,8 +442,6 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
        unlink(tmpfilename);
        return (CUPS_BACKEND_FAILED);
       }
-
-    filename = tmpfilename;
   }
   else if (argc == 6)
   {
@@ -642,6 +637,8 @@ lpd_queue(const char *hostname,             /* I - Host to connect to */
   char                 addrname[256];  /* Address name */
   http_addrlist_t      *addrlist,      /* Address list */
                        *addr;          /* Socket address */
+  int                  snmp_fd,        /* SNMP socket */
+                       have_supplies;  /* Printer supports supply levels? */
   int                  copy;           /* Copies written */
   time_t               start_time;     /* Time of first connect */
   int                  recoverable;    /* Recoverable error shown? */
@@ -700,9 +697,9 @@ lpd_queue(const char *hostname,             /* I - Host to connect to */
     */
 
     fputs("STATE: +connecting-to-device\n", stderr);
-    _cupsLangPrintf(stderr,
-                   _("INFO: Attempting to connect to host %s for printer %s\n"),
-                   hostname, printer);
+    fprintf(stderr, "DEBUG: Connecting to %s:%d for printer %s\n",
+           hostname, port, printer);
+    _cupsLangPuts(stderr, _("INFO: Connecting to printer...\n"));
 
     for (lport = reserve == RESERVE_RFC1179 ? 732 : 1024, addr = addrlist,
              delay = 5;;
@@ -869,7 +866,7 @@ lpd_queue(const char *hostname,             /* I - Host to connect to */
     }
 
     fputs("STATE: -connecting-to-device\n", stderr);
-    _cupsLangPrintf(stderr, _("INFO: Connected to %s...\n"), hostname);
+    _cupsLangPuts(stderr, _("INFO: Connected to printer...\n"));
 
 #ifdef AF_INET6
     if (addr->addr.addr.sa_family == AF_INET6)
@@ -883,6 +880,21 @@ lpd_queue(const char *hostname,            /* I - Host to connect to */
                httpAddrString(&addr->addr, addrname, sizeof(addrname)),
                ntohs(addr->addr.ipv4.sin_port), lport);
 
+   /*
+    * See if the printer supports SNMP...
+    */
+
+    if ((snmp_fd = _cupsSNMPOpen(addr->addr.addr.sa_family)) >= 0)
+      have_supplies = !backendSNMPSupplies(snmp_fd, &(addr->addr), NULL, NULL);
+    else
+      have_supplies = 0;
+
+   /*
+    * Check for side-channel requests...
+    */
+
+    backendCheckSideChannel(snmp_fd, &(addr->addr));
+
    /*
     * Next, open the print file and figure out its size...
     */
@@ -966,6 +978,16 @@ lpd_queue(const char *hostname,            /* I - Host to connect to */
 
     if (order == ORDER_CONTROL_DATA)
     {
+     /*
+      * Check for side-channel requests...
+      */
+
+      backendCheckSideChannel(snmp_fd, &(addr->addr));
+
+     /*
+      * Send the control file...
+      */
+
       if (lpd_command(fd, timeout, "\002%d cfA%03.3d%.15s\n", strlen(control),
                       (int)getpid() % 1000, localhost))
       {
@@ -1010,6 +1032,12 @@ lpd_queue(const char *hostname,          /* I - Host to connect to */
 
     if (status == 0)
     {
+     /*
+      * Check for side-channel requests...
+      */
+
+      backendCheckSideChannel(snmp_fd, &(addr->addr));
+
      /*
       * Send the print file...
       */
@@ -1097,6 +1125,16 @@ lpd_queue(const char *hostname,          /* I - Host to connect to */
 
     if (status == 0 && order == ORDER_DATA_CONTROL)
     {
+     /*
+      * Check for side-channel requests...
+      */
+
+      backendCheckSideChannel(snmp_fd, &(addr->addr));
+
+     /*
+      * Send control file...
+      */
+
       if (lpd_command(fd, timeout, "\002%d cfA%03.3d%.15s\n", strlen(control),
                       (int)getpid() % 1000, localhost))
       {
@@ -1137,6 +1175,13 @@ lpd_queue(const char *hostname,          /* I - Host to connect to */
        _cupsLangPuts(stderr, _("INFO: Control file sent successfully\n"));
     }
 
+   /*
+    * Collect the final supply levels as needed...
+    */
+
+    if (have_supplies)
+      backendSNMPSupplies(snmp_fd, &(addr->addr), NULL, NULL);
+
    /*
     * Close the socket connection and input file...
     */
@@ -1318,5 +1363,5 @@ sigterm_handler(int sig)          /* I - Signal */
 
 
 /*
- * End of "$Id: lpd.c 6910 2007-09-04 20:34:29Z mike $".
+ * End of "$Id: lpd.c 7740 2008-07-14 23:58:05Z mike $".
  */