]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Reconnect as needed prior to sending a GET, HEAD, or PUT request.
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 17 Jul 2013 14:10:21 +0000 (14:10 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 17 Jul 2013 14:10:21 +0000 (14:10 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11153 a1ca3aef-8c08-0410-bb20-df032aa958be

CHANGES.txt
cups/getputfile.c
cups/testhttp.c

index 6c3a5044b36914591c6101deaf503c9532306dcb..8f1728d2c4bdd351b151fdee90b447b1c78233e1 100644 (file)
@@ -3,7 +3,10 @@ CHANGES.txt - 1.7.0 - 2013-07-16
 
 CHANGES IN CUPS V1.7.0
 
-       - Fix a compile error in libcups (<rdar://problem/14467141>)
+       - httpGetFd, httpGetFile, httpPutFd, and httpPutFile did not
+         automatically reconnect if the server closed the connecion after the
+         previous response.
+       - Fixed a compile error in libcups (<rdar://problem/14467141>)
        - The scheduler incorrectly did not pass a FINAL_CONTENT_TYPE
          environment variable to the filters or backend
          (<rdar://problem/14355011>)
index 4a09099eeeed4553af8db48c544f854b159217e4..b4be78ae598647bb8555ef6e649d7871411fa454 100644 (file)
@@ -84,6 +84,16 @@ cupsGetFd(http_t     *http,          /* I - Connection to server or @code CUPS_HTTP_DEFA
 
   do
   {
+    if (!_cups_strcasecmp(httpGetField(http, HTTP_FIELD_CONNECTION), "close"))
+    {
+      httpClearFields(http);
+      if (httpReconnect2(http, 30000, NULL))
+      {
+       status = HTTP_STATUS_ERROR;
+       break;
+      }
+    }
+
     httpClearFields(http);
     httpSetField(http, HTTP_FIELD_AUTHORIZATION, http->authstring);
     httpSetField(http, HTTP_FIELD_IF_MODIFIED_SINCE, if_modified_since);
@@ -296,6 +306,16 @@ cupsPutFd(http_t     *http,                /* I - Connection to server or @code CUPS_HTTP_DEFA
 
   do
   {
+    if (!_cups_strcasecmp(httpGetField(http, HTTP_FIELD_CONNECTION), "close"))
+    {
+      httpClearFields(http);
+      if (httpReconnect2(http, 30000, NULL))
+      {
+       status = HTTP_STATUS_ERROR;
+       break;
+      }
+    }
+
     DEBUG_printf(("2cupsPutFd: starting attempt, authstring=\"%s\"...",
                   http->authstring));
 
index 4d0ee474a48d2640afadac7fb9617be80da37d30..a1fbc37aaf9bc5c18d98047eb34e36e2a4a35b47 100644 (file)
@@ -23,8 +23,7 @@
  * Include necessary headers...
  */
 
-#include "string-private.h"
-#include "http-private.h"
+#include "cups-private.h"
 
 
 /*
@@ -623,10 +622,87 @@ main(int  argc,                           /* I - Number of command-line arguments */
       continue;
     }
     printf("Checking file \"%s\"...\n", resource);
-    httpClearFields(http);
-    httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
-    httpHead(http, resource);
-    while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
+
+    do
+    {
+      if (!_cups_strcasecmp(httpGetField(http, HTTP_FIELD_CONNECTION), "close"))
+      {
+       httpClearFields(http);
+       if (httpReconnect2(http, 30000, NULL))
+       {
+          status = HTTP_STATUS_ERROR;
+          break;
+       }
+      }
+
+      httpClearFields(http);
+      httpSetField(http, HTTP_FIELD_AUTHORIZATION, httpGetAuthString(http));
+      httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
+      if (httpHead(http, resource))
+      {
+        if (httpReconnect2(http, 30000, NULL))
+        {
+          status = HTTP_STATUS_ERROR;
+          break;
+        }
+        else
+        {
+          status = HTTP_STATUS_UNAUTHORIZED;
+          continue;
+        }
+      }
+
+      while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
+
+      if (status == HTTP_STATUS_UNAUTHORIZED)
+      {
+       /*
+       * Flush any error message...
+       */
+
+       httpFlush(http);
+
+       /*
+       * See if we can do authentication...
+       */
+
+       if (cupsDoAuthentication(http, "GET", resource))
+       {
+         status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
+         break;
+       }
+
+       if (httpReconnect2(http, 30000, NULL))
+       {
+         status = HTTP_STATUS_ERROR;
+         break;
+       }
+
+       continue;
+      }
+#ifdef HAVE_SSL
+      else if (status == HTTP_STATUS_UPGRADE_REQUIRED)
+      {
+       /* Flush any error message... */
+       httpFlush(http);
+
+       /* Reconnect... */
+       if (httpReconnect2(http, 30000, NULL))
+       {
+         status = HTTP_STATUS_ERROR;
+         break;
+       }
+
+       /* Upgrade with encryption... */
+       httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
+
+       /* Try again, this time with encryption enabled... */
+       continue;
+      }
+#endif /* HAVE_SSL */
+    }
+    while (status == HTTP_STATUS_UNAUTHORIZED ||
+           status == HTTP_STATUS_UPGRADE_REQUIRED);
 
     if (status == HTTP_STATUS_OK)
       puts("HEAD OK:");
@@ -637,11 +713,88 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
     printf("Requesting file \"%s\" (Accept-Encoding: %s)...\n", resource,
            encoding ? encoding : "identity");
-    httpClearFields(http);
-    httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
-    httpSetField(http, HTTP_FIELD_ACCEPT_ENCODING, encoding);
-    httpGet(http, resource);
-    while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
+
+    do
+    {
+      if (!_cups_strcasecmp(httpGetField(http, HTTP_FIELD_CONNECTION), "close"))
+      {
+       httpClearFields(http);
+       if (httpReconnect2(http, 30000, NULL))
+       {
+          status = HTTP_STATUS_ERROR;
+          break;
+       }
+      }
+
+      httpClearFields(http);
+      httpSetField(http, HTTP_FIELD_AUTHORIZATION, httpGetAuthString(http));
+      httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
+      httpSetField(http, HTTP_FIELD_ACCEPT_ENCODING, encoding);
+
+      if (httpGet(http, resource))
+      {
+        if (httpReconnect2(http, 30000, NULL))
+        {
+          status = HTTP_STATUS_ERROR;
+          break;
+        }
+        else
+        {
+          status = HTTP_STATUS_UNAUTHORIZED;
+          continue;
+        }
+      }
+
+      while ((status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
+
+      if (status == HTTP_STATUS_UNAUTHORIZED)
+      {
+       /*
+       * Flush any error message...
+       */
+
+       httpFlush(http);
+
+       /*
+       * See if we can do authentication...
+       */
+
+       if (cupsDoAuthentication(http, "GET", resource))
+       {
+         status = HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED;
+         break;
+       }
+
+       if (httpReconnect2(http, 30000, NULL))
+       {
+         status = HTTP_STATUS_ERROR;
+         break;
+       }
+
+       continue;
+      }
+#ifdef HAVE_SSL
+      else if (status == HTTP_STATUS_UPGRADE_REQUIRED)
+      {
+       /* Flush any error message... */
+       httpFlush(http);
+
+       /* Reconnect... */
+       if (httpReconnect2(http, 30000, NULL))
+       {
+         status = HTTP_STATUS_ERROR;
+         break;
+       }
+
+       /* Upgrade with encryption... */
+       httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
+
+       /* Try again, this time with encryption enabled... */
+       continue;
+      }
+#endif /* HAVE_SSL */
+    }
+    while (status == HTTP_STATUS_UNAUTHORIZED || status == HTTP_STATUS_UPGRADE_REQUIRED);
 
     if (status == HTTP_STATUS_OK)
       puts("GET OK:");