]> 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 8f173d27bb10d39d6580f4a5e8778b7271729aff..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).
  *
@@ -112,6 +112,7 @@ int                                 /* O - Exit status */
 main(int  argc,                                /* I - Number of command-line arguments (6 or 7) */
      char *argv[])                     /* I - Command-line arguments */
 {
+  const char   *device_uri;            /* Device URI */
   char         method[255],            /* Method in URI */
                hostname[1024],         /* Hostname */
                username[255],          /* Username info */
@@ -173,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)
@@ -188,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, backendResolveURI(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));
@@ -437,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)
   {
@@ -635,8 +638,7 @@ lpd_queue(const char *hostname,             /* I - Host to connect to */
   http_addrlist_t      *addrlist,      /* Address list */
                        *addr;          /* Socket address */
   int                  snmp_fd,        /* SNMP socket */
-                       start_count,    /* Page count via SNMP at start */
-                       page_count;     /* Page count via SNMP */
+                       have_supplies;  /* Printer supports supply levels? */
   int                  copy;           /* Copies written */
   time_t               start_time;     /* Time of first connect */
   int                  recoverable;    /* Recoverable error shown? */
@@ -695,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;;
@@ -864,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,15 +885,9 @@ lpd_queue(const char *hostname,            /* I - Host to connect to */
     */
 
     if ((snmp_fd = _cupsSNMPOpen(addr->addr.addr.sa_family)) >= 0)
-      if (backendSNMPSupplies(snmp_fd, &(addr->addr), &start_count, NULL))
-      {
-       /*
-       * No, close it...
-       */
-
-       _cupsSNMPClose(snmp_fd);
-       snmp_fd = -1;
-      }
+      have_supplies = !backendSNMPSupplies(snmp_fd, &(addr->addr), NULL, NULL);
+    else
+      have_supplies = 0;
 
    /*
     * Check for side-channel requests...
@@ -1180,22 +1176,11 @@ lpd_queue(const char *hostname,         /* I - Host to connect to */
     }
 
    /*
-    * Collect the final page count as needed...
+    * Collect the final supply levels as needed...
     */
 
-    if (snmp_fd >= 0)
-    {
-      int printer_state;               /* State of printer */
-
-
-      while (!backendSNMPSupplies(snmp_fd, &(addr->addr), &page_count,
-                                  &printer_state) &&
-            printer_state != CUPS_TC_idle)
-       sleep(3);
-
-      if (page_count > start_count)
-        fprintf(stderr, "PAGE: total %d\n", page_count - start_count);
-    }
+    if (have_supplies)
+      backendSNMPSupplies(snmp_fd, &(addr->addr), NULL, NULL);
 
    /*
     * Close the socket connection and input file...
@@ -1378,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 $".
  */