]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/request.c
Merge changes from CUPS 1.6svn-r9968.
[thirdparty/cups.git] / cups / request.c
index 0b61327d19980d03e4ceec10934fe3df809d6287..a38ec19604917975398dc40571fea4fbb48f0210 100644 (file)
@@ -283,26 +283,24 @@ cupsDoIORequest(http_t     *http, /* I - Connection to server or @code CUPS_HTTP
       break;
     }
 
-    if (response)
+    if (response && outfile >= 0)
     {
-      if (outfile >= 0)
-      {
-       /*
-        * Write trailing data to file...
-       */
+     /*
+      * Write trailing data to file...
+      */
 
-       while ((bytes = (int)httpRead2(http, buffer, sizeof(buffer))) > 0)
-         if (write(outfile, buffer, bytes) < bytes)
-           break;
-      }
-      else
-      {
-       /*
-        * Flush any remaining data...
-        */
+      while ((bytes = (int)httpRead2(http, buffer, sizeof(buffer))) > 0)
+       if (write(outfile, buffer, bytes) < bytes)
+         break;
+    }
 
-        httpFlush(http);
-      }
+    if (http->state != HTTP_WAITING)
+    {
+     /*
+      * Flush any remaining data...
+      */
+
+      httpFlush(http);
     }
   }
 
@@ -343,7 +341,8 @@ cupsDoRequest(http_t     *http,             /* I - Connection to server or @code CUPS_HTTP_
  *
  * Use this function to get the response for an IPP request sent using
  * cupsSendDocument() or cupsSendRequest(). For requests that return
- * additional data, use httpRead() after getting a successful response.
+ * additional data, use httpRead() after getting a successful response,
+ * otherwise call httpFlush() to complete the response processing.
  *
  * @since CUPS 1.4/Mac OS X 10.6@
  */
@@ -426,6 +425,8 @@ cupsGetResponse(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
       response = NULL;
 
       _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
+      http->status = status = HTTP_ERROR;
+      http->error  = EIO;
     }
   }
   else if (status != HTTP_ERROR)
@@ -451,7 +452,7 @@ cupsGetResponse(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
       if (!cupsDoAuthentication(http, "POST", resource))
         httpReconnect(http);
       else
-        status = HTTP_AUTHORIZATION_CANCELED;
+        http->status = status = HTTP_AUTHORIZATION_CANCELED;
     }
 
 #ifdef HAVE_SSL
@@ -637,6 +638,20 @@ cupsSendRequest(http_t     *http,  /* I - Connection to server or @code CUPS_HTTP
     if ((http = _cupsConnect()) == NULL)
       return (HTTP_SERVICE_UNAVAILABLE);
 
+ /*
+  * If the prior request was not flushed out, do so now...
+  */
+
+  if (http->state == HTTP_GET_SEND ||
+      http->state == HTTP_POST_SEND)
+    httpFlush(http);
+  else if (http->state != HTTP_WAITING)
+  {
+    _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
+
+    return (HTTP_ERROR);
+  }
+
 #ifdef HAVE_SSL
  /*
   * See if we have an auth-info attribute and are communicating over
@@ -657,7 +672,7 @@ cupsSendRequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
   * Reconnect if the last response had a "Connection: close"...
   */
 
-  if (!strcasecmp(http->fields[HTTP_FIELD_CONNECTION], "close"))
+  if (!_cups_strcasecmp(http->fields[HTTP_FIELD_CONNECTION], "close"))
     if (httpReconnect(http))
     {
       _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
@@ -691,7 +706,7 @@ cupsSendRequest(http_t     *http,   /* I - Connection to server or @code CUPS_HTTP
       * "replay" attack...
       */
 
-      _cupsSetNegotiateAuthString(http);
+      _cupsSetNegotiateAuthString(http, "POST", resource);
     }
 #endif /* HAVE_GSSAPI */