]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/getdevices.c
Merge changes from CUPS 1.5svn-r9062.
[thirdparty/cups.git] / cups / getdevices.c
index 76122ceadd7e8c2cfe4e0df7fc68d331e3429f19..a74a593c714f2fb40de372b153a551395cb95824 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * "$Id$"
  *
- *   cupsGetDevices implementation for the Common UNIX Printing System (CUPS).
+ *   cupsGetDevices implementation for CUPS.
  *
  *   Copyright 2008-2010 by Apple Inc.
  *
@@ -22,8 +22,7 @@
  * Include necessary headers...
  */
 
-#include "globals.h"
-#include "debug.h"
+#include "cups-private.h"
 
 
 /*
@@ -107,15 +106,55 @@ cupsGetDevices(
   }
 
  /*
-  * Send the request...
+  * Send the request and do any necessary authentication...
   */
 
-  DEBUG_puts("2cupsGetDevices: Sending request...");
-  status = cupsSendRequest(http, request, "/", ippLength(request));
+  do
+  {
+    DEBUG_puts("2cupsGetDevices: Sending request...");
+    status = cupsSendRequest(http, request, "/", ippLength(request));
+
+    DEBUG_puts("2cupsGetDevices: Waiting for response status...");
+    while (status == HTTP_CONTINUE)
+      status = httpUpdate(http);
+
+    if (status != HTTP_OK)
+    {
+      httpFlush(http);
+
+      if (status == HTTP_UNAUTHORIZED)
+      {
+       /*
+       * See if we can do authentication...
+       */
+
+       DEBUG_puts("2cupsGetDevices: Need authorization...");
+
+       if (!cupsDoAuthentication(http, "POST", "/"))
+         httpReconnect(http);
+       else
+       {
+         status = HTTP_AUTHORIZATION_CANCELED;
+         break;
+       }
+      }
+
+#ifdef HAVE_SSL
+      else if (status == HTTP_UPGRADE_REQUIRED)
+      {
+       /*
+       * Force a reconnect with encryption...
+       */
+
+       DEBUG_puts("2cupsGetDevices: Need encryption...");
 
-  DEBUG_puts("2cupsGetDevices: Waiting for response status...");
-  while (status == HTTP_CONTINUE)
-    status = httpUpdate(http);
+       if (!httpReconnect(http))
+         httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+      }
+#endif /* HAVE_SSL */
+    }
+  }
+  while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED);
 
   DEBUG_printf(("2cupsGetDevices: status=%d", status));