/*
- * "$Id: lpadmin.c 5023 2006-01-29 14:39:44Z mike $"
+ * "$Id: lpadmin.c 7720 2008-07-11 22:46:21Z mike $"
*
* "lpadmin" command for the Common UNIX Printing System (CUPS).
*
+ * Copyright 2007-2009 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* 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:
*
cups_option_t *options; /* Options */
+ _cupsSetLocale(argv);
+
http = NULL;
printer = NULL;
num_options = 0;
_cupsLangPuts(stderr,
_("lpadmin: Unable to add a printer to the class:\n"
" You must specify a printer name "
- "first!\n"));
+ "first\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected class name after \'-c\' "
- "option!\n"));
+ "option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Class name can only contain printable "
- "characters!\n"));
+ "characters\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected printer name after \'-d\' "
- "option!\n"));
+ "option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Printer name can only contain "
- "printable characters!\n"));
+ "printable characters\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected hostname after \'-h\' "
- "option!\n"));
+ "option\n"));
return (1);
}
_cupsLangPuts(stderr,
_("lpadmin: Unable to set the interface script:\n"
" You must specify a printer name "
- "first!\n"));
+ "first\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected interface after \'-i\' "
- "option!\n"));
+ "option\n"));
return (1);
}
httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
#else
_cupsLangPrintf(stderr,
- _("%s: Sorry, no encryption support compiled in!\n"),
+ _("%s: Sorry, no encryption support compiled in\n"),
argv[0]);
#endif /* HAVE_SSL */
break;
_("lpadmin: Unable to set the interface script or "
"PPD file:\n"
" You must specify a printer name "
- "first!\n"));
+ "first\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected model after \'-m\' "
- "option!\n"));
+ "option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected name=value after \'-o\' "
- "option!\n"));
+ "option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected printer after \'-p\' "
- "option!\n"));
+ "option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Printer name can only contain "
- "printable characters!\n"));
+ "printable characters\n"));
return (1);
}
break;
_("lpadmin: Unable to remove a printer from the "
"class:\n"
" You must specify a printer name "
- "first!\n"));
+ "first\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected class after \'-r\' "
- "option!\n"));
+ "option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Class name can only contain printable "
- "characters!\n"));
+ "characters\n"));
return (1);
}
return (1);
break;
+ case 'U' : /* Username */
+ if (argv[i][2] != '\0')
+ cupsSetUser(argv[i] + 2);
+ else
+ {
+ i ++;
+ if (i >= argc)
+ {
+ _cupsLangPrintf(stderr,
+ _("%s: Error - expected username after "
+ "\'-U\' option\n"),
+ argv[0]);
+ return (1);
+ }
+
+ cupsSetUser(argv[i]);
+ }
+ break;
+
case 'u' : /* Allow/deny users */
if (argv[i][2])
val = argv[i] + 2;
{
_cupsLangPuts(stderr,
_("lpadmin: Expected allow/deny:userlist after "
- "\'-u\' option!\n"));
+ "\'-u\' option\n"));
return (1);
}
else
{
_cupsLangPrintf(stderr,
- _("lpadmin: Unknown allow/deny option \"%s\"!\n"),
+ _("lpadmin: Unknown allow/deny option \"%s\"\n"),
val);
return (1);
}
_cupsLangPuts(stderr,
_("lpadmin: Unable to set the device URI:\n"
" You must specify a printer name "
- "first!\n"));
+ "first\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected device URI after \'-v\' "
- "option!\n"));
+ "option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected printer or class after "
- "\'-x\' option!\n"));
+ "\'-x\' option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Printer name can only contain "
- "printable characters!\n"));
+ "printable characters\n"));
return (1);
}
_("lpadmin: Unable to set the printer "
"description:\n"
" You must specify a printer name "
- "first!\n"));
+ "first\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected description after "
- "\'-D\' option!\n"));
+ "\'-D\' option\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected file type(s) after \'-I\' "
- "option!\n"));
+ "option\n"));
return (1);
}
_cupsLangPuts(stderr,
- _("lpadmin: Warning - content type list ignored!\n"));
+ _("lpadmin: Warning - content type list ignored\n"));
break;
case 'L' : /* Set the printer-location attribute */
_cupsLangPuts(stderr,
_("lpadmin: Unable to set the printer location:\n"
" You must specify a printer name "
- "first!\n"));
+ "first\n"));
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Expected location after \'-L\' "
- "option!\n"));
+ "option\n"));
return (1);
}
_cupsLangPuts(stderr,
_("lpadmin: Unable to set the PPD file:\n"
" You must specify a printer name "
- "first!\n"));
+ "first\n"));
return (1);
}
if (i >= argc)
{
_cupsLangPuts(stderr,
- _("lpadmin: Expected PPD after \'-P\' option!\n"));
+ _("lpadmin: Expected PPD after \'-P\' option\n"));
return (1);
}
default :
_cupsLangPrintf(stderr,
- _("lpadmin: Unknown option \'%c\'!\n"), argv[i][1]);
+ _("lpadmin: Unknown option \'%c\'\n"), argv[i][1]);
return (1);
}
else
{
- _cupsLangPrintf(stderr, _("lpadmin: Unknown argument \'%s\'!\n"),
+ _cupsLangPrintf(stderr, _("lpadmin: Unknown argument \'%s\'\n"),
argv[i]);
return (1);
}
{
_cupsLangPuts(stderr,
_("lpadmin: Unable to set the printer options:\n"
- " You must specify a printer name first!\n"));
+ " You must specify a printer name first\n"));
return (1);
}
attr = ippAddStrings(request, IPP_TAG_PRINTER, IPP_TAG_URI,
"member-uris", members->num_values + 1, NULL, NULL);
for (i = 0; i < members->num_values; i ++)
- attr->values[i].string.text = strdup(members->values[i].string.text);
+ attr->values[i].string.text = _cupsStrAlloc(members->values[i].string.text);
- attr->values[i].string.text = strdup(uri);
+ attr->values[i].string.text = _cupsStrAlloc(uri);
}
else
- attr = ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, "member-uris", NULL, uri);
+ ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, "member-uris", NULL,
+ uri);
/*
* Then send the request...
if ((members = ippFindAttribute(response, "member-names", IPP_TAG_NAME)) == NULL)
{
- _cupsLangPuts(stderr, _("lpadmin: No member names were seen!\n"));
+ _cupsLangPuts(stderr, _("lpadmin: No member names were seen\n"));
ippDelete(response);
for (j = 0, k = 0; j < members->num_values; j ++)
if (j != i)
- attr->values[k ++].string.text = strdup(members->values[j].string.text);
+ attr->values[k ++].string.text =
+ _cupsStrAlloc(members->values[j].string.text);
}
/*
if ((fd = cupsTempFd(tempfile, sizeof(tempfile))) < 0)
{
- _cupsLangPrintf(stderr,
- _("lpadmin: Unable to create temporary file: %s\n"),
- strerror(errno));
+ _cupsLangPrintError(_("ERROR: Unable to create temporary file"));
return (1);
}
*response; /* IPP Response */
ipp_attribute_t *attr; /* IPP attribute */
ipp_op_t op; /* Operation to perform */
- const char *val, /* Option value */
- *ppdfile; /* PPD filename */
+ const char *ppdfile; /* PPD filename */
+ int ppdchanged; /* PPD changed? */
+ ppd_file_t *ppd; /* PPD file */
+ ppd_choice_t *choice; /* Marked choice */
char uri[HTTP_MAX_URI], /* URI for printer/class */
line[1024], /* Line from PPD file */
keyword[1024], /* Keyword from Default line */
FILE *in, /* PPD file */
*out; /* Temporary file */
int outfd; /* Temporary file descriptor */
- const char *protocol; /* Protocol */
+ const char *protocol; /* Old protocol option */
DEBUG_printf(("set_printer_options(%p, \"%s\", %d, %p)\n", http, printer,
* See what kind of printer or class it is...
*/
- if ((attr = ippFindAttribute(response, "printer-type", IPP_TAG_ENUM)) != NULL)
+ if ((attr = ippFindAttribute(response, "printer-type",
+ IPP_TAG_ENUM)) != NULL)
{
if (attr->values[0].integer & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
{
* Add the options...
*/
- cupsEncodeOptions(request, num_options, options);
+ cupsEncodeOptions2(request, num_options, options, IPP_TAG_PRINTER);
+
+ if ((protocol = cupsGetOption("protocol", num_options, options)) != NULL)
+ {
+ if (!strcasecmp(protocol, "bcp"))
+ ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
+ NULL, "bcp");
+ else if (!strcasecmp(protocol, "tbcp"))
+ ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
+ NULL, "tbcp");
+ }
if (op == CUPS_ADD_PRINTER)
ppdfile = cupsGetPPD(printer);
* Set default options in the PPD file...
*/
+ ppd = ppdOpenFile(ppdfile);
+ ppdMarkDefaults(ppd);
+ cupsMarkOptions(ppd, num_options, options);
+
if ((outfd = cupsTempFd(tempfile, sizeof(tempfile))) < 0)
{
- _cupsLangPrintf(stderr,
- _("lpadmin: Unable to create temporary file - %s\n"),
- strerror(errno));
+ _cupsLangPrintError(_("ERROR: Unable to create temporary file"));
ippDelete(request);
unlink(ppdfile);
return (1);
return (1);
}
- out = fdopen(outfd, "wb");
- protocol = cupsGetOption("protocol", num_options, options);
+ out = fdopen(outfd, "wb");
+ ppdchanged = 0;
while (get_line(line, sizeof(line), in) != NULL)
{
- if (!strncmp(line, "*cupsProtocol:", 14) && protocol)
- {
- /*
- * Set a new output protocol (BCP or TBCP) below...
- */
-
- continue;
- }
- else if (strncmp(line, "*Default", 8))
+ if (strncmp(line, "*Default", 8))
fprintf(out, "%s\n", line);
else
{
if (*keyptr == ':' || isspace(*keyptr & 255))
break;
- *keyptr = '\0';
-
- if (!strcmp(keyword, "PageRegion"))
- val = cupsGetOption("PageSize", num_options, options);
+ *keyptr++ = '\0';
+ while (isspace(*keyptr & 255))
+ keyptr ++;
+
+ if (!strcmp(keyword, "PageRegion") ||
+ !strcmp(keyword, "PageSize") ||
+ !strcmp(keyword, "PaperDimension") ||
+ !strcmp(keyword, "ImageableArea"))
+ {
+ if ((choice = ppdFindMarkedChoice(ppd, "PageSize")) == NULL)
+ choice = ppdFindMarkedChoice(ppd, "PageRegion");
+ }
else
- val = cupsGetOption(keyword, num_options, options);
+ choice = ppdFindMarkedChoice(ppd, keyword);
- if (val != NULL)
- fprintf(out, "*Default%s: %s\n", keyword, val);
+ if (choice && strcmp(choice->choice, keyptr))
+ {
+ fprintf(out, "*Default%s: %s\n", keyword, choice->choice);
+ ppdchanged = 1;
+ }
else
fprintf(out, "%s\n", line);
}
}
- if (protocol)
- fprintf(out, "*cupsProtocol: \"%s\"\n", protocol);
-
fclose(in);
fclose(out);
close(outfd);
+ ppdClose(ppd);
/*
* Do the request...
*/
- response = cupsDoFileRequest(http, request, "/admin/", tempfile);
+ ippDelete(cupsDoFileRequest(http, request, "/admin/",
+ ppdchanged ? tempfile : NULL));
/*
* Clean up temp files... (TODO: catch signals in case we CTRL-C during
* No PPD file - just set the options...
*/
- response = cupsDoRequest(http, request, "/admin/");
+ ippDelete(cupsDoRequest(http, request, "/admin/"));
}
/*
* Check the response...
*/
- ippDelete(response);
if (cupsLastError() > IPP_OK_CONFLICT)
{
_cupsLangPrintf(stderr, "lpadmin: %s\n", cupsLastErrorString());
/*
- * End of "$Id: lpadmin.c 5023 2006-01-29 14:39:44Z mike $".
+ * End of "$Id: lpadmin.c 7720 2008-07-11 22:46:21Z mike $".
*/