/*
- * "$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>
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 */
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)
* 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));
unlink(tmpfilename);
return (CUPS_BACKEND_FAILED);
}
-
- filename = tmpfilename;
}
else if (argc == 6)
{
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? */
*/
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;;
}
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)
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...
*/
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))
{
if (status == 0)
{
+ /*
+ * Check for side-channel requests...
+ */
+
+ backendCheckSideChannel(snmp_fd, &(addr->addr));
+
/*
* Send the print file...
*/
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))
{
_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...
*/
/*
- * 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 $".
*/