]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpadmin.c
Merge changes from CUPS 1.5svn-r8849.
[thirdparty/cups.git] / systemv / lpadmin.c
index c0467fa7677d0164dd17b9836a94185f1fb7bd3e..81ed5bb9d7fb9886809eae68ac715863290f41d9 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: lpadmin.c 5545 2006-05-18 21:00:56Z 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:
  *
@@ -92,6 +83,8 @@ main(int  argc,                       /* I - Number of command-line arguments */
   cups_option_t        *options;       /* Options */
 
 
+  _cupsSetLocale(argv);
+
   http        = NULL;
   printer     = NULL;
   num_options = 0;
@@ -121,7 +114,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              _cupsLangPuts(stderr,
                            _("lpadmin: Unable to add a printer to the class:\n"
                              "         You must specify a printer name "
-                             "first!\n"));
+                             "first\n"));
              return (1);
            }
 
@@ -135,7 +128,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected class name after \'-c\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -146,7 +139,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
            {
              _cupsLangPuts(stderr,
                            _("lpadmin: Class name can only contain printable "
-                             "characters!\n"));
+                             "characters\n"));
              return (1);
            }
 
@@ -179,7 +172,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected printer name after \'-d\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -190,7 +183,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
            {
              _cupsLangPuts(stderr,
                            _("lpadmin: Printer name can only contain "
-                             "printable characters!\n"));
+                             "printable characters\n"));
              return (1);
            }
 
@@ -217,7 +210,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected hostname after \'-h\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
               }
 
@@ -245,7 +238,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              _cupsLangPuts(stderr,
                            _("lpadmin: Unable to set the interface script:\n"
                              "         You must specify a printer name "
-                             "first!\n"));
+                             "first\n"));
              return (1);
            }
 
@@ -262,7 +255,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected interface after \'-i\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -281,7 +274,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
                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;
@@ -326,7 +319,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
                            _("lpadmin: Unable to set the interface script or "
                              "PPD file:\n"
                              "         You must specify a printer name "
-                             "first!\n"));
+                             "first\n"));
              return (1);
            }
 
@@ -343,7 +336,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected model after \'-m\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -363,7 +356,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected name=value after \'-o\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -396,7 +389,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected printer after \'-p\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -407,7 +400,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
            {
              _cupsLangPuts(stderr,
                            _("lpadmin: Printer name can only contain "
-                             "printable characters!\n"));
+                             "printable characters\n"));
              return (1);
            }
            break;
@@ -433,7 +426,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
                            _("lpadmin: Unable to remove a printer from the "
                              "class:\n"
                              "         You must specify a printer name "
-                             "first!\n"));
+                             "first\n"));
              return (1);
            }
 
@@ -447,7 +440,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected class after \'-r\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -458,7 +451,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
            {
              _cupsLangPuts(stderr,
                            _("lpadmin: Class name can only contain printable "
-                             "characters!\n"));
+                             "characters\n"));
              return (1);
            }
 
@@ -476,7 +469,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPrintf(stderr,
                                _("%s: Error - expected username after "
-                                 "\'-U\' option!\n"),
+                                 "\'-U\' option\n"),
                                argv[0]);
                return (1);
              }
@@ -496,7 +489,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected allow/deny:userlist after "
-                               "\'-u\' option!\n"));
+                               "\'-u\' option\n"));
                return (1);
              }
 
@@ -512,7 +505,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
             else
            {
              _cupsLangPrintf(stderr,
-                             _("lpadmin: Unknown allow/deny option \"%s\"!\n"),
+                             _("lpadmin: Unknown allow/deny option \"%s\"\n"),
                              val);
              return (1);
            }
@@ -538,7 +531,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              _cupsLangPuts(stderr,
                            _("lpadmin: Unable to set the device URI:\n"
                              "         You must specify a printer name "
-                             "first!\n"));
+                             "first\n"));
              return (1);
            }
 
@@ -555,7 +548,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected device URI after \'-v\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -589,7 +582,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected printer or class after "
-                               "\'-x\' option!\n"));
+                               "\'-x\' option\n"));
                return (1);
              }
 
@@ -600,7 +593,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
            {
              _cupsLangPuts(stderr,
                            _("lpadmin: Printer name can only contain "
-                             "printable characters!\n"));
+                             "printable characters\n"));
              return (1);
            }
 
@@ -631,7 +624,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
                            _("lpadmin: Unable to set the printer "
                              "description:\n"
                              "         You must specify a printer name "
-                             "first!\n"));
+                             "first\n"));
              return (1);
            }
 
@@ -648,7 +641,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected description after "
-                               "\'-D\' option!\n"));
+                               "\'-D\' option\n"));
                return (1);
              }
 
@@ -664,12 +657,12 @@ main(int  argc,                   /* I - Number of command-line arguments */
            {
              _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 */
@@ -692,7 +685,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              _cupsLangPuts(stderr,
                            _("lpadmin: Unable to set the printer location:\n"
                              "         You must specify a printer name "
-                             "first!\n"));
+                             "first\n"));
              return (1);
            }
 
@@ -709,7 +702,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              {
                _cupsLangPuts(stderr,
                              _("lpadmin: Expected location after \'-L\' "
-                               "option!\n"));
+                               "option\n"));
                return (1);
              }
 
@@ -738,7 +731,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              _cupsLangPuts(stderr,
                            _("lpadmin: Unable to set the PPD file:\n"
                              "         You must specify a printer name "
-                             "first!\n"));
+                             "first\n"));
              return (1);
            }
 
@@ -754,7 +747,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
              if (i >= argc)
              {
                _cupsLangPuts(stderr,
-                             _("lpadmin: Expected PPD after \'-P\' option!\n"));
+                             _("lpadmin: Expected PPD after \'-P\' option\n"));
                return (1);
              }
 
@@ -765,12 +758,12 @@ main(int  argc,                   /* I - Number of command-line arguments */
 
        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);
     }
@@ -798,7 +791,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
     {
       _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);
     }
 
@@ -921,12 +914,13 @@ add_printer_to_class(http_t *http,        /* I - Server connection */
     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...
@@ -1131,7 +1125,7 @@ delete_printer_from_class(
 
   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);
 
@@ -1196,7 +1190,8 @@ delete_printer_from_class(
 
     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);
   }
 
  /*
@@ -1455,9 +1450,7 @@ set_printer_file(http_t *http,            /* I - Server connection */
 
     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);
     }
 
@@ -1822,10 +1815,10 @@ set_printer_options(
   if ((protocol = cupsGetOption("protocol", num_options, options)) != NULL)
   {
     if (!strcasecmp(protocol, "bcp"))
-      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "port-monitor",
+      ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
                    NULL, "bcp");
     else if (!strcasecmp(protocol, "tbcp"))
-      ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "port-monitor",
+      ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
                    NULL, "tbcp");
   }
 
@@ -1846,9 +1839,7 @@ set_printer_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);
@@ -1984,5 +1975,5 @@ validate_name(const char *name)           /* I - Name to check */
 
 
 /*
- * End of "$Id: lpadmin.c 5545 2006-05-18 21:00:56Z mike $".
+ * End of "$Id: lpadmin.c 7720 2008-07-11 22:46:21Z mike $".
  */