/*
- * "$Id: lpd.c 7740 2008-07-14 23:58:05Z mike $"
+ * "$Id$"
*
- * Line Printer Daemon backend for CUPS.
+ * Line Printer Daemon backend for CUPS.
*
- * Copyright 2007-2012 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2013 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * "LICENSE" which should have been included with this file. If this
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * "LICENSE" which should have been included with this file. If this
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * main() - Send a file to the printer or server.
- * lpd_command() - Send an LPR command sequence and wait for a reply.
- * lpd_queue() - Queue a file using the Line Printer Daemon protocol.
- * lpd_write() - Write a buffer of data to an LPD server.
- * rresvport_af() - A simple implementation of rresvport_af().
- * sigterm_handler() - Handle 'terminate' signals that stop the backend.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
int copies, int banner, int format, int order,
int reserve, int manual_copies, int timeout,
int contimeout, const char *orighost);
-static int lpd_write(int lpd_fd, char *buffer, int length);
+static ssize_t lpd_write(int lpd_fd, char *buffer, size_t length);
#ifndef HAVE_RRESVPORT_AF
static int rresvport_af(int *port, int family);
#endif /* !HAVE_RRESVPORT_AF */
_cupsLangPrintFilter(stderr, "INFO", _("Copying print data."));
if (bytes > 0)
- write(fd, buffer, bytes);
+ write(fd, buffer, (size_t)bytes);
backendRunLoop(-1, fd, snmp_fd, &(addrlist->addr), 0, 0,
backendNetworkSideCB);
{
va_list ap; /* Argument pointer */
char buf[1024]; /* Output buffer */
- int bytes; /* Number of bytes to output */
+ ssize_t bytes; /* Number of bytes to output */
char status; /* Status from command */
* Send the command...
*/
- fprintf(stderr, "DEBUG: Sending command string (%d bytes)...\n", bytes);
+ fprintf(stderr, "DEBUG: Sending command string (" CUPS_LLFMT " bytes)...\n", CUPS_LLCAST bytes);
- if (lpd_write(fd, buf, bytes) < bytes)
+ if (lpd_write(fd, buf, (size_t)bytes) < bytes)
{
perror("DEBUG: Unable to send LPD command");
return (-1);
if (recv(fd, &status, 1, 0) < 1)
{
_cupsLangPrintFilter(stderr, "WARNING", _("The printer did not respond."));
- status = errno;
+ status = (char)errno;
}
fprintf(stderr, "DEBUG: lpd_command returning %d\n", status);
int have_supplies; /* Printer supports supply levels? */
int copy; /* Copies written */
time_t start_time; /* Time of first connect */
- size_t nbytes; /* Number of bytes written */
+ ssize_t nbytes; /* Number of bytes written */
off_t tbytes; /* Total bytes written */
char buffer[32768]; /* Output buffer */
#ifdef WIN32
return (CUPS_BACKEND_FAILED);
}
- if (!connect(fd, &(addr->addr.addr), httpAddrLength(&(addr->addr))))
+ if (!connect(fd, &(addr->addr.addr), (socklen_t)httpAddrLength(&(addr->addr))))
break;
error = errno;
break;
}
- sleep(delay);
+ sleep((unsigned)delay);
if (delay < 30)
delay += 5;
if (banner)
{
- snprintf(cptr, sizeof(control) - (cptr - control),
+ snprintf(cptr, sizeof(control) - (size_t)(cptr - control),
"C%.31s\n" /* RFC 1179, Section 7.2 - class name <= 31 chars */
"L%s\n",
localhost, user);
while (copies > 0)
{
- snprintf(cptr, sizeof(control) - (cptr - control), "%cdfA%03d%.15s\n",
+ snprintf(cptr, sizeof(control) - (size_t)(cptr - control), "%cdfA%03d%.15s\n",
format, (int)getpid() % 1000, localhost);
cptr += strlen(cptr);
copies --;
}
- snprintf(cptr, sizeof(control) - (cptr - control),
+ snprintf(cptr, sizeof(control) - (size_t)(cptr - control),
"UdfA%03d%.15s\n"
"N%.131s\n", /* RFC 1179, Section 7.2 - sourcefile name <= 131 chars */
(int)getpid() % 1000, localhost, title);
fprintf(stderr, "DEBUG: Sending control file (%u bytes)\n",
(unsigned)strlen(control));
- if (lpd_write(fd, control, strlen(control) + 1) < (strlen(control) + 1))
+ if ((size_t)lpd_write(fd, control, strlen(control) + 1) < (strlen(control) + 1))
{
- status = errno;
+ status = (char)errno;
perror("DEBUG: Unable to write control file");
}
{
_cupsLangPrintFilter(stderr, "WARNING",
_("The printer did not respond."));
- status = errno;
+ status = (char)errno;
}
}
_("Spooling job, %.0f%% complete."),
100.0 * tbytes / filestats.st_size);
- if (lpd_write(fd, buffer, nbytes) < nbytes)
+ if (lpd_write(fd, buffer, (size_t)nbytes) < nbytes)
{
perror("DEBUG: Unable to send print file to printer");
break;
if (mode == MODE_STANDARD)
{
if (tbytes < filestats.st_size)
- status = errno;
+ status = (char)errno;
else if (lpd_write(fd, "", 1) < 1)
{
perror("DEBUG: Unable to send trailing nul to printer");
- status = errno;
+ status = (char)errno;
}
else
{
fprintf(stderr, "DEBUG: Sending control file (%lu bytes)\n",
(unsigned long)strlen(control));
- if (lpd_write(fd, control, strlen(control) + 1) < (strlen(control) + 1))
+ if ((size_t)lpd_write(fd, control, strlen(control) + 1) < (strlen(control) + 1))
{
- status = errno;
+ status = (char)errno;
perror("DEBUG: Unable to write control file");
}
else
{
_cupsLangPrintFilter(stderr, "WARNING",
_("The printer did not respond."));
- status = errno;
+ status = (char)errno;
}
}
_("Control file sent successfully."));
}
+ fputs("STATE: +cups-waiting-for-job-completed\n", stderr);
+
/*
* Collect the final supply levels as needed...
*/
* 'lpd_write()' - Write a buffer of data to an LPD server.
*/
-static int /* O - Number of bytes written or -1 on error */
-lpd_write(int lpd_fd, /* I - LPD socket */
- char *buffer, /* I - Buffer to write */
- int length) /* I - Number of bytes to write */
+static ssize_t /* O - Number of bytes written or -1 on error */
+lpd_write(int lpd_fd, /* I - LPD socket */
+ char *buffer, /* I - Buffer to write */
+ size_t length) /* I - Number of bytes to write */
{
- int bytes, /* Number of bytes written */
- total; /* Total number of bytes written */
+ ssize_t bytes, /* Number of bytes written */
+ total; /* Total number of bytes written */
if (abort_job)
return (-1);
total = 0;
- while ((bytes = send(lpd_fd, buffer, length - total, 0)) >= 0)
+ while ((bytes = send(lpd_fd, buffer, length - (size_t)total, 0)) >= 0)
{
total += bytes;
buffer += bytes;
- if (total == length)
+ if ((size_t)total == length)
break;
}
if (bytes < 0)
return (-1);
else
- return (length);
+ return (total);
}
if (errno != EADDRINUSE)
{
-# ifdef WIN32
- closesocket(fd);
-# else
- close(fd);
-# endif /* WIN32 */
+ httpAddrClose(NULL, fd);
return (-1);
}
/*
- * End of "$Id: lpd.c 7740 2008-07-14 23:58:05Z mike $".
+ * End of "$Id$".
*/