/*
- * "$Id: lpd.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id: lpd.c 6911 2007-09-04 20:35:08Z mike $"
*
* Line Printer Daemon backend for the Common UNIX Printing System (CUPS).
*
username[255], /* Username info */
resource[1024], /* Resource info (printer name) */
*options, /* Pointer to options */
- name[255], /* Name of option */
- value[255], /* Value of option */
- *ptr, /* Pointer into name or value */
+ *name, /* Name of option */
+ *value, /* Value of option */
+ sep, /* Separator character */
*filename, /* File to print */
title[256]; /* Title string */
int port; /* Port number */
}
else if (argc < 6 || argc > 7)
{
- fprintf(stderr, _("Usage: %s job-id user title copies options [file]\n"),
- argv[0]);
+ _cupsLangPrintf(stderr,
+ _("Usage: %s job-id user title copies options [file]\n"),
+ argv[0]);
return (CUPS_BACKEND_FAILED);
}
* Get the name...
*/
- for (ptr = name; *options && *options != '=';)
- if (ptr < (name + sizeof(name) - 1))
- *ptr++ = *options++;
- *ptr = '\0';
+ name = options;
- if (*options == '=')
+ while (*options && *options != '=' && *options != '+' && *options != '&')
+ options ++;
+
+ if ((sep = *options) != '\0')
+ *options++ = '\0';
+
+ if (sep == '=')
{
/*
* Get the value...
*/
- options ++;
+ value = options;
- for (ptr = value; *options && *options != '+' && *options != '&';)
- if (ptr < (value + sizeof(value) - 1))
- *ptr++ = *options++;
- *ptr = '\0';
-
- if (*options == '+' || *options == '&')
+ while (*options && *options != '+' && *options != '&')
options ++;
+
+ if (*options)
+ *options++ = '\0';
}
else
- value[0] = '\0';
+ value = (char *)"";
/*
* Process the option...
if (strchr("cdfglnoprtv", value[0]))
format = value[0];
else
- fprintf(stderr, _("ERROR: Unknown format character \"%c\"\n"),
- value[0]);
+ _cupsLangPrintf(stderr, _("ERROR: Unknown format character \"%c\"\n"),
+ value[0]);
}
else if (!strcasecmp(name, "mode") && value[0])
{
else if (!strcasecmp(value, "stream"))
mode = MODE_STREAM;
else
- fprintf(stderr, _("ERROR: Unknown print mode \"%s\"\n"), value);
+ _cupsLangPrintf(stderr, _("ERROR: Unknown print mode \"%s\"\n"),
+ value);
}
else if (!strcasecmp(name, "order") && value[0])
{
else if (!strcasecmp(value, "data,control"))
order = ORDER_DATA_CONTROL;
else
- fprintf(stderr, _("ERROR: Unknown file order \"%s\"\n"), value);
+ _cupsLangPrintf(stderr, _("ERROR: Unknown file order \"%s\"\n"),
+ value);
}
else if (!strcasecmp(name, "reserve"))
{
if (fd == -1)
{
- fprintf(stderr, _("ERROR: Unable to open print file %s: %s\n"),
- filename, strerror(errno));
+ _cupsLangPrintf(stderr, _("ERROR: Unable to open print file %s: %s\n"),
+ filename, strerror(errno));
return (CUPS_BACKEND_FAILED);
}
}
* the remote end...
*/
+ char *ptr;
+
for (ptr = title; *ptr; ptr ++)
if (!isalnum(*ptr & 255) && !isspace(*ptr & 255))
*ptr = '_';
if (recv(fd, &status, 1, 0) < 1)
{
- fprintf(stderr,
- _("WARNING: Remote host did not respond with command status "
- "byte after %d seconds!\n"), timeout);
+ _cupsLangPrintf(stderr,
+ _("WARNING: Remote host did not respond with command "
+ "status byte after %d seconds!\n"), timeout);
status = errno;
}
if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL)
{
- fprintf(stderr, _("ERROR: Unable to locate printer \'%s\'!\n"), hostname);
+ _cupsLangPrintf(stderr, _("ERROR: Unable to locate printer \'%s\'!\n"),
+ hostname);
return (CUPS_BACKEND_STOP);
}
*/
fputs("STATE: +connecting-to-device\n", stderr);
- fprintf(stderr,
- _("INFO: Attempting to connect to host %s for printer %s\n"),
- hostname, printer);
+ _cupsLangPrintf(stderr,
+ _("INFO: Attempting to connect to host %s for printer %s\n"),
+ hostname, printer);
for (lport = reserve == RESERVE_RFC1179 ? 732 : 1024, addr = addrlist,
delay = 5;;
* available printer in the class.
*/
- fputs(_("INFO: Unable to contact printer, queuing on next "
- "printer in class...\n"), stderr);
+ _cupsLangPuts(stderr,
+ _("INFO: Unable to contact printer, queuing on next "
+ "printer in class...\n"));
httpAddrFreeList(addrlist);
{
if (contimeout && (time(NULL) - start_time) > contimeout)
{
- fputs(_("ERROR: Printer not responding!\n"), stderr);
+ _cupsLangPuts(stderr, _("ERROR: Printer not responding!\n"));
return (CUPS_BACKEND_FAILED);
}
recoverable = 1;
- fprintf(stderr,
- _("WARNING: recoverable: Network host \'%s\' is busy; will "
- "retry in %d seconds...\n"),
- hostname, delay);
+ _cupsLangPrintf(stderr,
+ _("WARNING: recoverable: Network host \'%s\' is busy; "
+ "will retry in %d seconds...\n"), hostname, delay);
sleep(delay);
recoverable = 1;
fprintf(stderr, "DEBUG: Connection error: %s\n", strerror(errno));
- fputs(_("ERROR: recoverable: Unable to connect to printer; will "
- "retry in 30 seconds...\n"), stderr);
+ _cupsLangPuts(stderr,
+ _("ERROR: recoverable: Unable to connect to printer; "
+ "will retry in 30 seconds...\n"));
sleep(30);
}
}
}
fputs("STATE: -connecting-to-device\n", stderr);
- fprintf(stderr, _("INFO: Connected to %s...\n"), hostname);
+ _cupsLangPrintf(stderr, _("INFO: Connected to %s...\n"), hostname);
#ifdef AF_INET6
if (addr->addr.addr.sa_family == AF_INET6)
return (CUPS_BACKEND_FAILED);
}
- fprintf(stderr, _("INFO: Sending control file (%u bytes)\n"),
- (unsigned)strlen(control));
+ _cupsLangPrintf(stderr, _("INFO: Sending control file (%u bytes)\n"),
+ (unsigned)strlen(control));
if (lpd_write(fd, control, strlen(control) + 1) < (strlen(control) + 1))
{
if (read(fd, &status, 1) < 1)
{
- fprintf(stderr,
- _("WARNING: Remote host did not respond with control "
- "status byte after %d seconds!\n"), timeout);
+ _cupsLangPrintf(stderr,
+ _("WARNING: Remote host did not respond with control "
+ "status byte after %d seconds!\n"), timeout);
status = errno;
}
}
if (status != 0)
- fprintf(stderr,
- _("ERROR: Remote host did not accept control file (%d)\n"),
- status);
+ _cupsLangPrintf(stderr,
+ _("ERROR: Remote host did not accept control file "
+ "(%d)\n"), status);
else
- fputs(_("INFO: Control file sent successfully\n"), stderr);
+ _cupsLangPuts(stderr, _("INFO: Control file sent successfully\n"));
}
else
status = 0;
return (CUPS_BACKEND_FAILED);
}
- fprintf(stderr,
+ _cupsLangPrintf(stderr,
#ifdef HAVE_LONG_LONG
- _("INFO: Sending data file (%lld bytes)\n"),
+ _("INFO: Sending data file (%lld bytes)\n"),
#else
- _("INFO: Sending data file (%ld bytes)\n"),
+ _("INFO: Sending data file (%ld bytes)\n"),
#endif /* HAVE_LONG_LONG */
- CUPS_LLCAST filestats.st_size);
+ CUPS_LLCAST filestats.st_size);
tbytes = 0;
for (copy = 0; copy < manual_copies; copy ++)
while ((nbytes = read(print_fd, buffer, sizeof(buffer))) > 0)
{
- fprintf(stderr, _("INFO: Spooling LPR job, %.0f%% complete...\n"),
- 100.0 * tbytes / filestats.st_size);
+ _cupsLangPrintf(stderr,
+ _("INFO: Spooling LPR job, %.0f%% complete...\n"),
+ 100.0 * tbytes / filestats.st_size);
if (lpd_write(fd, buffer, nbytes) < nbytes)
{
if (recv(fd, &status, 1, 0) < 1)
{
- fprintf(stderr,
- _("WARNING: Remote host did not respond with data "
- "status byte after %d seconds!\n"), timeout);
+ _cupsLangPrintf(stderr,
+ _("WARNING: Remote host did not respond with data "
+ "status byte after %d seconds!\n"), timeout);
status = 0;
}
status = 0;
if (status != 0)
- fprintf(stderr, _("ERROR: Remote host did not accept data file (%d)\n"),
- status);
+ _cupsLangPrintf(stderr,
+ _("ERROR: Remote host did not accept data file (%d)\n"),
+ status);
else
- fputs(_("INFO: Data file sent successfully\n"), stderr);
+ _cupsLangPuts(stderr, _("INFO: Data file sent successfully\n"));
}
if (status == 0 && order == ORDER_DATA_CONTROL)
return (CUPS_BACKEND_FAILED);
}
- fprintf(stderr, _("INFO: Sending control file (%lu bytes)\n"),
- (unsigned long)strlen(control));
+ _cupsLangPrintf(stderr, _("INFO: Sending control file (%lu bytes)\n"),
+ (unsigned long)strlen(control));
if (lpd_write(fd, control, strlen(control) + 1) < (strlen(control) + 1))
{
if (read(fd, &status, 1) < 1)
{
- fprintf(stderr,
- _("WARNING: Remote host did not respond with control "
- "status byte after %d seconds!\n"), timeout);
+ _cupsLangPrintf(stderr,
+ _("WARNING: Remote host did not respond with control "
+ "status byte after %d seconds!\n"), timeout);
status = errno;
}
}
if (status != 0)
- fprintf(stderr,
- _("ERROR: Remote host did not accept control file (%d)\n"),
- status);
+ _cupsLangPrintf(stderr,
+ _("ERROR: Remote host did not accept control file "
+ "(%d)\n"), status);
else
- fputs(_("INFO: Control file sent successfully\n"), stderr);
+ _cupsLangPuts(stderr, _("INFO: Control file sent successfully\n"));
}
/*
/*
- * End of "$Id: lpd.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id: lpd.c 6911 2007-09-04 20:35:08Z mike $".
*/