]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
cupsSendRequest was giving up after a reconnect - httpReconnect needed to reset
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 16 Sep 2011 00:07:39 +0000 (00:07 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 16 Sep 2011 00:07:39 +0000 (00:07 +0000)
the HTTP state.  Also removed some spots where the error message could be lost.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10003 7a7537e8-13f0-0310-91df-b6672ffda945

cups/http-addrlist.c
cups/http.c
cups/request.c

index 02abed9dd1f4832c8bb3bb98d725cb42072f5372..1a28b5a183869dd4e6de3347fd13369ec5f5de3d 100644 (file)
@@ -169,7 +169,7 @@ httpAddrConnect(
   }
 
   if (!addrlist)
-    _cupsSetError(IPP_SERVICE_UNAVAILABLE, _("Unable to connect to server"), 1);
+    _cupsSetError(IPP_SERVICE_UNAVAILABLE, strerror(errno), 0);
 
   return (addrlist);
 }
index b35592580d682a83e7a75a9ed488055294b22bdb..6c4cc65c645f42d7902f76b3fd7d272beb13a7a3 100644 (file)
@@ -2327,6 +2327,7 @@ httpReconnect(http_t *http)               /* I - Connection to server */
   http->hostaddr = &(addr->addr);
   http->error    = 0;
   http->status   = HTTP_CONTINUE;
+  http->state    = HTTP_WAITING;
 
 #ifdef HAVE_SSL
   if (http->encryption == HTTP_ENCRYPT_ALWAYS)
index 881c0d2f2e01c68902049f2248f0063fb90b6d08..a1c33ec833aa03f1b03a433f3c14ebd5751c09eb 100644 (file)
@@ -635,9 +635,14 @@ cupsSendRequest(http_t     *http,  /* I - Connection to server or @code CUPS_HTTP
 
   if (http->state == HTTP_GET_SEND ||
       http->state == HTTP_POST_SEND)
+  {
+    DEBUG_puts("2cupsSendRequest: Flush prior response.");
     httpFlush(http);
+  }
   else if (http->state != HTTP_WAITING)
   {
+    DEBUG_printf(("1cupsSendRequest: Unknown HTTP state (%d), bailing.",
+                  http->state));
     _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
 
     return (HTTP_ERROR);
@@ -654,7 +659,7 @@ cupsSendRequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
       !httpAddrLocalhost(http->hostaddr) && !http->tls &&
       httpEncryption(http, HTTP_ENCRYPT_REQUIRED))
   {
-    _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+    DEBUG_puts("1cupsSendRequest: Unable to encrypt connection.");
     return (HTTP_SERVICE_UNAVAILABLE);
   }
 #endif /* HAVE_SSL */
@@ -664,11 +669,15 @@ cupsSendRequest(http_t     *http, /* I - Connection to server or @code CUPS_HTTP
   */
 
   if (!_cups_strcasecmp(http->fields[HTTP_FIELD_CONNECTION], "close"))
+  {
+    DEBUG_puts("2cupsSendRequest: Connection: close");
+    httpClearFields(http);
     if (httpReconnect(http))
     {
-      _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+      DEBUG_puts("1cupsSendRequest: Unable to reconnect.");
       return (HTTP_SERVICE_UNAVAILABLE);
     }
+  }
 
  /*
   * Loop until we can send the request without authorization problems.
@@ -713,9 +722,10 @@ cupsSendRequest(http_t     *http,  /* I - Connection to server or @code CUPS_HTTP
 
     if (httpPost(http, resource))
     {
+      DEBUG_puts("2cupsSendRequest: POST failed, reconnecting.");
       if (httpReconnect(http))
       {
-        _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+        DEBUG_puts("1cupsSendRequest: Unable to reconnect.");
         return (HTTP_SERVICE_UNAVAILABLE);
       }
       else
@@ -746,6 +756,8 @@ cupsSendRequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
 
     if (state == IPP_ERROR)
     {
+      DEBUG_puts("1cupsSendRequest: Unable to send IPP request.");
+
       http->status = HTTP_ERROR;
       http->state  = HTTP_WAITING;
 
@@ -793,15 +805,21 @@ cupsSendRequest(http_t     *http, /* I - Connection to server or @code CUPS_HTTP
       case HTTP_ERROR :
       case HTTP_CONTINUE :
       case HTTP_OK :
+          DEBUG_printf(("1cupsSendRequest: Returning %d.", status));
           return (status);
 
       case HTTP_UNAUTHORIZED :
           if (cupsDoAuthentication(http, "POST", resource))
+         {
+            DEBUG_puts("1cupsSendRequest: Returning HTTP_AUTHORIZATION_CANCELED.");
            return (HTTP_AUTHORIZATION_CANCELED);
+         }
+
+          DEBUG_puts("2cupsSendRequest: Reconnecting after HTTP_UNAUTHORIZED.");
 
          if (httpReconnect(http))
          {
-           _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+           DEBUG_puts("1cupsSendRequest: Unable to reconnect.");
            return (HTTP_SERVICE_UNAVAILABLE);
          }
          break;
@@ -813,15 +831,19 @@ cupsSendRequest(http_t     *http, /* I - Connection to server or @code CUPS_HTTP
          * encryption...
          */
 
+          DEBUG_puts("2cupsSendRequest: Reconnecting after "
+                    "HTTP_UPGRADE_REQUIRED.");
+
          if (httpReconnect(http))
          {
-           _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+           DEBUG_puts("1cupsSendRequest: Unable to reconnect.");
            return (HTTP_SERVICE_UNAVAILABLE);
          }
 
+         DEBUG_puts("2cupsSendRequest: Upgrading to TLS.");
          if (httpEncryption(http, HTTP_ENCRYPT_REQUIRED))
          {
-           _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+           DEBUG_puts("1cupsSendRequest: Unable to encrypt connection.");
            return (HTTP_SERVICE_UNAVAILABLE);
          }
          break;
@@ -834,9 +856,12 @@ cupsSendRequest(http_t     *http,  /* I - Connection to server or @code CUPS_HTTP
 
          expect = (http_status_t)0;
 
+          DEBUG_puts("2cupsSendRequest: Reconnecting after "
+                    "HTTP_EXPECTATION_FAILED.");
+
          if (httpReconnect(http))
          {
-           _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+           DEBUG_puts("1cupsSendRequest: Unable to reconnect.");
            return (HTTP_SERVICE_UNAVAILABLE);
          }
          break;