]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/getputfile.c
Merge changes from CUPS 1.4svn-r8606.
[thirdparty/cups.git] / cups / getputfile.c
index 8990751ee406e5ac429871134736a67e631309e1..a8be5aca0bc134c82e984eef26e7e30a3eb61970 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: getputfile.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id: getputfile.c 7359 2008-02-29 19:01:35Z mike $"
  *
  *   Get/put file functions for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 2007 by Apple Inc.
+ *   Copyright 2007-2009 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
  * Include necessary headers...
  */
 
-#include "http-private.h"
+#include "globals.h"
 #include "cups.h"
 #include "language.h"
-#include "string.h"
 #include "debug.h"
 #include <stdlib.h>
 #include <ctype.h>
 /*
  * 'cupsGetFd()' - Get a file from the server.
  *
- * This function returns HTTP_OK when the file is successfully retrieved.
+ * This function returns @code HTTP_OK@ when the file is successfully retrieved.
  *
- * @since CUPS 1.1.20@
+ * @since CUPS 1.1.20/Mac OS X 10.4@
  */
 
 http_status_t                          /* O - HTTP status */
-cupsGetFd(http_t     *http,            /* I - HTTP connection to server */
+cupsGetFd(http_t     *http,            /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
          const char *resource,         /* I - Resource name */
          int        fd)                /* I - File descriptor */
 {
@@ -67,10 +66,10 @@ cupsGetFd(http_t     *http,         /* I - HTTP connection to server */
   * Range check input...
   */
 
-  DEBUG_printf(("cupsGetFd(http=%p, resource=\"%s\", fd=%d)\n", http,
+  DEBUG_printf(("cupsGetFd(http=%p, resource=\"%s\", fd=%d)", http,
                 resource, fd));
 
-  if (!http || !resource || fd < 0)
+  if (!resource || fd < 0)
   {
     if (http)
       http->error = EINVAL;
@@ -78,6 +77,10 @@ cupsGetFd(http_t     *http,          /* I - HTTP connection to server */
     return (HTTP_ERROR);
   }
 
+  if (!http)
+    if ((http = _cupsConnect()) == NULL)
+      return (HTTP_SERVICE_UNAVAILABLE);
+
  /*
   * Then send GET requests to the HTTP server...
   */
@@ -120,7 +123,10 @@ cupsGetFd(http_t     *http,                /* I - HTTP connection to server */
       */
 
       if (cupsDoAuthentication(http, "GET", resource))
+      {
+        status = HTTP_AUTHORIZATION_CANCELED;
         break;
+      }
 
       if (httpReconnect(http))
       {
@@ -167,12 +173,17 @@ cupsGetFd(http_t     *http,               /* I - HTTP connection to server */
       write(fd, buffer, bytes);
   }
   else
+  {
+    _cupsSetHTTPError(status);
     httpFlush(http);
+  }
 
  /*
   * Return the request status...
   */
 
+  DEBUG_printf(("1cupsGetFd: Returning %d...", status));
+
   return (status);
 }
 
@@ -180,13 +191,13 @@ cupsGetFd(http_t     *http,               /* I - HTTP connection to server */
 /*
  * 'cupsGetFile()' - Get a file from the server.
  *
- * This function returns HTTP_OK when the file is successfully retrieved.
+ * This function returns @code HTTP_OK@ when the file is successfully retrieved.
  *
- * @since CUPS 1.1.20@
+ * @since CUPS 1.1.20/Mac OS X 10.4@
  */
 
 http_status_t                          /* O - HTTP status */
-cupsGetFile(http_t     *http,          /* I - HTTP connection to server */
+cupsGetFile(http_t     *http,          /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
            const char *resource,       /* I - Resource name */
            const char *filename)       /* I - Filename */
 {
@@ -247,13 +258,14 @@ cupsGetFile(http_t     *http,             /* I - HTTP connection to server */
 /*
  * 'cupsPutFd()' - Put a file on the server.
  *
- * This function returns HTTP_CREATED when the file is stored successfully.
+ * This function returns @code HTTP_CREATED@ when the file is stored
+ * successfully.
  *
- * @since CUPS 1.1.20@
+ * @since CUPS 1.1.20/Mac OS X 10.4@
  */
 
 http_status_t                          /* O - HTTP status */
-cupsPutFd(http_t     *http,            /* I - HTTP connection to server */
+cupsPutFd(http_t     *http,            /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
           const char *resource,                /* I - Resource name */
          int        fd)                /* I - File descriptor */
 {
@@ -267,10 +279,10 @@ cupsPutFd(http_t     *http,               /* I - HTTP connection to server */
   * Range check input...
   */
 
-  DEBUG_printf(("cupsPutFd(http=%p, resource=\"%s\", fd=%d)\n", http,
+  DEBUG_printf(("cupsPutFd(http=%p, resource=\"%s\", fd=%d)", http,
                 resource, fd));
 
-  if (!http || !resource || fd < 0)
+  if (!resource || fd < 0)
   {
     if (http)
       http->error = EINVAL;
@@ -278,6 +290,10 @@ cupsPutFd(http_t     *http,                /* I - HTTP connection to server */
     return (HTTP_ERROR);
   }
 
+  if (!http)
+    if ((http = _cupsConnect()) == NULL)
+      return (HTTP_SERVICE_UNAVAILABLE);
+
  /*
   * Then send PUT requests to the HTTP server...
   */
@@ -286,7 +302,7 @@ cupsPutFd(http_t     *http,         /* I - HTTP connection to server */
 
   do
   {
-    DEBUG_printf(("cupsPutFd: starting attempt, authstring=\"%s\"...\n",
+    DEBUG_printf(("2cupsPutFd: starting attempt, authstring=\"%s\"...",
                   http->authstring));
 
     httpClearFields(http);
@@ -344,7 +360,7 @@ cupsPutFd(http_t     *http,         /* I - HTTP connection to server */
 
     if (status == HTTP_ERROR && !retries)
     {
-      DEBUG_printf(("cupsPutFd: retry on status %d\n", status));
+      DEBUG_printf(("2cupsPutFd: retry on status %d", status));
 
       retries ++;
 
@@ -362,7 +378,7 @@ cupsPutFd(http_t     *http,         /* I - HTTP connection to server */
       continue;
     }
 
-    DEBUG_printf(("cupsPutFd: status=%d\n", status));
+    DEBUG_printf(("2cupsPutFd: status=%d", status));
 
     if (status == HTTP_UNAUTHORIZED)
     {
@@ -377,7 +393,10 @@ cupsPutFd(http_t     *http,                /* I - HTTP connection to server */
       */
 
       if (cupsDoAuthentication(http, "PUT", resource))
+      {
+        status = HTTP_AUTHORIZATION_CANCELED;
         break;
+      }
 
       if (httpReconnect(http))
       {
@@ -416,7 +435,12 @@ cupsPutFd(http_t     *http,                /* I - HTTP connection to server */
   */
 
   if (status != HTTP_CREATED)
+  {
+    _cupsSetHTTPError(status);
     httpFlush(http);
+  }
+
+  DEBUG_printf(("1cupsPutFd: Returning %d...", status));
 
   return (status);
 }
@@ -425,13 +449,14 @@ cupsPutFd(http_t     *http,               /* I - HTTP connection to server */
 /*
  * 'cupsPutFile()' - Put a file on the server.
  *
- * This function returns HTTP_CREATED when the file is stored successfully.
+ * This function returns @code HTTP_CREATED@ when the file is stored
+ * successfully.
  *
- * @since CUPS 1.1.20@
+ * @since CUPS 1.1.20/Mac OS X 10.4@
  */
 
 http_status_t                          /* O - HTTP status */
-cupsPutFile(http_t     *http,          /* I - HTTP connection to server */
+cupsPutFile(http_t     *http,          /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
             const char *resource,      /* I - Resource name */
            const char *filename)       /* I - Filename */
 {
@@ -479,5 +504,5 @@ cupsPutFile(http_t     *http,               /* I - HTTP connection to server */
 
 
 /*
- * End of "$Id: getputfile.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id: getputfile.c 7359 2008-02-29 19:01:35Z mike $".
  */