]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/adminutil.c
Merge changes from CUPS 1.4svn-r8177 (tentative CUPS 1.4b2)
[thirdparty/cups.git] / cups / adminutil.c
index e3adf54b448ecd5350f4bc5647b0394c728b8e71..8ef12ad5bb2b1d75f011db63e6d4d3f99953c8ba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: adminutil.c 6930 2007-09-08 00:28:06Z mike $"
+ * "$Id: adminutil.c 7850 2008-08-20 00:07:25Z mike $"
  *
  *   Administration utility API definitions for the Common UNIX Printing
  *   System (CUPS).
@@ -75,6 +75,8 @@ static void           write_option(cups_file_t *dstfp, int order,
 
 /*
  * 'cupsAdminCreateWindowsPPD()' - Create the Windows PPD file for a printer.
+ *
+ * @since CUPS 1.2/Mac OS X 10.5@
  */
 
 char *                                 /* O - PPD file or NULL */
@@ -260,9 +262,9 @@ cupsAdminCreateWindowsPPD(
       if ((ptr = strchr(line, ':')) == NULL)
       {
         snprintf(line, sizeof(line),
-                 _cupsLangString(language, _("Missing value on line %d!")),
-                 linenum);
-        _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
+                _cupsLangString(language, _("Missing value on line %d!")),
+                linenum);
+        _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
 
         cupsFileClose(srcfp);
         cupsFileClose(dstfp);
@@ -281,7 +283,7 @@ cupsAdminCreateWindowsPPD(
                 _cupsLangString(language,
                                 _("Missing double quote on line %d!")),
                 linenum);
-        _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
+        _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
 
         cupsFileClose(srcfp);
         cupsFileClose(dstfp);
@@ -300,7 +302,7 @@ cupsAdminCreateWindowsPPD(
                 _cupsLangString(language,
                                 _("Bad option + choice on line %d!")),
                 linenum);
-        _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
+        _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line, 0);
 
         cupsFileClose(srcfp);
         cupsFileClose(dstfp);
@@ -343,10 +345,7 @@ cupsAdminCreateWindowsPPD(
 
   if (linenum == 0)
   {
-    snprintf(line, sizeof(line),
-             _cupsLangString(language, _("Empty PPD file!")),
-             linenum);
-    _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, line);
+    _cupsSetError(IPP_DOCUMENT_FORMAT_ERROR, _("Empty PPD file!"), 1);
 
     cupsFileClose(dstfp);
     unlink(buffer);
@@ -389,7 +388,7 @@ cupsAdminCreateWindowsPPD(
   {
     write_option(dstfp, jclorder ++, "cupsJobSheetsStart", "Start Banner",
                  "job-sheets", suppattr, defattr, 0, 2);
-    write_option(dstfp, jclorder ++, "cupsJobSheetsEnd", "End Banner",
+    write_option(dstfp, jclorder, "cupsJobSheetsEnd", "End Banner",
                  "job-sheets", suppattr, defattr, 1, 2);
   }
 
@@ -404,6 +403,8 @@ cupsAdminCreateWindowsPPD(
 
 /*
  * 'cupsAdminExportSamba()' - Export a printer to Samba.
+ *
+ * @since CUPS 1.2/Mac OS X 10.5@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -434,7 +435,7 @@ cupsAdminExportSamba(
 
   if (!dest || !ppd || !samba_server || !samba_user || !samba_password)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
     return (0);
   }
 
@@ -444,7 +445,7 @@ cupsAdminExportSamba(
 
   if ((fp = cupsTempFile2(authfile, sizeof(authfile))) == NULL)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+    _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
     return (0);
   }
 
@@ -497,7 +498,7 @@ cupsAdminExportSamba(
                               _("Unable to copy Windows 2000 printer "
                                 "driver files (%d)!")), status);
 
-      _cupsSetError(IPP_INTERNAL_ERROR, message);
+      _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
        _cupsLangPrintf(logfile, "%s\n", message);
@@ -532,7 +533,7 @@ cupsAdminExportSamba(
                                 _("Unable to copy CUPS printer driver "
                                   "files (%d)!")), status);
 
-       _cupsSetError(IPP_INTERNAL_ERROR, message);
+       _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
        if (logfile)
          _cupsLangPrintf(logfile, "%s\n", message);
@@ -575,7 +576,7 @@ cupsAdminExportSamba(
                               _("Unable to install Windows 2000 printer "
                                 "driver files (%d)!")), status);
 
-      _cupsSetError(IPP_INTERNAL_ERROR, message);
+      _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
        _cupsLangPrintf(logfile, "%s\n", message);
@@ -620,7 +621,7 @@ cupsAdminExportSamba(
                               _("Unable to copy Windows 9x printer "
                                 "driver files (%d)!")), status);
 
-      _cupsSetError(IPP_INTERNAL_ERROR, message);
+      _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
        _cupsLangPrintf(logfile, "%s\n", message);
@@ -649,7 +650,7 @@ cupsAdminExportSamba(
                               _("Unable to install Windows 9x printer "
                                 "driver files (%d)!")), status);
 
-      _cupsSetError(IPP_INTERNAL_ERROR, message);
+      _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
        _cupsLangPrintf(logfile, "%s\n", message);
@@ -701,7 +702,7 @@ cupsAdminExportSamba(
                               _("Unable to copy 64-bit Windows printer "
                                 "driver files (%d)!")), status);
 
-      _cupsSetError(IPP_INTERNAL_ERROR, message);
+      _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
        _cupsLangPrintf(logfile, "%s\n", message);
@@ -736,7 +737,7 @@ cupsAdminExportSamba(
                                 _("Unable to copy 64-bit CUPS printer driver "
                                   "files (%d)!")), status);
 
-       _cupsSetError(IPP_INTERNAL_ERROR, message);
+       _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
        if (logfile)
          _cupsLangPrintf(logfile, "%s\n", message);
@@ -779,7 +780,7 @@ cupsAdminExportSamba(
                               _("Unable to install Windows 2000 printer "
                                 "driver files (%d)!")), status);
 
-      _cupsSetError(IPP_INTERNAL_ERROR, message);
+      _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       if (logfile)
        _cupsLangPrintf(logfile, "%s\n", message);
@@ -804,13 +805,13 @@ cupsAdminExportSamba(
                                "are installed!")),
               sizeof(message));
 
-    _cupsSetError(IPP_NOT_FOUND, message);
+    _cupsSetError(IPP_NOT_FOUND, message, 0);
     _cupsLangPrintf(logfile, "%s\n", message);
   }
 
   if (have_drivers == 0)
   {
-    _cupsSetError(IPP_NOT_FOUND, message);
+    _cupsSetError(IPP_NOT_FOUND, message, 0);
 
     unlink(authfile);
 
@@ -831,7 +832,7 @@ cupsAdminExportSamba(
                             _("Unable to set Windows printer driver (%d)!")),
                             status);
 
-    _cupsSetError(IPP_INTERNAL_ERROR, message);
+    _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
     if (logfile)
       _cupsLangPrintf(logfile, "%s\n", message);
@@ -853,7 +854,7 @@ cupsAdminExportSamba(
  * The returned settings should be freed with cupsFreeOptions() when
  * you are done with them.
  *
- * @since CUPS 1.3@
+ * @since CUPS 1.3/Mac OS X 10.5@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -897,11 +898,62 @@ _cupsAdminGetServerSettings(
   */
 
   if (!http)
-    http = _cupsConnect();
+  {
+   /*
+    * See if we are connected to the same server...
+    */
+
+    if (cg->http)
+    {
+     /*
+      * Compare the connection hostname, port, and encryption settings to
+      * the cached defaults; these were initialized the first time we
+      * connected...
+      */
+
+      if (strcmp(cg->http->hostname, cg->server) ||
+          cg->ipp_port != _httpAddrPort(cg->http->hostaddr) ||
+         (cg->http->encryption != cg->encryption &&
+          cg->http->encryption == HTTP_ENCRYPT_NEVER))
+      {
+       /*
+       * Need to close the current connection because something has changed...
+       */
+
+       httpClose(cg->http);
+       cg->http = NULL;
+      }
+    }
+
+   /*
+    * (Re)connect as needed...
+    */
+
+    if (!cg->http)
+    {
+      if ((cg->http = _httpCreate(cupsServer(), ippPort(),
+                                  cupsEncryption())) == NULL)
+      {
+       if (errno)
+         _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+       else
+         _cupsSetError(IPP_SERVICE_UNAVAILABLE,
+                       _("Unable to connect to host."), 1);
+
+       if (num_settings)
+         *num_settings = 0;
+
+       if (settings)
+         *settings = NULL;
+
+       return (0);
+      }
+    }
+  }
 
   if (!http || !num_settings || !settings)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
 
     if (num_settings)
       *num_settings = 0;
@@ -928,9 +980,9 @@ _cupsAdminGetServerSettings(
 
 
       snprintf(message, sizeof(message),
-               _cupsLangString(cupsLangDefault(), _("open of %s failed: %s")),
+               _cupsLangString(cupsLangDefault(), _("Open of %s failed: %s")),
                cupsdconf, strerror(errno));
-      _cupsSetError(IPP_INTERNAL_ERROR, message);
+      _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
     }
   }
   else
@@ -967,7 +1019,7 @@ _cupsAdminGetServerSettings(
       if (!value && strncmp(line, "</", 2))
         value = line + strlen(line);
 
-      if (!strcasecmp(line, "Port") || !strcasecmp(line, "Listen"))
+      if ((!strcasecmp(line, "Port") || !strcasecmp(line, "Listen")) && value)
       {
        char    *port;                  /* Pointer to port number, if any */
 
@@ -1023,7 +1075,7 @@ _cupsAdminGetServerSettings(
       {
        in_policy = 0;
       }
-      else if (!strcasecmp(line, "<Limit") && in_policy)
+      else if (!strcasecmp(line, "<Limit") && in_policy && value)
       {
        /*
        * See if the policy limit is for the Cancel-Job operation...
@@ -1056,7 +1108,7 @@ _cupsAdminGetServerSettings(
       {
        cancel_policy = 0;
       }
-      else if (!strcasecmp(line, "<Location"))
+      else if (!strcasecmp(line, "<Location") && value)
       {
         in_admin_location = !strcasecmp(value, "/admin");
        in_location       = 1;
@@ -1066,7 +1118,7 @@ _cupsAdminGetServerSettings(
        in_admin_location = 0;
        in_location       = 0;
       }
-      else if (!strcasecmp(line, "Allow") &&
+      else if (!strcasecmp(line, "Allow") && value &&
                strcasecmp(value, "localhost") && strcasecmp(value, "127.0.0.1")
 #ifdef AF_LOCAL
               && *value != '/'
@@ -1145,7 +1197,7 @@ _cupsAdminGetServerSettings(
 /*
  * 'cupsAdminSetServerSettings()' - Set settings on the server.
  *
- * @since CUPS 1.3@
+ * @since CUPS 1.3/Mac OS X 10.5@
  */
 
 int                                    /* O - 1 on success, 0 on failure */
@@ -1224,7 +1276,7 @@ _cupsAdminSetServerSettings(
 
   if (!http || !num_settings || !settings)
   {
-    _cupsSetError(IPP_INTERNAL_ERROR, NULL);
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
 
     return (0);
   }
@@ -1233,12 +1285,12 @@ _cupsAdminSetServerSettings(
   * Get the cupsd.conf file...
   */
 
-  if ((status = get_cupsd_conf(http, cg, 0, cupsdconf, sizeof(cupsdconf),
-                               &remote)) == HTTP_OK)
+  if (get_cupsd_conf(http, cg, 0, cupsdconf, sizeof(cupsdconf),
+                     &remote) == HTTP_OK)
   {
     if ((cupsd = cupsFileOpen(cupsdconf, "r")) == NULL)
     {
-      _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+      _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
       return (0);
     }
   }
@@ -1395,7 +1447,7 @@ _cupsAdminSetServerSettings(
     if (remote)
       unlink(cupsdconf);
 
-    _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+    _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
     return (0);
   }
 
@@ -1518,27 +1570,33 @@ _cupsAdminSetServerSettings(
          {
            cupsFilePuts(temp, "BrowseAllow all\n");
 
-           if (!remotep || !*remotep)
-             cupsFilePuts(temp, "BrowseRemoteProtocols "
-                                CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS "\n");
-            else if (remotep)
-             cupsFilePrintf(temp, "BrowseRemoteProtocols %s\n", remotep);
+           if (!remotep)
+             remotep = CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS;
+
+           cupsFilePrintf(temp, "BrowseRemoteProtocols %s\n", remotep);
           }
          else
            cupsFilePuts(temp, "BrowseRemoteProtocols\n");
 
+         cupsd_num_settings = cupsAddOption("BrowseRemoteProtocols", remotep,
+                                            cupsd_num_settings,
+                                            &cupsd_settings);
+
          if (new_share_printers)
          {
            cupsFilePuts(temp, "BrowseAddress @LOCAL\n");
 
-           if (!localp || !*localp)
-             cupsFilePuts(temp, "BrowseLocalProtocols "
-                                CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS "\n");
-            else if (localp)
-             cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp);
+           if (!localp)
+             localp = CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS;
+
+           cupsFilePrintf(temp, "BrowseLocalProtocols %s\n", localp);
          }
          else
            cupsFilePuts(temp, "BrowseLocalProtocols\n");
+
+         cupsd_num_settings = cupsAddOption("BrowseLocalProtocols", localp,
+                                            cupsd_num_settings,
+                                            &cupsd_settings);
         }
        else
        {
@@ -1561,7 +1619,7 @@ _cupsAdminSetServerSettings(
       else
       {
         cupsFilePuts(temp, "# Show general information in error_log.\n");
-       cupsFilePuts(temp, "LogLevel info\n");
+       cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n");
       }
     }
     else if (!strcasecmp(line, "<Policy"))
@@ -1740,8 +1798,7 @@ _cupsAdminSetServerSettings(
     else if ((((in_admin_location || in_conf_location || in_root_location) &&
                remote_admin >= 0) ||
               (in_root_location && share_printers >= 0)) &&
-             (((!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny")) &&
-              !strcasecmp(value, "@LOCAL")) ||
+             (!strcasecmp(line, "Allow") || !strcasecmp(line, "Deny") ||
              !strcasecmp(line, "Order")))
       continue;
     else if (in_cancel_job == 2)
@@ -1841,7 +1898,7 @@ _cupsAdminSetServerSettings(
     else
     {
       cupsFilePuts(temp, "# Show general information in error_log.\n");
-      cupsFilePuts(temp, "LogLevel info\n");
+      cupsFilePuts(temp, "LogLevel " CUPS_DEFAULT_LOG_LEVEL "\n");
     }
   }
 
@@ -2203,7 +2260,7 @@ get_cupsd_conf(
       snprintf(message, sizeof(message),
                _cupsLangString(cupsLangDefault(), _("stat of %s failed: %s")),
                name, strerror(errno));
-      _cupsSetError(IPP_INTERNAL_ERROR, message);
+      _cupsSetError(IPP_INTERNAL_ERROR, message, 0);
 
       *name = '\0';
 
@@ -2225,7 +2282,7 @@ get_cupsd_conf(
     {
       *name = '\0';
 
-      _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno));
+      _cupsSetError(IPP_INTERNAL_ERROR, NULL, 0);
 
       invalidate_cupsd_cache(cg);
 
@@ -2382,5 +2439,5 @@ write_option(cups_file_t     *dstfp,      /* I - PPD file */
 
 
 /*
- * End of "$Id: adminutil.c 6930 2007-09-08 00:28:06Z mike $".
+ * End of "$Id: adminutil.c 7850 2008-08-20 00:07:25Z mike $".
  */