/*
- * "$Id: socket.c 6438 2007-04-03 17:52:41Z mike $"
+ * "$Id: socket.c 6910 2007-09-04 20:34:29Z mike $"
*
* AppSocket backend for the Common UNIX Printing System (CUPS).
*
+ * Copyright 2007 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
+ * 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 please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*
username[255], /* Username info (not used) */
resource[1024], /* Resource info (not used) */
*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; /* Option separator */
int print_fd; /* Print file */
int copies; /* Number of copies to print */
time_t start_time; /* Time of first connect */
int device_fd; /* AppSocket */
int error; /* Error code (if any) */
http_addrlist_t *addrlist, /* Address list */
- *addr; /* Connected address */
+ *addr; /* Connected address */
char addrname[256]; /* Address name */
ssize_t tbytes; /* Total number of bytes written */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
}
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;
+
+ while (*options && *options != '=' && *options != '+' && *options != '&')
+ options ++;
+
+ if ((sep = *options) != '\0')
+ *options++ = '\0';
- if (*options == '=')
+ if (sep == '=')
{
/*
* Get the value...
*/
- options ++;
-
- for (ptr = value; *options && *options != '+' && *options != '&';)
- if (ptr < (value + sizeof(value) - 1))
- *ptr++ = *options++;
- *ptr = '\0';
+ value = options;
- if (*options == '+' || *options == '&')
+ while (*options && *options != '+' && *options != '&')
options ++;
+
+ if (*options)
+ *options++ = '\0';
}
else
- value[0] = '\0';
+ value = (char *)"";
/*
* Process the option...
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);
}
- fprintf(stderr, _("INFO: Attempting to connect to host %s on port %d\n"),
- hostname, port);
+ _cupsLangPrintf(stderr,
+ _("INFO: Attempting to connect to host %s on port %d\n"),
+ hostname, port);
fputs("STATE: +connecting-to-device\n", stderr);
* 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"));
/*
* Sleep 5 seconds to keep the job from requeuing too rapidly...
{
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);
+ _cupsLangPrintf(stderr, "DEBUG: Connection error: %s\n",
+ strerror(errno));
+ _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)
tbytes = backendRunLoop(print_fd, device_fd, 1, side_cb);
if (print_fd != 0 && tbytes >= 0)
- fprintf(stderr,
+ _cupsLangPrintf(stderr,
#ifdef HAVE_LONG_LONG
- _("INFO: Sent print file, %lld bytes...\n"),
+ _("INFO: Sent print file, %lld bytes...\n"),
#else
- _("INFO: Sent print file, %ld bytes...\n"),
+ _("INFO: Sent print file, %ld bytes...\n"),
#endif /* HAVE_LONG_LONG */
- CUPS_LLCAST tbytes);
+ CUPS_LLCAST tbytes);
}
/*
* Shutdown the socket and wait for the other end to finish...
*/
- fputs(_("INFO: Print file sent, waiting for printer to finish...\n"),
- stderr);
+ _cupsLangPuts(stderr,
+ _("INFO: Print file sent, waiting for printer to finish...\n"));
shutdown(device_fd, 1);
close(print_fd);
if (tbytes >= 0)
- fputs(_("INFO: Ready to print.\n"), stderr);
+ _cupsLangPuts(stderr, _("INFO: Ready to print.\n"));
return (tbytes < 0 ? CUPS_BACKEND_FAILED : CUPS_BACKEND_OK);
}
cups_sc_status_t status; /* Request/response status */
char data[2048]; /* Request/response data */
int datalen; /* Request/response data size */
+ const char *device_id; /* 1284DEVICEID env var */
datalen = sizeof(data);
if (cupsSideChannelRead(&command, &status, data, &datalen, 1.0))
{
- fputs(_("WARNING: Failed to read side-channel request!\n"), stderr);
+ _cupsLangPuts(stderr, _("WARNING: Failed to read side-channel request!\n"));
return;
}
* Our sockets disable the Nagle algorithm and data is sent immediately.
*/
- status = CUPS_SC_STATUS_OK;
+ if (backendDrainOutput(print_fd, device_fd))
+ status = CUPS_SC_STATUS_IO_ERROR;
+ else
+ status = CUPS_SC_STATUS_OK;
+
datalen = 0;
break;
datalen = 1;
break;
+ case CUPS_SC_CMD_GET_DEVICE_ID :
+ if ((device_id = getenv("1284DEVICEID")) != NULL)
+ {
+ strlcpy(data, device_id, sizeof(data));
+ datalen = (int)strlen(data);
+ break;
+ }
+
default :
status = CUPS_SC_STATUS_NOT_IMPLEMENTED;
datalen = 0;
/*
- * End of "$Id: socket.c 6438 2007-04-03 17:52:41Z mike $".
+ * End of "$Id: socket.c 6910 2007-09-04 20:34:29Z mike $".
*/