X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fcups.git;a=blobdiff_plain;f=cups%2Fgetdevices.c;h=a74a593c714f2fb40de372b153a551395cb95824;hp=76122ceadd7e8c2cfe4e0df7fc68d331e3429f19;hb=5180a04ce8365f7f3e6156fe7389367aee1de9b7;hpb=ba55dc12de9ef3103d220a332ad7d26c54e397fa diff --git a/cups/getdevices.c b/cups/getdevices.c index 76122cead..a74a593c7 100644 --- a/cups/getdevices.c +++ b/cups/getdevices.c @@ -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));