/*
- * "$Id$"
+ * "$Id: cups-lpd.c 6781 2007-08-08 21:09:31Z mike $"
*
* Line Printer Daemon interface for the Common UNIX Printing System (CUPS).
*
+ * Copyright 2007-2008 by Apple Inc.
* Copyright 1997-2006 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
- * "LICENSE.txt" 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
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
int destsize, cups_option_t **options,
int *accepting, int *shared, ipp_pstate_t *state);
static int print_file(http_t *http, int id, const char *filename,
- const char *docname, const char *user, int last);
+ const char *docname, const char *user,
+ const char *format, int last);
static int recv_print_job(const char *name, int num_defaults,
cups_option_t *defaults);
static int remove_jobs(const char *name, const char *agent,
num_defaults = 0;
defaults = NULL;
hostlookups = 1;
- num_defaults = cupsAddOption("job-originating-host-name", hostname,
- num_defaults, &defaults);
for (i = 1; i < argc; i ++)
if (argv[i][0] == '-')
hostip);
}
+ num_defaults = cupsAddOption("job-originating-host-name", hostname,
+ num_defaults, &defaults);
+
/*
* RFC1179 specifies that only 1 daemon command can be received for
* every connection.
*options = NULL;
/*
- * If the queue name contains a space, lookup the printer-name using
- * the printer-info value...
+ * See if the name is a queue name optionally with an instance name.
+ */
+
+ strlcpy(dest, name, destsize);
+ if ((value = strchr(dest, '/')) != NULL)
+ *value = '\0';
+
+ /*
+ * Setup the Get-Printer-Attributes request...
+ */
+
+ request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, "/printers/%s", dest);
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
+
+ ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "requested-attributes",
+ (int)(sizeof(requested) / sizeof(requested[0])),
+ NULL, requested);
+
+ /*
+ * Do the request...
*/
- if (strchr(name, ' '))
+ response = cupsDoRequest(http, request, "/");
+
+ if (!response || cupsLastError() > IPP_OK_CONFLICT)
{
/*
- * Lookup the printer-info...
+ * If we can't find the printer by name, look up the printer-name
+ * using the printer-info values...
*/
ipp_attribute_t *accepting_attr,/* printer-is-accepting-jobs */
*state_attr; /* printer-state */
+ ippDelete(response);
+
/*
* Setup the CUPS-Get-Printers request...
*/
request = ippNewRequest(CUPS_GET_PRINTERS);
- ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+ ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes",
(int)(sizeof(requested) / sizeof(requested[0])),
NULL, requested);
}
else
{
- /*
- * Otherwise treat it as a queue name optionally with an instance name.
- */
-
- strlcpy(dest, name, destsize);
- if ((value = strchr(dest, '/')) != NULL)
- *value = '\0';
-
- /*
- * Setup the Get-Printer-Attributes request...
- */
-
- request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
-
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, "/printers/%s", dest);
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
- NULL, uri);
-
- ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- "requested-attributes",
- (int)(sizeof(requested) / sizeof(requested[0])),
- NULL, requested);
-
- /*
- * Do the request...
- */
-
- response = cupsDoRequest(http, request, "/");
-
- if (!response || cupsLastError() > IPP_OK_CONFLICT)
- {
- syslog(LOG_ERR, "Unable to check printer status - %s",
- cupsLastErrorString());
-
- ippDelete(response);
-
- return (-1);
- }
-
/*
* Get values from the response...
*/
if (accepting)
{
if ((attr = ippFindAttribute(response, "printer-is-accepting-jobs",
- IPP_TAG_BOOLEAN)) == NULL)
+ IPP_TAG_BOOLEAN)) == NULL)
syslog(LOG_ERR, "No printer-is-accepting-jobs attribute found in "
- "response from server!");
+ "response from server!");
else
*accepting = attr->values[0].boolean;
}
if (shared)
{
if ((attr = ippFindAttribute(response, "printer-is-shared",
- IPP_TAG_BOOLEAN)) == NULL)
+ IPP_TAG_BOOLEAN)) == NULL)
{
syslog(LOG_ERR, "No printer-is-shared attribute found in "
- "response from server!");
+ "response from server!");
*shared = 1;
}
else
if (state)
{
if ((attr = ippFindAttribute(response, "printer-state",
- IPP_TAG_INTEGER)) == NULL)
+ IPP_TAG_ENUM)) == NULL)
syslog(LOG_ERR, "No printer-state attribute found in "
- "response from server!");
+ "response from server!");
else
*state = (ipp_pstate_t)attr->values[0].integer;
}
#ifdef HAVE_CFPRIV_H /* MacOS X */
if (shared && *shared)
{
- CFURLRef prefsurl; /* */
- CFDataRef xmldata; /* */
- CFPropertyListRef plist; /* */
- CFStringRef queueid; /* */
- CFArrayRef lprqarray; /* */
- CFBooleanRef serverflag; /* */
- Boolean prefsok; /* */
+ CFURLRef prefsurl; /* URL for preferences file */
+ CFDataRef xmldata; /* XML data from preferences file */
+ CFPropertyListRef plist; /* Property list from XML data */
+ CFStringRef queueid; /* CFString of destination name */
+ CFArrayRef lprqarray; /* Array of shared "LPR" printers */
+ CFBooleanRef serverflag; /* State of the print service */
static const char printerprefsfile[] =
"/Library/Preferences/com.apple.printservice.plist";
/* Preferences file */
false);
if (prefsurl)
{
- prefsok = CFURLCreateDataAndPropertiesFromResource(
- kCFAllocatorDefault, prefsurl, &xmldata,
- NULL, NULL, NULL);
- if (prefsok)
+ if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
+ prefsurl, &xmldata, NULL,
+ NULL, NULL))
{
plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, xmldata,
- kCFPropertyListImmutable, NULL);
+ kCFPropertyListImmutable,
+ NULL);
if (plist)
{
serverflag = (CFBooleanRef)CFDictionaryGetValue(
- (CFDictionaryRef)plist, CFSTR("serviceState"));
+ (CFDictionaryRef)plist,
+ CFSTR("serviceState"));
if (serverflag && CFBooleanGetValue(serverflag))
{
lprqarray = (CFArrayRef)CFDictionaryGetValue(
- (CFDictionaryRef)plist, CFSTR("lprSharedQueues"));
+ (CFDictionaryRef)plist,
+ CFSTR("lprSharedQueues"));
if (lprqarray)
{
if (queueid)
{
- *shared = CFArrayContainsValue(
- lprqarray,
- CFRangeMake(0, CFArrayGetCount(lprqarray)),
- queueid);
+ *shared = CFArrayContainsValue(lprqarray,
+ CFRangeMake(0,
+ CFArrayGetCount(lprqarray)),
+ queueid);
CFRelease(queueid);
}
-
- CFRelease(lprqarray);
}
}
- if (serverflag)
- CFRelease(serverflag);
-
CFRelease(plist);
}
+
+ CFRelease(xmldata);
}
CFRelease(prefsurl);
"on queue: %s", name);
}
}
-#endif /* HAVE_CFPRIV_H */
+#endif /* HAVE_CFPRIV_H */
/*
* Next look for the printer in the lpoptions file...
const char *filename, /* I - File to print */
const char *docname, /* I - document-name */
const char *user, /* I - requesting-user-name */
+ const char *format, /* I - document-format */
int last) /* I - 1 = last file in job */
{
ipp_t *request; /* IPP request */
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"document-name", NULL, docname);
+ if (format)
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE,
+ "document-format", NULL, format);
+
if (last)
ippAddBoolean(request, IPP_TAG_OPERATION, "last-document", 1);
docnumber ++;
if (print_file(http, id, temp[i], docname, user,
+ cupsGetOption("document-format", num_options,
+ options),
docnumber == doccount))
status = 1;
else
if (status)
break;
}
-
- fclose(fp);
}
+
+ fclose(fp);
}
}
return (1);
}
else
- syslog(LOG_INFO, "Job ID %d cancelled", id);
+ syslog(LOG_INFO, "Job ID %d canceled", id);
}
httpClose(http);
/*
- * End of "$Id$".
+ * End of "$Id: cups-lpd.c 6781 2007-08-08 21:09:31Z mike $".
*/