]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/getdevices.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cups / getdevices.c
index 4f5f8d00049f8e2be58cf8167e8a15cd6d169ef9..e0ac9b5ccd50186756a3b469b910d2ce130c2c55 100644 (file)
@@ -1,29 +1,17 @@
 /*
- * "$Id$"
+ * cupsGetDevices implementation for CUPS.
  *
- *   cupsGetDevices implementation for the Common UNIX Printing System (CUPS).
+ * Copyright 2008-2016 by Apple Inc.
  *
- *   Copyright 2008 by Apple Inc.
- *
- *   These coded instructions, statements, and computer programs are the
- *   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/".
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   cupsGetDevices() - Get available printer devices.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include "globals.h"
-#include "debug.h"
+#include "cups-private.h"
+#include "adminutil.h"
 
 
 /*
@@ -35,7 +23,7 @@
  * parameters provide comma-delimited lists of backends to include or omit from
  * the request respectively.
  *
- * @since CUPS 1.4@
+ * @since CUPS 1.4/macOS 10.6@
  */
 
 ipp_status_t                           /* O - Request status - @code IPP_OK@ on success. */
@@ -66,20 +54,22 @@ cupsGetDevices(
   * Range check input...
   */
 
+  DEBUG_printf(("cupsGetDevices(http=%p, timeout=%d, include_schemes=\"%s\", exclude_schemes=\"%s\", callback=%p, user_data=%p)", (void *)http, timeout, include_schemes, exclude_schemes, (void *)callback, user_data));
+
   if (!callback)
-    return (IPP_INTERNAL_ERROR);
+    return (IPP_STATUS_ERROR_INTERNAL);
 
   if (!http)
     http = _cupsConnect();
 
   if (!http)
-    return (IPP_SERVICE_UNAVAILABLE);
+    return (IPP_STATUS_ERROR_SERVICE_UNAVAILABLE);
 
  /*
   * Create a CUPS-Get-Devices request...
   */
 
-  request = ippNewRequest(CUPS_GET_DEVICES);
+  request = ippNewRequest(IPP_OP_CUPS_GET_DEVICES);
 
   if (timeout > 0)
     ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "timeout",
@@ -107,55 +97,57 @@ cupsGetDevices(
 
   do
   {
-    DEBUG_puts("cupsGetDevices: Sending request...");
+    DEBUG_puts("2cupsGetDevices: Sending request...");
     status = cupsSendRequest(http, request, "/", ippLength(request));
 
-    DEBUG_puts("cupsGetDevices: Waiting for response status...");
-    while (status == HTTP_CONTINUE)
+    DEBUG_puts("2cupsGetDevices: Waiting for response status...");
+    while (status == HTTP_STATUS_CONTINUE)
       status = httpUpdate(http);
 
-    if (status != HTTP_OK)
+    if (status != HTTP_STATUS_OK)
     {
       httpFlush(http);
 
-      if (status == HTTP_UNAUTHORIZED)
+      if (status == HTTP_STATUS_UNAUTHORIZED)
       {
        /*
        * See if we can do authentication...
        */
 
-       int auth_result;
+       DEBUG_puts("2cupsGetDevices: Need authorization...");
 
-       DEBUG_puts("cupsGetDevices: Need authorization...");
-
-       if ((auth_result = cupsDoAuthentication(http, "POST", "/")) == 0)
-         httpReconnect(http);
-       else if (auth_result < 0)
-         http->status = status = HTTP_FORBIDDEN;
+       if (!cupsDoAuthentication(http, "POST", "/"))
+         httpReconnect2(http, 30000, NULL);
+       else
+       {
+         status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
+         break;
+       }
       }
 
 #ifdef HAVE_SSL
-      else if (status == HTTP_UPGRADE_REQUIRED)
+      else if (status == HTTP_STATUS_UPGRADE_REQUIRED)
       {
        /*
        * Force a reconnect with encryption...
        */
 
-       DEBUG_puts("cupsGetDevices: Need encryption...");
+       DEBUG_puts("2cupsGetDevices: Need encryption...");
 
-       if (!httpReconnect(http))
-         httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+       if (!httpReconnect2(http, 30000, NULL))
+         httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
       }
 #endif /* HAVE_SSL */
     }
   }
-  while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED);
+  while (status == HTTP_STATUS_UNAUTHORIZED ||
+         status == HTTP_STATUS_UPGRADE_REQUIRED);
 
-  DEBUG_printf(("cupsGetDevices: status=%d\n", status));
+  DEBUG_printf(("2cupsGetDevices: status=%d", status));
 
   ippDelete(request);
 
-  if (status != HTTP_OK)
+  if (status != HTTP_STATUS_OK)
   {
     _cupsSetHTTPError(status);
     return (cupsLastError());
@@ -177,15 +169,14 @@ cupsGetDevices(
   device_uri            = NULL;
   attr                  = NULL;
 
-  DEBUG_puts("cupsGetDevices: Reading response...");
+  DEBUG_puts("2cupsGetDevices: Reading response...");
 
   do
   {
-    if ((state = ippRead(http, response)) == IPP_ERROR)
+    if ((state = ippRead(http, response)) == IPP_STATE_ERROR)
       break;
 
-    DEBUG_printf(("cupsGetDevices: state=%d, response->last=%p\n", state,
-                  response->last));
+    DEBUG_printf(("2cupsGetDevices: state=%d, response->last=%p", state, (void *)response->last));
 
     if (!response->attrs)
       continue;
@@ -197,8 +188,8 @@ cupsGetDevices(
       else
         attr = attr->next;
 
-      DEBUG_printf(("cupsGetDevices: attr->name=\"%s\", attr->value_tag=%d\n",
-                    attr->name ? attr->name : "(null)", attr->value_tag));
+      DEBUG_printf(("2cupsGetDevices: attr->name=\"%s\", attr->value_tag=%d",
+                    attr->name, attr->value_tag));
 
       if (!attr->name)
       {
@@ -235,10 +226,9 @@ cupsGetDevices(
         device_uri = attr->values[0].string.text;
     }
   }
-  while (state != IPP_DATA);
+  while (state != IPP_STATE_DATA);
 
-  DEBUG_printf(("cupsGetDevices: state=%d, response->last=%p\n", state,
-               response->last));
+  DEBUG_printf(("2cupsGetDevices: state=%d, response->last=%p", state, (void *)response->last));
 
   if (device_class && device_id && device_info && device_make_and_model &&
       device_uri)
@@ -252,13 +242,13 @@ cupsGetDevices(
   httpBlocking(http, blocking);
   httpFlush(http);
 
-  if (status == IPP_ERROR)
-    _cupsSetError(IPP_ERROR, NULL, 0);
+  if (status == HTTP_STATUS_ERROR)
+    _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(http->error), 0);
   else
   {
     attr = ippFindAttribute(response, "status-message", IPP_TAG_TEXT);
 
-    DEBUG_printf(("cupsGetDevices: status-code=%s, status-message=\"%s\"\n",
+    DEBUG_printf(("cupsGetDevices: status-code=%s, status-message=\"%s\"",
                  ippErrorString(response->request.status.status_code),
                  attr ? attr->values[0].string.text : ""));
 
@@ -271,8 +261,3 @@ cupsGetDevices(
 
   return (cupsLastError());
 }
-
-
-/*
- * End of "$Id$".
- */