]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/adminutil.c
Merge changes from CUPS 1.4svn-r7851.
[thirdparty/cups.git] / cups / adminutil.c
index 3ea7e81af5fe3d5e31bdf398ea5cb165aa8d8d7f..96354a1120488f929aaa268a933b8676ff6106ad 100644 (file)
@@ -894,7 +894,58 @@ _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)
   {