]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/getputfile.c
Sync up with CUPS 1.7svn-r10893
[thirdparty/cups.git] / cups / getputfile.c
index 7e12fe9fc4308bd197f87015d60418a0065af034..6816f6d427d110c7a3a5788dfc833cb5becef5e3 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Get/put file functions for CUPS.
  *
- *   Copyright 2007-2012 by Apple Inc.
+ *   Copyright 2007-2013 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -39,7 +39,7 @@
 /*
  * 'cupsGetFd()' - Get a file from the server.
  *
- * This function returns @code HTTP_OK@ when the file is successfully retrieved.
+ * This function returns @code HTTP_STATUS_OK@ when the file is successfully retrieved.
  *
  * @since CUPS 1.1.20/OS X 10.4@
  */
@@ -68,12 +68,12 @@ cupsGetFd(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFA
     if (http)
       http->error = EINVAL;
 
-    return (HTTP_ERROR);
+    return (HTTP_STATUS_ERROR);
   }
 
   if (!http)
     if ((http = _cupsConnect()) == NULL)
-      return (HTTP_SERVICE_UNAVAILABLE);
+      return (HTTP_STATUS_SERVICE_UNAVAILABLE);
 
  /*
   * Then send GET requests to the HTTP server...
@@ -90,21 +90,21 @@ cupsGetFd(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFA
 
     if (httpGet(http, resource))
     {
-      if (httpReconnect(http))
+      if (httpReconnect2(http, 30000, NULL))
       {
-        status = HTTP_ERROR;
+        status = HTTP_STATUS_ERROR;
        break;
       }
       else
       {
-        status = HTTP_UNAUTHORIZED;
+        status = HTTP_STATUS_UNAUTHORIZED;
         continue;
       }
     }
 
-    while ((status = httpUpdate(http)) == HTTP_CONTINUE);
+    while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
 
-    if (status == HTTP_UNAUTHORIZED)
+    if (status == HTTP_STATUS_UNAUTHORIZED)
     {
      /*
       * Flush any error message...
@@ -118,46 +118,46 @@ cupsGetFd(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DEFA
 
       if (cupsDoAuthentication(http, "GET", resource))
       {
-        status = HTTP_AUTHORIZATION_CANCELED;
+        status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
         break;
       }
 
-      if (httpReconnect(http))
+      if (httpReconnect2(http, 30000, NULL))
       {
-        status = HTTP_ERROR;
+        status = HTTP_STATUS_ERROR;
         break;
       }
 
       continue;
     }
 #ifdef HAVE_SSL
-    else if (status == HTTP_UPGRADE_REQUIRED)
+    else if (status == HTTP_STATUS_UPGRADE_REQUIRED)
     {
       /* Flush any error message... */
       httpFlush(http);
 
       /* Reconnect... */
-      if (httpReconnect(http))
+      if (httpReconnect2(http, 30000, NULL))
       {
-        status = HTTP_ERROR;
+        status = HTTP_STATUS_ERROR;
         break;
       }
 
       /* Upgrade with encryption... */
-      httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+      httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
 
       /* Try again, this time with encryption enabled... */
       continue;
     }
 #endif /* HAVE_SSL */
   }
-  while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED);
+  while (status == HTTP_STATUS_UNAUTHORIZED || status == HTTP_STATUS_UPGRADE_REQUIRED);
 
  /*
   * See if we actually got the file or an error...
   */
 
-  if (status == HTTP_OK)
+  if (status == HTTP_STATUS_OK)
   {
    /*
     * Yes, copy the file...
@@ -185,7 +185,7 @@ cupsGetFd(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFA
 /*
  * 'cupsGetFile()' - Get a file from the server.
  *
- * This function returns @code HTTP_OK@ when the file is successfully retrieved.
+ * This function returns @code HTTP_STATUS_OK@ when the file is successfully retrieved.
  *
  * @since CUPS 1.1.20/OS X 10.4@
  */
@@ -208,7 +208,7 @@ cupsGetFile(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DE
     if (http)
       http->error = EINVAL;
 
-    return (HTTP_ERROR);
+    return (HTTP_STATUS_ERROR);
   }
 
  /*
@@ -223,7 +223,7 @@ cupsGetFile(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DE
 
     http->error = errno;
 
-    return (HTTP_ERROR);
+    return (HTTP_STATUS_ERROR);
   }
 
  /*
@@ -238,7 +238,7 @@ cupsGetFile(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DE
 
   close(fd);
 
-  if (status != HTTP_OK)
+  if (status != HTTP_STATUS_OK)
     unlink(filename);
 
  /*
@@ -252,7 +252,7 @@ cupsGetFile(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DE
 /*
  * 'cupsPutFd()' - Put a file on the server.
  *
- * This function returns @code HTTP_CREATED@ when the file is stored
+ * This function returns @code HTTP_STATUS_CREATED@ when the file is stored
  * successfully.
  *
  * @since CUPS 1.1.20/OS X 10.4@
@@ -281,12 +281,12 @@ cupsPutFd(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DEFA
     if (http)
       http->error = EINVAL;
 
-    return (HTTP_ERROR);
+    return (HTTP_STATUS_ERROR);
   }
 
   if (!http)
     if ((http = _cupsConnect()) == NULL)
-      return (HTTP_SERVICE_UNAVAILABLE);
+      return (HTTP_STATUS_SERVICE_UNAVAILABLE);
 
  /*
   * Then send PUT requests to the HTTP server...
@@ -302,18 +302,18 @@ cupsPutFd(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DEFA
     httpClearFields(http);
     httpSetField(http, HTTP_FIELD_AUTHORIZATION, http->authstring);
     httpSetField(http, HTTP_FIELD_TRANSFER_ENCODING, "chunked");
-    httpSetExpect(http, HTTP_CONTINUE);
+    httpSetExpect(http, HTTP_STATUS_CONTINUE);
 
     if (httpPut(http, resource))
     {
-      if (httpReconnect(http))
+      if (httpReconnect2(http, 30000, NULL))
       {
-        status = HTTP_ERROR;
+        status = HTTP_STATUS_ERROR;
        break;
       }
       else
       {
-        status = HTTP_UNAUTHORIZED;
+        status = HTTP_STATUS_UNAUTHORIZED;
         continue;
       }
     }
@@ -325,9 +325,9 @@ cupsPutFd(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFA
     if (httpWait(http, 1000))
       status = httpUpdate(http);
     else
-      status = HTTP_CONTINUE;
+      status = HTTP_STATUS_CONTINUE;
 
-    if (status == HTTP_CONTINUE)
+    if (status == HTTP_STATUS_CONTINUE)
     {
      /*
       * Copy the file...
@@ -338,21 +338,21 @@ cupsPutFd(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DEFA
       while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
        if (httpCheck(http))
        {
-          if ((status = httpUpdate(http)) != HTTP_CONTINUE)
+          if ((status = httpUpdate(http)) != HTTP_STATUS_CONTINUE)
             break;
        }
        else
           httpWrite2(http, buffer, bytes);
     }
 
-    if (status == HTTP_CONTINUE)
+    if (status == HTTP_STATUS_CONTINUE)
     {
       httpWrite2(http, buffer, 0);
 
-      while ((status = httpUpdate(http)) == HTTP_CONTINUE);
+      while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
     }
 
-    if (status == HTTP_ERROR && !retries)
+    if (status == HTTP_STATUS_ERROR && !retries)
     {
       DEBUG_printf(("2cupsPutFd: retry on status %d", status));
 
@@ -362,9 +362,9 @@ cupsPutFd(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFA
       httpFlush(http);
 
       /* Reconnect... */
-      if (httpReconnect(http))
+      if (httpReconnect2(http, 30000, NULL))
       {
-        status = HTTP_ERROR;
+        status = HTTP_STATUS_ERROR;
         break;
       }
 
@@ -374,7 +374,7 @@ cupsPutFd(http_t     *http,         /* I - Connection to server or @code CUPS_HTTP_DEFA
 
     DEBUG_printf(("2cupsPutFd: status=%d", status));
 
-    if (status == HTTP_UNAUTHORIZED)
+    if (status == HTTP_STATUS_UNAUTHORIZED)
     {
      /*
       * Flush any error message...
@@ -388,47 +388,47 @@ cupsPutFd(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DEFA
 
       if (cupsDoAuthentication(http, "PUT", resource))
       {
-        status = HTTP_AUTHORIZATION_CANCELED;
+        status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
         break;
       }
 
-      if (httpReconnect(http))
+      if (httpReconnect2(http, 30000, NULL))
       {
-        status = HTTP_ERROR;
+        status = HTTP_STATUS_ERROR;
         break;
       }
 
       continue;
     }
 #ifdef HAVE_SSL
-    else if (status == HTTP_UPGRADE_REQUIRED)
+    else if (status == HTTP_STATUS_UPGRADE_REQUIRED)
     {
       /* Flush any error message... */
       httpFlush(http);
 
       /* Reconnect... */
-      if (httpReconnect(http))
+      if (httpReconnect2(http, 30000, NULL))
       {
-        status = HTTP_ERROR;
+        status = HTTP_STATUS_ERROR;
         break;
       }
 
       /* Upgrade with encryption... */
-      httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+      httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
 
       /* Try again, this time with encryption enabled... */
       continue;
     }
 #endif /* HAVE_SSL */
   }
-  while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED ||
-         (status == HTTP_ERROR && retries < 2));
+  while (status == HTTP_STATUS_UNAUTHORIZED || status == HTTP_STATUS_UPGRADE_REQUIRED ||
+         (status == HTTP_STATUS_ERROR && retries < 2));
 
  /*
   * See if we actually put the file or an error...
   */
 
-  if (status != HTTP_CREATED)
+  if (status != HTTP_STATUS_CREATED)
   {
     _cupsSetHTTPError(status);
     httpFlush(http);
@@ -467,7 +467,7 @@ cupsPutFile(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DE
     if (http)
       http->error = EINVAL;
 
-    return (HTTP_ERROR);
+    return (HTTP_STATUS_ERROR);
   }
 
  /*
@@ -482,7 +482,7 @@ cupsPutFile(http_t     *http,               /* I - Connection to server or @code CUPS_HTTP_DE
 
     http->error = errno;
 
-    return (HTTP_ERROR);
+    return (HTTP_STATUS_ERROR);
   }
 
  /*